fix: 修复 process_message_stream 中缺少 GraphContext 的问题
问题:
- 在 9d4cf15 提交中只更新了 process_message 方法,但没有更新 process_message_stream 方法
- process_message_stream 还在使用旧代码中的 GraphContext,导致报错 'name GraphContext is not defined'
修复:
- 移除了 GraphContext 的使用
- 更新 input_state 为新的 MainGraphState 格式
- 从 graph.astream() 中移除了 context 参数
This commit is contained in:
@@ -14,6 +14,7 @@ from ..model_services.chat_services import get_all_chat_services, LocalVLLMChatP
|
|||||||
from app.main_graph.utils.rag_initializer import init_rag_tool
|
from app.main_graph.utils.rag_initializer import init_rag_tool
|
||||||
from app.core.intent_classifier import get_intent_classifier
|
from app.core.intent_classifier import get_intent_classifier
|
||||||
from app.logger import info, warning
|
from app.logger import info, warning
|
||||||
|
from app.main_graph.state import MainGraphState, CurrentAction
|
||||||
|
|
||||||
class AIAgentService:
|
class AIAgentService:
|
||||||
def __init__(self, checkpointer):
|
def __init__(self, checkpointer):
|
||||||
@@ -120,8 +121,12 @@ class AIAgentService:
|
|||||||
"configurable": {"thread_id": thread_id},
|
"configurable": {"thread_id": thread_id},
|
||||||
"metadata": {"user_id": user_id}
|
"metadata": {"user_id": user_id}
|
||||||
}
|
}
|
||||||
input_state = {"messages": [{"role": "user", "content": message}]}
|
input_state = {
|
||||||
context = GraphContext(user_id=user_id)
|
"user_query": message,
|
||||||
|
"messages": [{"role": "user", "content": message}],
|
||||||
|
"user_id": user_id,
|
||||||
|
"current_action": CurrentAction.NONE
|
||||||
|
}
|
||||||
|
|
||||||
# ========== 新增:混合路由 ==========
|
# ========== 新增:混合路由 ==========
|
||||||
intent_result = await self.intent_classifier.classify(message)
|
intent_result = await self.intent_classifier.classify(message)
|
||||||
@@ -161,7 +166,6 @@ class AIAgentService:
|
|||||||
async for chunk in graph.astream(
|
async for chunk in graph.astream(
|
||||||
input_state,
|
input_state,
|
||||||
config=config,
|
config=config,
|
||||||
context=context,
|
|
||||||
stream_mode=["messages", "updates", "custom"],
|
stream_mode=["messages", "updates", "custom"],
|
||||||
version="v2",
|
version="v2",
|
||||||
subgraphs=True
|
subgraphs=True
|
||||||
|
|||||||
Reference in New Issue
Block a user