31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
"""意图识别节点:Jev 判断这次请求是不是明确的问答"""
|
|
|
|
from app.clients.decision import get_decision_engine
|
|
from app.processor.base import BaseNode
|
|
from app.processor.intent_policy import resolve_intent
|
|
from app.processor.state import QueryState
|
|
from app.processor.summary import request_summary
|
|
from app.prompt.intent import build_intent_question
|
|
from app.schemas.decision import DecisionRequest
|
|
|
|
|
|
class IntentNode(BaseNode):
|
|
name = "intent_node"
|
|
|
|
async def process(self, state: QueryState) -> QueryState:
|
|
updated_state: QueryState = state.copy()
|
|
context = state["input_context"]
|
|
request = DecisionRequest(
|
|
# Jev 只接收 JSON,会话历史作为 history 字段和本次请求放在一起
|
|
state={"history": context.history, **request_summary(context)},
|
|
decisions={"intent": build_intent_question()},
|
|
)
|
|
response = await get_decision_engine().run(request)
|
|
# 完整保留原始决策,便于在追踪中查看各选项的概率
|
|
updated_state["intent_decision"] = response
|
|
updated_state["intent"] = resolve_intent(
|
|
response.results["intent"],
|
|
qa_min_probability=self.config.intent_qa_min_probability,
|
|
)
|
|
return updated_state
|