bugfix:修复部分提示词导致的格式错误问题及langfuse客户端复用bug
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
import json
|
||||
|
||||
from langchain_core.exceptions import OutputParserException
|
||||
from langchain_core.messages import HumanMessage, SystemMessage
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app.clients.llm import get_llm
|
||||
from app.processor.base import BaseNode
|
||||
@@ -28,14 +30,39 @@ class ClarifyNode(BaseNode):
|
||||
payload["requirement"] = state["requirement"].model_dump(mode="json")
|
||||
|
||||
llm_client = get_llm(Clarification)
|
||||
clarification = await llm_client.ainvoke(
|
||||
[
|
||||
SystemMessage(content=CLARIFY_SYSTEM_PROMPT),
|
||||
HumanMessage(content=json.dumps(payload, ensure_ascii=False)),
|
||||
]
|
||||
)
|
||||
messages = [
|
||||
SystemMessage(content=CLARIFY_SYSTEM_PROMPT),
|
||||
HumanMessage(content=json.dumps(payload, ensure_ascii=False)),
|
||||
]
|
||||
|
||||
# 格式错误重试一次
|
||||
for attempt in range(2):
|
||||
try:
|
||||
clarification = await llm_client.ainvoke(messages)
|
||||
break
|
||||
except (ValidationError, OutputParserException):
|
||||
if attempt == 0:
|
||||
# 要求重新生成完整问题,避免截断选项改变原意
|
||||
messages.append(
|
||||
HumanMessage(
|
||||
content=(
|
||||
"上次输出未通过 Clarification 格式校验,请重新生成完整结果:"
|
||||
"question 为非空问题,options 为空或含 2–3 项,"
|
||||
"每项包含唯一 id、非空 label 和 description,最多一个 recommended=true"
|
||||
)
|
||||
)
|
||||
)
|
||||
continue
|
||||
# 连续格式失败时退回自由回答,需求阶段沿用已确定的问题
|
||||
requirement = state.get("requirement") if intent != "unclear" else None
|
||||
question = (
|
||||
requirement.clarification_question if requirement else None
|
||||
) or "你希望我对当前大屏做什么?可以描述想修改的内容,或想了解的问题"
|
||||
clarification = Clarification(question=question)
|
||||
|
||||
updated_state["clarification"] = clarification
|
||||
# 在进入 interrupt 前保存等待状态,暂停中的节点尚不会返回更新
|
||||
updated_state["status"] = "waiting_for_input"
|
||||
return updated_state
|
||||
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ class InputNode(BaseNode):
|
||||
updated_state["retry_count"] = 0
|
||||
updated_state["repair_plan"] = None
|
||||
updated_state["failure_reason"] = None
|
||||
# 首次请求进入处理状态,恢复澄清时也使用同一状态
|
||||
updated_state["status"] = "running"
|
||||
return updated_state
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ class QANode(BaseNode):
|
||||
if not answer:
|
||||
raise ValueError("问答模型未返回文本回答")
|
||||
updated_state["answer"] = answer
|
||||
# 回答生成完成,问答分支在此结束
|
||||
updated_state["status"] = "completed"
|
||||
return updated_state
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ class ValidatorNode(BaseNode):
|
||||
|
||||
def process(self, state: QueryState) -> QueryState:
|
||||
updated_state: QueryState = state.copy()
|
||||
# 校验失败仍可能进入修正循环,最终失败由 Fallback 标记
|
||||
updated_state["status"] = "running"
|
||||
actions = state["actions"]
|
||||
try:
|
||||
# 重新校验模型内容,避免赋值后绕过字段校验
|
||||
@@ -130,6 +132,8 @@ class ValidatorNode(BaseNode):
|
||||
updated_state["validation_errors"] = []
|
||||
# 保存整批动作执行后的 JSON,供后续检查,不代表前端已经完成更新
|
||||
updated_state["simulated_screen"] = screen
|
||||
# 仅表示后端动作已通过校验,前端执行结果需另行反馈
|
||||
updated_state["status"] = "completed"
|
||||
return updated_state
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user