修复代码,实现rag测试
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 6m11s

This commit is contained in:
2026-05-04 20:31:04 +08:00
parent 0543a4da8b
commit acc8d801f3
5 changed files with 15 additions and 31 deletions

View File

@@ -17,6 +17,7 @@ from app.main_graph.utils.retry_utils import (
RAG_RETRY_CONFIG, RAG_RETRY_CONFIG,
create_retry_wrapper_for_node create_retry_wrapper_for_node
) )
from app.logger import info
# 真正导入和利用已有 RAG 代码 # 真正导入和利用已有 RAG 代码
from app.rag.tools import create_rag_tool from app.rag.tools import create_rag_tool
@@ -95,7 +96,7 @@ def inject_rag_tool_to_state(state: MainGraphState, rag_tool: Any) -> MainGraphS
return state return state
# ========== RAG 检索核心逻辑(真正利用已有代码) ========== # ========== RAG 检索核心逻辑(真正利用已有代码)==========
async def _rag_retrieve_core(state: MainGraphState) -> MainGraphState: async def _rag_retrieve_core(state: MainGraphState) -> MainGraphState:
""" """
RAG 检索核心逻辑(真正利用 rag/tools.py - 异步版本 RAG 检索核心逻辑(真正利用 rag/tools.py - 异步版本
@@ -158,7 +159,7 @@ async def _rag_retrieve_core(state: MainGraphState) -> MainGraphState:
raise RuntimeError("RAG 工具未初始化,请先调用 set_global_rag_tool() 或 set_global_rag_pipeline()") raise RuntimeError("RAG 工具未初始化,请先调用 set_global_rag_tool() 或 set_global_rag_pipeline()")
# ========== RAG 检索节点(带超时和重试) ========== # ========== RAG 检索节点(带超时和重试)==========
async def rag_retrieve_node(state: MainGraphState, config: Optional[Dict[str, Any]] = None) -> MainGraphState: async def rag_retrieve_node(state: MainGraphState, config: Optional[Dict[str, Any]] = None) -> MainGraphState:
""" """
RAG 检索节点:带超时和重试,真正利用已有 RAG 代码 RAG 检索节点:带超时和重试,真正利用已有 RAG 代码

View File

@@ -44,9 +44,6 @@ class ErrorRecord:
@dataclass @dataclass
class MainGraphState: class MainGraphState:
""" """
主图状态 - 整合了旧 MessagesState 的所有字段
包含:
- 旧代码的 MessagesState 兼容性字段 - 旧代码的 MessagesState 兼容性字段
- React 推理控制字段 - React 推理控制字段
- 循环和错误处理 - 循环和错误处理
@@ -69,7 +66,7 @@ class MainGraphState:
# ========== React 推理专用字段 ========== # ========== React 推理专用字段 ==========
reasoning_step: int = 0 reasoning_step: int = 0
max_steps: int = 40 max_steps: int = 10 # 从 40 改到 10避免过长循环
last_action: str = "" last_action: str = ""
reasoning_history: List[Dict[str, Any]] = field(default_factory=list) reasoning_history: List[Dict[str, Any]] = field(default_factory=list)

View File

@@ -2,21 +2,12 @@
""" """
快速测试 - 测试 fast_rag 路径修复 快速测试 - 测试 fast_rag 路径修复
""" """
import sys
import asyncio import asyncio
from pathlib import Path from backend.app.main_graph.state import MainGraphState, CurrentAction
from dotenv import load_dotenv from backend.app.main_graph.utils.main_graph_builder import build_react_main_graph
from backend.app.model_services.chat_services import get_all_chat_services
# 路径设置 from backend.app.main_graph.tools.graph_tools import AVAILABLE_TOOLS
project_root = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(project_root))
sys.path.insert(0, str(project_root / "backend"))
load_dotenv(project_root / ".env")
from app.main_graph.state import MainGraphState, CurrentAction
from app.main_graph.utils.main_graph_builder import build_react_main_graph
from app.model_services.chat_services import get_all_chat_services
from app.main_graph.tools.graph_tools import AVAILABLE_TOOLS
async def test_fast_rag_path(): async def test_fast_rag_path():

View File

@@ -7,17 +7,12 @@ import asyncio
from pathlib import Path from pathlib import Path
from dotenv import load_dotenv from dotenv import load_dotenv
# 路径设置
project_root = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(project_root))
sys.path.insert(0, str(project_root / "backend"))
load_dotenv(project_root / ".env")
from app.main_graph.state import MainGraphState, CurrentAction from backend.app.main_graph.state import MainGraphState, CurrentAction
from app.main_graph.utils.main_graph_builder import build_react_main_graph from backend.app.main_graph.utils.main_graph_builder import build_react_main_graph
from app.model_services.chat_services import get_all_chat_services from backend.app.model_services.chat_services import get_all_chat_services
from app.main_graph.tools.graph_tools import AVAILABLE_TOOLS from backend.app.main_graph.tools.graph_tools import AVAILABLE_TOOLS
from app.main_graph.utils.rag_initializer import init_rag_tool from backend.app.main_graph.utils.rag_initializer import init_rag_tool
# ========== 测试用例配置 ========== # ========== 测试用例配置 ==========