优化AI服务的内容提取逻辑,增强对API返回结果的处理能力,改进JSON解析和错误处理机制,确保在提取数据失败时能够返回空结果而不抛出异常,同时记录详细的调试信息以提高容错性和可维护性。
This commit is contained in:
parent
315301fc0b
commit
9bf1dd1210
Binary file not shown.
@ -472,13 +472,28 @@ class AIService:
|
||||
self.ai_logger.log_conversation(
|
||||
prompt=prompt,
|
||||
api_request=api_request_info,
|
||||
api_response=None,
|
||||
api_response=result,
|
||||
extracted_data=None,
|
||||
error=error_msg,
|
||||
session_id=session_id
|
||||
)
|
||||
raise Exception(error_msg)
|
||||
|
||||
except Exception as e:
|
||||
# 如果发生异常,记录错误日志
|
||||
error_msg = str(e)
|
||||
if self.ai_logger:
|
||||
self.ai_logger.log_conversation(
|
||||
prompt=prompt,
|
||||
api_request=api_request_info,
|
||||
api_response=None,
|
||||
extracted_data=None,
|
||||
error=error_msg,
|
||||
session_id=session_id
|
||||
)
|
||||
# 重新抛出异常,让上层处理
|
||||
raise
|
||||
|
||||
def _extract_json_from_text(self, text: str) -> Optional[Dict]:
|
||||
"""
|
||||
从文本中提取JSON对象
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user