refactor: 整理文件夹结构,修复 create_serde 导入问题
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m50s
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m50s
- 移动 main_graph/tools/ 到 deprecated/main_graph_tools/(旧架构工具) - 移动 rag_initializer.py 和 retry_utils.py 到 core/ - 清理 main_graph/nodes/ 里的旧节点到 deprecated/ - 修复 backend.py 中 create_serde 导入问题
This commit is contained in:
55
backend/app/deprecated/main_graph_tools/common_tools.py
Normal file
55
backend/app/deprecated/main_graph_tools/common_tools.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
公共工具模块 - 联网搜索、可视化图表等公共功能
|
||||
Common Tools Module - Web search, visualization, etc.
|
||||
"""
|
||||
|
||||
from langchain_core.tools import tool
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@tool
|
||||
def web_search_tool(query: str, max_results: int = 5) -> str:
|
||||
"""
|
||||
联网搜索工具 - 无需 API Key,使用 DuckDuckGo 免费搜索
|
||||
|
||||
Args:
|
||||
query: 搜索关键词或问题
|
||||
max_results: 返回结果数量,默认 5 条
|
||||
|
||||
Returns:
|
||||
格式化的搜索结果,包含引用溯源
|
||||
"""
|
||||
try:
|
||||
from backend.app.core import web_search
|
||||
return web_search(query, max_results)
|
||||
except Exception as e:
|
||||
return f"联网搜索出错:{str(e)}"
|
||||
|
||||
|
||||
@tool
|
||||
def generate_chart_tool(data_text: str, chart_type: str = "bar") -> str:
|
||||
"""
|
||||
可视化图表工具 - 生成 Mermaid 格式图表
|
||||
|
||||
Args:
|
||||
data_text: 图表数据文本,格式:标题,标签1:值1,标签2:值2,...
|
||||
示例:月度销售额,1月:100,2月:150,3月:200
|
||||
chart_type: 图表类型,可选:bar(柱状图)、line(折线图)、pie(饼图)
|
||||
|
||||
Returns:
|
||||
格式化的图表输出(Mermaid 格式)
|
||||
"""
|
||||
try:
|
||||
from backend.app.core import generate_chart
|
||||
return generate_chart(data_text, chart_type)
|
||||
except Exception as e:
|
||||
return f"生成图表出错:{str(e)}\n\n请使用格式:标题,标签1:值1,标签2:值2,..."
|
||||
|
||||
|
||||
# 公共工具列表
|
||||
COMMON_TOOLS = [
|
||||
web_search_tool,
|
||||
generate_chart_tool
|
||||
]
|
||||
|
||||
COMMON_TOOLS_BY_NAME = {tool.name: tool for tool in COMMON_TOOLS}
|
||||
Reference in New Issue
Block a user