错误信息: 'Logger' object has no attribute '_get_timestamp'
原因: 错误使用了不存在的 logger._get_timestamp()
方法
修复:
src/services/ai_service.py
中使用 datetime.now().strftime()
替代from datetime import datetime
导入错误信息: 问题分类失败: '\n "question_type"'
原因: LLM返回的JSON格式不标准,导致解析失败
修复:
src/agents/orchestrator.py
中的JSON解析逻辑_parse_classification_response()
方法,增强容错性_fallback_classification()
后备分类方法原因: LangChain库的导入路径变更
修复:
from langchain.embeddings import OpenAIEmbeddings
from langchain_openai import OpenAIEmbeddings
def _parse_classification_response(self, content: str) -> Dict[str, Any]:
"""解析分类响应,增强容错性"""
try:
# 尝试直接解析JSON
return json.loads(content)
except json.JSONDecodeError:
# 提取JSON部分
start_idx = content.find('{')
end_idx = content.rfind('}')
if start_idx != -1 and end_idx != -1:
json_content = content[start_idx:end_idx + 1]
return json.loads(json_content)
# 后备分类
return self._fallback_classification(content)
当JSON解析完全失败时,基于关键词进行分类:
重新启动服务:
python main.py
测试聊天接口:
curl -X POST "http://localhost:8000/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{"message": "你好,我想进行物料入库"}'
使用测试工具:
python test_fix.py
建议在生产环境中监控以下指标:
修复后的系统具有更好的容错性: