[fix]LLM formatted output
This commit is contained in:
@@ -542,15 +542,14 @@ class EmotionAnalyticsService:
|
|||||||
{"role": "user", "content": prompt}
|
{"role": "user", "content": prompt}
|
||||||
]
|
]
|
||||||
|
|
||||||
response = await llm_client.chat(messages=messages)
|
# 8. 使用结构化输出直接获取 Pydantic 模型
|
||||||
response_text = response.content.strip()
|
|
||||||
|
|
||||||
# 8. 解析LLM响应
|
|
||||||
try:
|
try:
|
||||||
response_data = json.loads(response_text)
|
suggestions_response = await llm_client.response_structured(
|
||||||
suggestions_response = EmotionSuggestionsResponse(**response_data)
|
messages=messages,
|
||||||
except (json.JSONDecodeError, Exception) as e:
|
response_model=EmotionSuggestionsResponse
|
||||||
logger.error(f"解析LLM响应失败: {str(e)}, response={response_text}")
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"LLM 结构化输出失败: {str(e)}")
|
||||||
# 返回默认建议
|
# 返回默认建议
|
||||||
suggestions_response = self._get_default_suggestions(health_data)
|
suggestions_response = self._get_default_suggestions(health_data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user