主要修复: 1. 修复 RAG 推理无限循环问题(大小写不匹配 + 缺少已检索结果检查) 2. 修复 intent_classifier.py 的绝对导入错误 3. 删除旧的 start.sh 脚本,添加新的启动脚本 4. 优化路由逻辑和状态管理
This commit is contained in:
@@ -8,10 +8,10 @@ from typing import Dict, Any, Optional, List
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
|
||||
from app.main_graph.state import MainGraphState
|
||||
from app.logger import info, debug
|
||||
from app.model_services.chat_services import get_small_llm_service, get_chat_service
|
||||
from app.main_graph.nodes.rag_nodes import rag_retrieve_node
|
||||
from ..state import MainGraphState
|
||||
from ...logger import info, debug
|
||||
from ...model_services.chat_services import get_small_llm_service, get_chat_service
|
||||
from .rag_nodes import rag_retrieve_node
|
||||
|
||||
|
||||
# ========== 核心数据类型 ==========
|
||||
@@ -367,8 +367,8 @@ async def fast_rag_node(state: MainGraphState, config: Optional[Dict[str, Any]]
|
||||
debug(f"[Fast RAG] 发送事件失败: {e}")
|
||||
|
||||
try:
|
||||
# 先尝试 RAG 检索
|
||||
state = rag_retrieve_node(state, config)
|
||||
# 先尝试 RAG 检索 - 注意:rag_retrieve_node 是异步函数,需要 await
|
||||
state = await rag_retrieve_node(state, config)
|
||||
|
||||
# 检查检索结果
|
||||
rag_docs = getattr(state, "rag_docs", [])
|
||||
|
||||
@@ -364,11 +364,15 @@ def route_by_reasoning(state: MainGraphState) -> str:
|
||||
if "subgraph_completed" in previous_actions or state.final_result:
|
||||
return "llm_call"
|
||||
|
||||
# 关键修复:如果已经执行过 rag_retrieve 并且又执行过推理,直接去 LLM_CALL
|
||||
# 这样的流程:推理1 → RAG → 推理2(判断 RAG 结果) → LLM_CALL
|
||||
rag_count = previous_actions.count("rag_retrieve")
|
||||
if rag_count >= 1 and len(previous_actions) >= rag_count + 1:
|
||||
info(f"[route_by_reasoning] 已完成 RAG 检索和结果判断,直接去 llm_call")
|
||||
# 关键修复:检测 RAG 重复循环 - 如果发现"RETRIEVE_RAG"出现超过1次,直接去 LLM
|
||||
rag_count = previous_actions.count("RETRIEVE_RAG")
|
||||
if rag_count >= 2:
|
||||
info(f"[route_by_reasoning] 检测到 RAG 重复循环({rag_count}次),直接去 llm_call")
|
||||
return "llm_call"
|
||||
|
||||
# 关键修复:如果已经有 rag_docs 或 rag_context,说明已经检索过了,直接去 LLM
|
||||
if (state.rag_docs and len(state.rag_docs) > 0) or (state.rag_context and len(state.rag_context) > 0):
|
||||
info(f"[route_by_reasoning] 检测到已存在 RAG 检索结果,直接去 llm_call")
|
||||
return "llm_call"
|
||||
|
||||
# 关键修复:限制最多 3 次推理,避免无限循环
|
||||
|
||||
Reference in New Issue
Block a user