导入方式修改
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m44s

This commit is contained in:
2026-05-05 23:17:00 +08:00
parent b5c15ef445
commit 3ae9daa01a
51 changed files with 445 additions and 532 deletions

View File

@@ -2,29 +2,24 @@
"""
主图完整测试 - 覆盖各个分支
"""
import sys
import asyncio
from pathlib import Path
from dotenv import load_dotenv
# 添加 backend 到路径
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "backend"))
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
from app.main_graph.utils.rag_initializer import init_rag_tool
from backend.app.main_graph.state import MainGraphState, CurrentAction
from backend.app.main_graph.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
from backend.app.main_graph.utils.rag_initializer import init_rag_tool
# ========== 测试用例配置 ==========
TEST_CASES = [
# # 测试1: 简单闲聊 - 应该走 fast_chitchat
# {
# "name": "闲聊测试",
# "query": "你好!",
# "description": "测试快速闲聊分支"
# },
# 测试1: 简单闲聊 - 应该走 fast_chitchat
{
"name": "闲聊测试",
"query": "你好!",
"description": "测试快速闲聊分支"
},
# 测试2: 知识查询 - 应该走 fast_rag然后可能升级到 react
{
"name": "知识查询测试",
@@ -37,12 +32,12 @@ TEST_CASES = [
"query": "请帮我分析如果我有10万元想要在一年内获得15%的收益,有哪些低风险的投资方案?",
"description": "测试 React 循环推理分支"
},
# # 测试4: 需要工具调用的问题
# {
# "name": "工具调用测试",
# "query": "搜索一下今天的天气怎么样",
# "description": "测试工具调用分支"
# },
# 测试4: 需要工具调用的问题
{
"name": "联网工具调用测试",
"query": "搜索一下今天的天气怎么样",
"description": "测试工具调用分支"
},
# 测试5: 带记忆的对话
{
"name": "记忆测试",
@@ -64,22 +59,18 @@ async def setup_test_environment():
if not chat_services:
raise RuntimeError("没有可用的 LLM 服务")
llm = list(chat_services.values())[0]
print(f"✓ 使用 LLM: {list(chat_services.keys())[0]}")
print(f"✓ 可用模型: {list(chat_services.keys())}")
# 初始化 RAG 工具
def create_local_llm():
return llm
rag_tool = await init_rag_tool(create_local_llm)
rag_tool = await init_rag_tool()
tools = AVAILABLE_TOOLS.copy()
if rag_tool:
tools.append(rag_tool)
print(f"✓ RAG 工具初始化成功")
# 构建图
# 构建图(使用新的 API: chat_services 而不是 llm
graph = build_react_main_graph(
llm=llm,
chat_services=chat_services,
tools=tools,
use_hybrid_router=True
).compile()