feat: 引入deepseek结构化输出
This commit is contained in:
@@ -57,6 +57,7 @@ from app.agents.memoir.prompts import (
|
||||
inject_image_placeholder_template,
|
||||
STAGE_TO_ORDER,
|
||||
)
|
||||
from app.features.memoir.memoir_images.json_payload import extract_json_payload
|
||||
from app.features.memoir.memoir_images.parser import split_narrative_to_sections
|
||||
from app.core.logging import get_logger, setup_logging
|
||||
|
||||
@@ -200,8 +201,12 @@ def extract_slots_with_llm(llm, text: str, current_stage: str, stage_slots: dict
|
||||
current_stage=current_stage,
|
||||
stage_slots=stage_slots,
|
||||
)
|
||||
response = llm.invoke(prompt)
|
||||
parsed = json.loads(response.content.strip())
|
||||
json_llm = llm.bind(
|
||||
model_kwargs={"response_format": {"type": "json_object"}},
|
||||
max_tokens=1024,
|
||||
)
|
||||
response = json_llm.invoke(prompt)
|
||||
parsed = json.loads(extract_json_payload(response.content.strip()))
|
||||
return parsed.get("detected_stage", current_stage), parsed.get("slots", {}) or {}
|
||||
except Exception as e:
|
||||
logger.warning(f"LLM slot 提取失败: {e}")
|
||||
|
||||
Reference in New Issue
Block a user