feat: 引入deepseek结构化输出

This commit is contained in:
yangshilin
2026-03-19 11:27:43 +08:00
parent f3629efec3
commit 4c75c6f4f4
10 changed files with 74 additions and 26 deletions

View File

@@ -16,6 +16,7 @@ from app.agents.chat.prompts_profile import (
get_profile_followup_prompt,
get_profile_greeting_prompt,
)
from app.features.memoir.memoir_images.json_payload import extract_json_payload
logger = get_logger(__name__)
@@ -58,9 +59,13 @@ class ProfileAgent:
prompt = get_profile_extraction_prompt(
user_message, missing_fields, recent_dialogue=recent_dialogue or None
)
response = await self.llm.ainvoke(prompt)
json_llm = self.llm.bind(
model_kwargs={"response_format": {"type": "json_object"}},
max_tokens=512,
)
response = await json_llm.ainvoke(prompt)
content = response.content.strip()
parsed = json.loads(content)
parsed = json.loads(extract_json_payload(content))
result = {}
if "birth_year" in parsed and parsed["birth_year"] is not None:
raw = parsed["birth_year"]