mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 20:01:04 +00:00
[fix] (llm_analyzer) 健壮的处理,安全访问LLM服务返回的嵌套字段
This commit is contained in:
@@ -56,8 +56,21 @@ class LLMAnalyzer:
|
||||
except Exception as json_err:
|
||||
error_text = await resp.text()
|
||||
logger.error(f"自定义LLM服务商响应JSON解析失败: {json_err}, 内容: {error_text}")
|
||||
# 兼容 OpenAI 格式
|
||||
content = response_json["choices"][0]["message"]["content"]
|
||||
return None
|
||||
# 兼容 OpenAI 格式,安全访问嵌套字段
|
||||
content = None
|
||||
try:
|
||||
choices = response_json.get("choices")
|
||||
if choices and isinstance(choices, list) and len(choices) > 0:
|
||||
message = choices[0].get("message")
|
||||
if message and isinstance(message, dict):
|
||||
content = message.get("content")
|
||||
if content is None:
|
||||
logger.error(f"自定义LLM响应格式异常: {response_json}")
|
||||
return None
|
||||
except Exception as key_err:
|
||||
logger.error(f"自定义LLM响应结构解析失败: {key_err}, 响应内容: {response_json}")
|
||||
return None
|
||||
# 构造一个兼容原有逻辑的对象
|
||||
class CustomResponse:
|
||||
completion_text = content
|
||||
|
||||
Reference in New Issue
Block a user