- Added documentation for audit tracking (IP address, invocation method). - Updated database model descriptions for enhanced WorkOrder and Conversation fields. - Documented the new UnifiedConfig system. - Reflected enhanced logging transparency for knowledge base parsing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
673 lines
18 KiB
Plaintext
673 lines
18 KiB
Plaintext
################################################################################
|
||
# DEPRECATED CONFIGURATION FILE: config/llm_config.py
|
||
################################################################################
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
LLM配置文件 - 千问模型配置
|
||
"""
|
||
|
||
from src.agent.llm_client import LLMConfig
|
||
|
||
# 千问模型配置
|
||
QWEN_CONFIG = LLMConfig(
|
||
provider="qwen",
|
||
api_key="sk-c0dbefa1718d46eaa897199135066f00", # 请替换为您的千问API密钥
|
||
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
||
model="qwen-plus-latest", # 可选: qwen-turbo, qwen-plus, qwen-max
|
||
temperature=0.7,
|
||
max_tokens=2000
|
||
)
|
||
|
||
# 其他模型配置示例
|
||
OPENAI_CONFIG = LLMConfig(
|
||
provider="openai",
|
||
api_key="sk-your-openai-api-key-here",
|
||
model="gpt-3.5-turbo",
|
||
temperature=0.7,
|
||
max_tokens=2000
|
||
)
|
||
|
||
ANTHROPIC_CONFIG = LLMConfig(
|
||
provider="anthropic",
|
||
api_key="sk-ant-your-anthropic-api-key-here",
|
||
model="claude-3-sonnet-20240229",
|
||
temperature=0.7,
|
||
max_tokens=2000
|
||
)
|
||
|
||
# 默认使用千问模型
|
||
DEFAULT_CONFIG = QWEN_CONFIG
|
||
|
||
|
||
def get_default_llm_config() -> LLMConfig:
|
||
"""
|
||
获取默认的LLM配置
|
||
优先从统一配置管理器获取,如果失败则使用本地配置
|
||
"""
|
||
try:
|
||
from src.config.unified_config import get_config
|
||
config = get_config()
|
||
llm_dict = config.get_llm_config()
|
||
|
||
# 创建LLMConfig对象
|
||
return LLMConfig(
|
||
provider=llm_dict.get("provider", "qwen"),
|
||
api_key=llm_dict.get("api_key", ""),
|
||
base_url=llm_dict.get("base_url", "https://dashscope.aliyuncs.com/compatible-mode/v1"),
|
||
model=llm_dict.get("model", "qwen-plus-latest"),
|
||
temperature=llm_dict.get("temperature", 0.7),
|
||
max_tokens=llm_dict.get("max_tokens", 2000)
|
||
)
|
||
except Exception:
|
||
# 如果统一配置不可用,使用本地配置
|
||
return DEFAULT_CONFIG
|
||
|
||
|
||
################################################################################
|
||
# DEPRECATED CONFIGURATION FILE: config/integrations_config.json
|
||
################################################################################
|
||
{
|
||
"feishu": {
|
||
"app_id": "cli_a8b50ec0eed1500d",
|
||
"app_secret": "ccxkE7ZCFQZcwkkM1rLy0ccZRXYsT2xK",
|
||
"app_token": "XXnEbiCmEaMblSs6FDJcFCqsnIg",
|
||
"table_id": "tblnl3vJPpgMTSiP",
|
||
"last_updated": "2025-09-19T18:40:55.291113",
|
||
"status": "active"
|
||
},
|
||
"system": {
|
||
"sync_limit": 10,
|
||
"ai_suggestions_enabled": true,
|
||
"auto_sync_interval": 0,
|
||
"last_sync_time": null
|
||
}
|
||
}
|
||
|
||
################################################################################
|
||
# DEPRECATED CONFIGURATION FILE: config/ai_accuracy_config.py
|
||
################################################################################
|
||
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
|
||
"""
|
||
AI准确率配置
|
||
管理AI建议的准确率阈值和相关配置
|
||
"""
|
||
|
||
from dataclasses import dataclass
|
||
from typing import Dict, Any
|
||
|
||
@dataclass
|
||
class AIAccuracyConfig:
|
||
"""AI准确率配置类"""
|
||
|
||
# 相似度阈值配置
|
||
auto_approve_threshold: float = 0.95 # 自动审批阈值(≥95%)
|
||
use_human_resolution_threshold: float = 0.90 # 使用人工描述阈值(<90%)
|
||
manual_review_threshold: float = 0.80 # 人工审核阈值(≥80%)
|
||
|
||
# 置信度配置
|
||
ai_suggestion_confidence: float = 0.95 # AI建议默认置信度
|
||
human_resolution_confidence: float = 0.90 # 人工描述置信度
|
||
|
||
# 入库策略配置
|
||
prefer_human_when_low_accuracy: bool = True # 当AI准确率低时优先使用人工描述
|
||
enable_auto_approval: bool = True # 是否启用自动审批
|
||
enable_human_fallback: bool = True # 是否启用人工描述回退
|
||
|
||
def get_threshold_explanation(self, similarity: float) -> str:
|
||
"""获取相似度阈值的解释"""
|
||
if similarity >= self.auto_approve_threshold:
|
||
return f"相似度≥{self.auto_approve_threshold*100:.0f}%,自动审批使用AI建议"
|
||
elif similarity >= self.manual_review_threshold:
|
||
return f"相似度≥{self.manual_review_threshold*100:.0f}%,建议人工审核"
|
||
elif similarity >= self.use_human_resolution_threshold:
|
||
return f"相似度<{self.use_human_resolution_threshold*100:.0f}%,建议使用人工描述"
|
||
else:
|
||
return f"相似度<{self.use_human_resolution_threshold*100:.0f}%,优先使用人工描述"
|
||
|
||
def should_use_human_resolution(self, similarity: float) -> bool:
|
||
"""判断是否应该使用人工描述"""
|
||
return similarity < self.use_human_resolution_threshold
|
||
|
||
def should_auto_approve(self, similarity: float) -> bool:
|
||
"""判断是否应该自动审批"""
|
||
return similarity >= self.auto_approve_threshold and self.enable_auto_approval
|
||
|
||
def get_confidence_score(self, similarity: float, use_human: bool = False) -> float:
|
||
"""获取置信度分数"""
|
||
if use_human:
|
||
return self.human_resolution_confidence
|
||
else:
|
||
return max(similarity, self.ai_suggestion_confidence)
|
||
|
||
def to_dict(self) -> Dict[str, Any]:
|
||
"""转换为字典格式"""
|
||
return {
|
||
"auto_approve_threshold": self.auto_approve_threshold,
|
||
"use_human_resolution_threshold": self.use_human_resolution_threshold,
|
||
"manual_review_threshold": self.manual_review_threshold,
|
||
"ai_suggestion_confidence": self.ai_suggestion_confidence,
|
||
"human_resolution_confidence": self.human_resolution_confidence,
|
||
"prefer_human_when_low_accuracy": self.prefer_human_when_low_accuracy,
|
||
"enable_auto_approval": self.enable_auto_approval,
|
||
"enable_human_fallback": self.enable_human_fallback
|
||
}
|
||
|
||
@classmethod
|
||
def from_dict(cls, data: Dict[str, Any]) -> 'AIAccuracyConfig':
|
||
"""从字典创建配置"""
|
||
return cls(**data)
|
||
|
||
# 默认配置实例
|
||
DEFAULT_CONFIG = AIAccuracyConfig()
|
||
|
||
# 配置预设
|
||
PRESETS = {
|
||
"conservative": AIAccuracyConfig(
|
||
auto_approve_threshold=0.98,
|
||
use_human_resolution_threshold=0.85,
|
||
manual_review_threshold=0.90,
|
||
human_resolution_confidence=0.95
|
||
),
|
||
"balanced": AIAccuracyConfig(
|
||
auto_approve_threshold=0.95,
|
||
use_human_resolution_threshold=0.90,
|
||
manual_review_threshold=0.80,
|
||
human_resolution_confidence=0.90
|
||
),
|
||
"aggressive": AIAccuracyConfig(
|
||
auto_approve_threshold=0.90,
|
||
use_human_resolution_threshold=0.80,
|
||
manual_review_threshold=0.70,
|
||
human_resolution_confidence=0.85
|
||
)
|
||
}
|
||
|
||
def get_accuracy_config(preset: str = "balanced") -> AIAccuracyConfig:
|
||
"""获取准确率配置"""
|
||
return PRESETS.get(preset, DEFAULT_CONFIG)
|
||
|
||
def update_accuracy_config(config: AIAccuracyConfig) -> bool:
|
||
"""更新准确率配置(可以保存到文件或数据库)"""
|
||
try:
|
||
# 这里可以实现配置的持久化存储
|
||
# 例如保存到配置文件或数据库
|
||
return True
|
||
except Exception:
|
||
return False
|
||
|
||
|
||
################################################################################
|
||
# DEPRECATED CONFIGURATION FILE: config/field_mapping_config.json
|
||
################################################################################
|
||
{
|
||
"field_mapping": {
|
||
"TR Number": "order_id",
|
||
"TR Description": "description",
|
||
"Type of problem": "category",
|
||
"TR Level": "priority",
|
||
"TR Status": "status",
|
||
"Source": "source",
|
||
"Date creation": "created_at",
|
||
"处理过程": "resolution",
|
||
"TR tracking": "resolution",
|
||
"Created by": "created_by",
|
||
"Module(模块)": "module",
|
||
"Wilfulness(责任人)": "wilfulness",
|
||
"Date of close TR": "date_of_close",
|
||
"Vehicle Type01": "vehicle_type",
|
||
"VIN|sim": "vin_sim",
|
||
"App remote control version": "app_remote_control_version",
|
||
"HMI SW": "hmi_sw",
|
||
"父记录": "parent_record",
|
||
"Has it been updated on the same day": "has_updated_same_day",
|
||
"Operating time": "operating_time",
|
||
"AI建议": "ai_suggestion",
|
||
"Issue Start Time": "updated_at",
|
||
"Wilfulness(责任人<E4BBBB>?": "wilfulness",
|
||
"父<>?<3F>录": "parent_record",
|
||
"AI建<49>??": "ai_suggestion"
|
||
},
|
||
"field_aliases": {
|
||
"order_id": [
|
||
"TR Number",
|
||
"TR编号",
|
||
"工单号",
|
||
"Order ID",
|
||
"Ticket ID",
|
||
"工单编号",
|
||
"新字段1",
|
||
"新字段"
|
||
],
|
||
"description": [
|
||
"TR Description",
|
||
"TR描述",
|
||
"描述",
|
||
"Description",
|
||
"问题描述",
|
||
"详细描述"
|
||
],
|
||
"category": [
|
||
"Type of problem",
|
||
"问题类型",
|
||
"Category",
|
||
"分类",
|
||
"Problem Type",
|
||
"问题分类"
|
||
],
|
||
"priority": [
|
||
"TR Level",
|
||
"优先级",
|
||
"Priority",
|
||
"Level",
|
||
"紧急程度",
|
||
"重要程度"
|
||
],
|
||
"status": [
|
||
"TR Status",
|
||
"状态",
|
||
"Status",
|
||
"工单状态",
|
||
"处理状态"
|
||
],
|
||
"source": [
|
||
"Source",
|
||
"来源",
|
||
"Source Type",
|
||
"来源类型",
|
||
"提交来源"
|
||
],
|
||
"created_at": [
|
||
"Date creation",
|
||
"创建日期",
|
||
"Created At",
|
||
"Creation Date",
|
||
"创建时间"
|
||
],
|
||
"solution": [
|
||
"处理过程",
|
||
"Solution",
|
||
"解决方案",
|
||
"Process",
|
||
"处理方案"
|
||
],
|
||
"resolution": [
|
||
"TR tracking",
|
||
"Resolution",
|
||
"解决结果",
|
||
"跟踪",
|
||
"处理结果"
|
||
],
|
||
"created_by": [
|
||
"Created by",
|
||
"创建人",
|
||
"Creator",
|
||
"Created By",
|
||
"提交人"
|
||
],
|
||
"vehicle_type": [
|
||
"Vehicle Type01",
|
||
"车型",
|
||
"Vehicle Type",
|
||
"车辆类型",
|
||
"车款"
|
||
],
|
||
"vin_sim": [
|
||
"VIN|sim",
|
||
"VIN",
|
||
"车架号",
|
||
"SIM",
|
||
"VIN/SIM",
|
||
"车辆识别号"
|
||
],
|
||
"module": [
|
||
"Module(模块)",
|
||
"模块",
|
||
"Module",
|
||
"功能模块"
|
||
],
|
||
"wilfulness": [
|
||
"Wilfulness(责任人)",
|
||
"责任人",
|
||
"负责人",
|
||
"Assignee"
|
||
],
|
||
"date_of_close": [
|
||
"Date of close TR",
|
||
"关闭日期",
|
||
"Close Date",
|
||
"完成日期"
|
||
],
|
||
"app_remote_control_version": [
|
||
"App remote control version",
|
||
"应用远程控制版本",
|
||
"App Version",
|
||
"应用版本"
|
||
],
|
||
"hmi_sw": [
|
||
"HMI SW",
|
||
"HMI软件版本",
|
||
"HMI Software",
|
||
"人机界面软件"
|
||
],
|
||
"parent_record": [
|
||
"父记录",
|
||
"Parent Record",
|
||
"上级记录",
|
||
"关联记录"
|
||
],
|
||
"has_updated_same_day": [
|
||
"Has it been updated on the same day",
|
||
"是否同日更新",
|
||
"Same Day Update",
|
||
"当日更新"
|
||
],
|
||
"operating_time": [
|
||
"Operating time",
|
||
"操作时间",
|
||
"Operation Time",
|
||
"运行时间"
|
||
],
|
||
"ai_suggestion": [
|
||
"AI建议",
|
||
"AI Suggestion",
|
||
"AI建议",
|
||
"智能建议"
|
||
],
|
||
"updated_at": [
|
||
"Issue Start Time",
|
||
"问题开始时间",
|
||
"Start Time",
|
||
"更新时间"
|
||
]
|
||
},
|
||
"field_patterns": {
|
||
"order_id": [
|
||
".*number.*",
|
||
".*id.*",
|
||
".*编号.*",
|
||
".*ticket.*",
|
||
".*新.*"
|
||
],
|
||
"description": [
|
||
".*description.*",
|
||
".*描述.*",
|
||
".*detail.*",
|
||
".*内容.*"
|
||
],
|
||
"category": [
|
||
".*type.*",
|
||
".*category.*",
|
||
".*分类.*",
|
||
".*类型.*",
|
||
".*problem.*"
|
||
],
|
||
"priority": [
|
||
".*level.*",
|
||
".*priority.*",
|
||
".*优先级.*",
|
||
".*urgent.*"
|
||
],
|
||
"status": [
|
||
".*status.*",
|
||
".*状态.*",
|
||
".*state.*"
|
||
],
|
||
"source": [
|
||
".*source.*",
|
||
".*来源.*",
|
||
".*origin.*"
|
||
],
|
||
"created_at": [
|
||
".*creation.*",
|
||
".*created.*",
|
||
".*创建.*",
|
||
".*date.*"
|
||
],
|
||
"solution": [
|
||
".*solution.*",
|
||
".*处理.*",
|
||
".*解决.*",
|
||
".*process.*"
|
||
],
|
||
"resolution": [
|
||
".*resolution.*",
|
||
".*tracking.*",
|
||
".*跟踪.*",
|
||
".*result.*"
|
||
],
|
||
"created_by": [
|
||
".*created.*by.*",
|
||
".*creator.*",
|
||
".*创建人.*",
|
||
".*author.*"
|
||
],
|
||
"vehicle_type": [
|
||
".*vehicle.*type.*",
|
||
".*车型.*",
|
||
".*车辆.*",
|
||
".*car.*"
|
||
],
|
||
"vin_sim": [
|
||
".*vin.*",
|
||
".*sim.*",
|
||
".*车架.*",
|
||
".*识别.*"
|
||
],
|
||
"module": [
|
||
".*module.*",
|
||
".*模块.*",
|
||
".*功能.*"
|
||
],
|
||
"wilfulness": [
|
||
".*wilfulness.*",
|
||
".*责任人.*",
|
||
".*负责人.*",
|
||
".*assignee.*"
|
||
],
|
||
"date_of_close": [
|
||
".*close.*",
|
||
".*关闭.*",
|
||
".*完成.*",
|
||
".*finish.*"
|
||
],
|
||
"app_remote_control_version": [
|
||
".*app.*version.*",
|
||
".*应用.*版本.*",
|
||
".*remote.*control.*"
|
||
],
|
||
"hmi_sw": [
|
||
".*hmi.*",
|
||
".*软件.*",
|
||
".*software.*"
|
||
],
|
||
"parent_record": [
|
||
".*parent.*",
|
||
".*父.*",
|
||
".*上级.*",
|
||
".*关联.*"
|
||
],
|
||
"has_updated_same_day": [
|
||
".*same.*day.*",
|
||
".*同日.*",
|
||
".*当日.*",
|
||
".*updated.*same.*"
|
||
],
|
||
"operating_time": [
|
||
".*operating.*time.*",
|
||
".*操作.*时间.*",
|
||
".*运行.*时间.*"
|
||
],
|
||
"ai_suggestion": [
|
||
".*ai.*suggestion.*",
|
||
".*ai.*建议.*",
|
||
".*智能.*建议.*"
|
||
],
|
||
"updated_at": [
|
||
".*start.*time.*",
|
||
".*开始.*时间.*",
|
||
".*updated.*at.*",
|
||
".*更新时间.*"
|
||
]
|
||
},
|
||
"field_priorities": {
|
||
"order_id": 3,
|
||
"description": 3,
|
||
"category": 3,
|
||
"priority": 3,
|
||
"status": 3,
|
||
"created_at": 3,
|
||
"source": 3,
|
||
"solution": 3,
|
||
"resolution": 3,
|
||
"created_by": 3,
|
||
"vehicle_type": 3,
|
||
"vin_sim": 3,
|
||
"module": 3,
|
||
"wilfulness": 3,
|
||
"date_of_close": 3,
|
||
"app_remote_control_version": 3,
|
||
"hmi_sw": 3,
|
||
"parent_record": 3,
|
||
"has_updated_same_day": 3,
|
||
"operating_time": 3,
|
||
"ai_suggestion": 3,
|
||
"updated_at": 3
|
||
},
|
||
"auto_mapping_enabled": true,
|
||
"similarity_threshold": 0.6
|
||
}
|
||
|
||
################################################################################
|
||
# DEPRECATED CONFIGURATION FILE: config/unified_config.json
|
||
################################################################################
|
||
{
|
||
"database": {
|
||
"url": "mysql+pymysql://tsp_assistant:password@jeason.online/tsp_assistant?charset=utf8mb4",
|
||
"pool_size": 10,
|
||
"max_overflow": 20,
|
||
"pool_timeout": 30,
|
||
"pool_recycle": 3600
|
||
},
|
||
"llm": {
|
||
"provider": "qwen",
|
||
"api_key": "sk-c0dbefa1718d46eaa897199135066f00",
|
||
"base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
|
||
"model": "qwen-plus-latest",
|
||
"temperature": 0.7,
|
||
"max_tokens": 2000,
|
||
"timeout": 30
|
||
},
|
||
"server": {
|
||
"host": "0.0.0.0",
|
||
"port": 5000,
|
||
"websocket_port": 8765,
|
||
"debug": false,
|
||
"log_level": "INFO"
|
||
},
|
||
"feishu": {
|
||
"app_id": "",
|
||
"app_secret": "",
|
||
"app_token": "",
|
||
"table_id": "",
|
||
"status": "active",
|
||
"sync_limit": 10,
|
||
"auto_sync_interval": 0
|
||
},
|
||
"ai_accuracy": {
|
||
"auto_approve_threshold": 0.95,
|
||
"use_human_resolution_threshold": 0.9,
|
||
"manual_review_threshold": 0.8,
|
||
"ai_suggestion_confidence": 0.95,
|
||
"human_resolution_confidence": 0.9,
|
||
"prefer_human_when_low_accuracy": true,
|
||
"enable_auto_approval": true,
|
||
"enable_human_fallback": true
|
||
},
|
||
"system": {
|
||
"backup_enabled": true,
|
||
"backup_interval": 24,
|
||
"max_backup_files": 7,
|
||
"cache_enabled": true,
|
||
"cache_ttl": 3600,
|
||
"monitoring_enabled": true
|
||
}
|
||
}
|
||
|
||
################################################################################
|
||
# DEPRECATED CONFIGURATION FILE: src/config/config.py
|
||
################################################################################
|
||
import os
|
||
from typing import Dict, Any
|
||
|
||
class Config:
|
||
"""系统配置类"""
|
||
|
||
# 阿里云千问API配置
|
||
ALIBABA_API_KEY = "sk-c0dbefa1718d46eaa897199135066f00"
|
||
ALIBABA_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
||
ALIBABA_MODEL_NAME = "qwen-plus-latest"
|
||
|
||
# 数据库配置
|
||
DATABASE_URL = "mysql+pymysql://tsp_assistant:123456@jeason.online/tsp_assistant?charset=utf8mb4"
|
||
# DATABASE_URL = "sqlite:///local_test.db" # 本地测试数据库
|
||
|
||
# 知识库配置
|
||
KNOWLEDGE_BASE_PATH = "data/knowledge_base"
|
||
VECTOR_DB_PATH = "data/vector_db"
|
||
|
||
# 对话配置
|
||
MAX_HISTORY_LENGTH = 10
|
||
RESPONSE_TIMEOUT = 30
|
||
|
||
# 分析配置
|
||
ANALYTICS_UPDATE_INTERVAL = 3600 # 1小时
|
||
ALERT_THRESHOLD = 0.8 # 预警阈值
|
||
|
||
# 日志配置
|
||
LOG_LEVEL = "INFO"
|
||
LOG_FILE = "logs/tsp_assistant.log"
|
||
|
||
# 系统监控配置
|
||
SYSTEM_MONITORING = True # 是否启用系统监控
|
||
MONITORING_INTERVAL = 60 # 监控间隔(秒)
|
||
|
||
@classmethod
|
||
def get_api_config(cls) -> Dict[str, Any]:
|
||
"""获取API配置"""
|
||
return {
|
||
"api_key": cls.ALIBABA_API_KEY,
|
||
"base_url": cls.ALIBABA_BASE_URL,
|
||
"model_name": cls.ALIBABA_MODEL_NAME
|
||
}
|
||
|
||
@classmethod
|
||
def get_database_config(cls) -> Dict[str, Any]:
|
||
"""获取数据库配置"""
|
||
return {
|
||
"url": cls.DATABASE_URL,
|
||
"echo": False
|
||
}
|
||
|
||
@classmethod
|
||
def get_knowledge_config(cls) -> Dict[str, Any]:
|
||
"""获取知识库配置"""
|
||
return {
|
||
"base_path": cls.KNOWLEDGE_BASE_PATH,
|
||
"vector_db_path": cls.VECTOR_DB_PATH
|
||
}
|
||
|
||
@classmethod
|
||
def get_config(cls) -> Dict[str, Any]:
|
||
"""获取完整配置"""
|
||
return {
|
||
"system_monitoring": cls.SYSTEM_MONITORING,
|
||
"monitoring_interval": cls.MONITORING_INTERVAL,
|
||
"log_level": cls.LOG_LEVEL,
|
||
"log_file": cls.LOG_FILE,
|
||
"analytics_update_interval": cls.ANALYTICS_UPDATE_INTERVAL,
|
||
"alert_threshold": cls.ALERT_THRESHOLD
|
||
}
|
||
|