feat:完成重构和测试
This commit is contained in:
@@ -14,8 +14,10 @@ class IntentNode(BaseNode):
|
||||
|
||||
async def process(self, state: QueryState) -> QueryState:
|
||||
updated_state: QueryState = state.copy()
|
||||
context = state["input_context"]
|
||||
request = DecisionRequest(
|
||||
state=request_summary(state["input_context"]),
|
||||
# Jev 只接收 JSON,会话历史作为 history 字段和本次请求放在一起
|
||||
state={"history": context.history, **request_summary(context)},
|
||||
decisions={"intent": build_intent_question()},
|
||||
)
|
||||
response = await get_decision_engine().run(request)
|
||||
|
||||
@@ -6,6 +6,7 @@ from langgraph.config import get_stream_writer
|
||||
|
||||
from app.clients.llm import get_llm
|
||||
from app.processor.base import BaseNode
|
||||
from app.processor.history import history_messages
|
||||
from app.processor.state import QueryState
|
||||
from app.prompt.qa import QA_SYSTEM_PROMPT
|
||||
|
||||
@@ -24,11 +25,16 @@ class QANode(BaseNode):
|
||||
|
||||
parser = StrOutputParser()
|
||||
parts: list[str] = []
|
||||
context = state["input_context"]
|
||||
async for chunk in get_llm().astream(
|
||||
[
|
||||
SystemMessage(content=QA_SYSTEM_PROMPT),
|
||||
# 会话历史作为此前的对话消息,本次请求是最后一条用户消息
|
||||
*history_messages(context.history),
|
||||
HumanMessage(
|
||||
content=state["input_context"].model_dump_json(exclude_unset=True)
|
||||
content=context.model_dump_json(
|
||||
exclude_unset=True, exclude={"history"}
|
||||
)
|
||||
),
|
||||
]
|
||||
):
|
||||
|
||||
@@ -10,6 +10,7 @@ from langchain_core.messages import HumanMessage
|
||||
from app.agent.screen_agent import AgentReply, get_screen_agent
|
||||
from app.agent.tools import ScreenAgentContext
|
||||
from app.processor.base import BaseNode
|
||||
from app.processor.history import history_messages
|
||||
from app.processor.state import QueryState
|
||||
from app.processor.summary import request_summary
|
||||
from app.resources.component import get_catalog_cache
|
||||
@@ -55,10 +56,12 @@ class ScreenAgentNode(BaseNode):
|
||||
agent = await get_screen_agent()
|
||||
result = await agent.ainvoke(
|
||||
{
|
||||
# 会话历史作为此前的对话消息,本次请求是最后一条用户消息
|
||||
"messages": [
|
||||
*history_messages(context.history),
|
||||
HumanMessage(
|
||||
content=json.dumps(request_summary(context), ensure_ascii=False)
|
||||
)
|
||||
),
|
||||
]
|
||||
},
|
||||
context=ScreenAgentContext(screen=context.screen, catalog=catalog),
|
||||
|
||||
Reference in New Issue
Block a user