删除前端子图测试代码
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 21m29s

- 删除 sidebar.py 中的子图测试面板
- 删除 subgraph_panel.py 文件
- 删除 api_client.py 中的子图 API 调用代码
This commit is contained in:
2026-04-27 15:31:52 +08:00
parent 048f57a89f
commit 0cb9571db7
3 changed files with 8 additions and 308 deletions

View File

@@ -24,8 +24,7 @@ class APIClient:
""" """
self.base_url = (base_url or config.api_base).rstrip("/") self.base_url = (base_url or config.api_base).rstrip("/")
# ==================== 历史管理接口 ==================== # ==================== 历史管理接口 ====================\n
def get_user_threads(self, user_id: str, limit: int = None) -> List[Dict[str, Any]]: def get_user_threads(self, user_id: str, limit: int = None) -> List[Dict[str, Any]]:
""" """
获取用户的历史对话列表 获取用户的历史对话列表
@@ -113,8 +112,7 @@ class APIClient:
error(f"获取线程摘要异常: {e}") error(f"获取线程摘要异常: {e}")
return {"summary": "加载失败", "message_count": 0} return {"summary": "加载失败", "message_count": 0}
# ==================== 聊天接口 ==================== # ==================== 聊天接口 ====================\n
def chat_stream( def chat_stream(
self, self,
message: str, message: str,
@@ -133,11 +131,11 @@ class APIClient:
Yields: Yields:
SSE 事件字典,类型包括: SSE 事件字典,类型包括:
- token: 逐字输出 {type: "token", content: "..."} - token: 逐字输出 {type: \"token\", content: \"...\"}
- tool_start: 工具调用开始 {type: "tool_start", tool: "..."} - tool_start: 工具调用开始 {type: \"tool_start\", tool: \"...\"}
- tool_end: 工具调用完成 {type: "tool_end", tool: "..."} - tool_end: 工具调用完成 {type: \"tool_end\", tool: \"...\"}
- done: 对话完成 {type: "done", token_usage: {...}, elapsed_time: ...} - done: 对话完成 {type: \"done\", token_usage: {...}, elapsed_time: ...}
- error: 错误信息 {type: "error", message: "..."} - error: 错误信息 {type: \"error\", message: \"...\"}
""" """
payload = { payload = {
"message": message, "message": message,
@@ -186,8 +184,7 @@ class APIClient:
"message": f"请求失败: {str(e)}" "message": f"请求失败: {str(e)}"
} }
# ==================== 审核接口 ==================== # ==================== 审核接口 ====================\n
def get_pending_reviews(self, limit: int = 100) -> List[Dict[str, Any]]: def get_pending_reviews(self, limit: int = 100) -> List[Dict[str, Any]]:
""" """
获取待审核列表 获取待审核列表
@@ -379,70 +376,6 @@ class APIClient:
error(f"请求审核异常: {e}") error(f"请求审核异常: {e}")
return "" return ""
# ==================== 子图专用 API ====================
def call_dictionary_subgraph(self, action: str, query: str = "", user_id: str = "default") -> dict:
"""调用词典子图"""
try:
resp = requests.get(
f"{self.base_url}/subgraph/dictionary/{action}",
params={"query": query, "user_id": user_id},
timeout=10
)
if resp.status_code == 200:
return resp.json()
else:
warning(f"调用词典子图失败: HTTP {resp.status_code}")
return {"success": False, "error": "HTTP错误"}
except Exception as e:
error(f"调用词典子图异常: {e}")
return {"success": False, "error": str(e)}
def call_news_subgraph(self, action: str, query: str = "", user_id: str = "default") -> dict:
"""调用资讯子图"""
try:
resp = requests.get(
f"{self.base_url}/subgraph/news/{action}",
params={"query": query, "user_id": user_id},
timeout=10
)
if resp.status_code == 200:
return resp.json()
else:
warning(f"调用资讯子图失败: HTTP {resp.status_code}")
return {"success": False, "error": "HTTP错误"}
except Exception as e:
error(f"调用资讯子图异常: {e}")
return {"success": False, "error": str(e)}
def call_contact_subgraph(self, action: str, query: str = "", user_id: str = "default") -> dict:
"""调用通讯录子图"""
try:
resp = requests.get(
f"{self.base_url}/subgraph/contact/{action}",
params={"query": query, "user_id": user_id},
timeout=10
)
if resp.status_code == 200:
return resp.json()
else:
warning(f"调用通讯录子图失败: HTTP {resp.status_code}")
return {"success": False, "error": "HTTP错误"}
except Exception as e:
error(f"调用通讯录子图异常: {e}")
return {"success": False, "error": str(e)}
def get_subgraph_help(self) -> dict:
"""获取子图 API 使用帮助"""
try:
resp = requests.get(f"{self.base_url}/subgraph/help", timeout=5)
if resp.status_code == 200:
return resp.json()
else:
return {}
except Exception as e:
return {}
# 全局 API 客户端实例(单例模式) # 全局 API 客户端实例(单例模式)
api_client = APIClient() api_client = APIClient()

View File

@@ -22,17 +22,6 @@ def render_sidebar():
st.divider() st.divider()
_render_user_section() _render_user_section()
# 子图测试面板:放在最底部的角落里
st.divider()
with st.expander("🔧 测试工具", expanded=False):
from components.subgraph_panel import _render_dictionary_panel, _render_news_panel, _render_contact_panel
st.caption("📚 词典子图")
_render_dictionary_panel()
st.caption("📰 资讯子图")
_render_news_panel()
st.caption("📇 通讯录子图")
_render_contact_panel()
def _render_user_section(): def _render_user_section():
"""渲染用户登录区域""" """渲染用户登录区域"""
# st.header("👤 用户") # 移除显眼的标题,改用更柔和的 caption # st.header("👤 用户") # 移除显眼的标题,改用更柔和的 caption

View File

@@ -1,222 +0,0 @@
"""
子图测试面板组件
包含词典、资讯、通讯录三个子图的测试界面
使用确定取消继续交互
"""
import streamlit as st
from api_client import api_client
from state import AppState
def render_subgraph_panel():
"""渲染子图测试面板"""
st.markdown("## 🔧 子图测试面板")
with st.expander("📚 词典子图", expanded=False):
_render_dictionary_panel()
with st.expander("📰 资讯子图", expanded=False):
_render_news_panel()
with st.expander("📇 通讯录子图", expanded=False):
_render_contact_panel()
def _render_dictionary_panel():
"""渲染词典子图测试面板"""
# 会话状态管理
if "dict_action" not in st.session_state:
st.session_state.dict_action = "auto"
if "dict_query" not in st.session_state:
st.session_state.dict_query = ""
if "dict_result" not in st.session_state:
st.session_state.dict_result = None
if "dict_confirm" not in st.session_state:
st.session_state.dict_confirm = False
# 选择 Action
action_col1, action_col2 = st.columns([1, 2])
with action_col1:
action = st.selectbox(
"操作",
options=["auto", "query", "translate", "daily", "extract"],
index=["auto", "query", "translate", "daily", "extract"].index(st.session_state.dict_action),
key="dict_action_selector"
)
with action_col2:
query = st.text_input("查询内容", value=st.session_state.dict_query, key="dict_query_input")
# 按钮行
btn_col1, btn_col2, btn_col3 = st.columns([1, 1, 1])
with btn_col1:
if st.button("▶️ 运行", key="dict_run", use_container_width=True):
st.session_state.dict_action = action
st.session_state.dict_query = query
with st.spinner("调用子图中..."):
result = api_client.call_dictionary_subgraph(action, query)
st.session_state.dict_result = result
st.session_state.dict_confirm = False
st.rerun()
# 显示结果
if st.session_state.dict_result:
result = st.session_state.dict_result
if result.get("success"):
st.success("✅ 调用成功")
st.markdown("### 结果")
st.markdown(result.get("result", ""))
# 确定/取消/继续按钮
confirm_col1, confirm_col2, confirm_col3 = st.columns([1, 1, 1])
with confirm_col1:
if st.button("✅ 确定", key="dict_confirm", use_container_width=True):
st.session_state.dict_confirm = True
st.info("已确认结果")
with confirm_col2:
if st.button("❌ 取消", key="dict_cancel", use_container_width=True):
st.session_state.dict_result = None
st.rerun()
with confirm_col3:
if st.button("⏭️ 继续", key="dict_continue", use_container_width=True):
st.session_state.dict_confirm = True
st.info("已继续")
# 显示原始数据(可选)
with st.expander("🔍 原始数据", expanded=False):
st.json(result.get("raw_data", {}))
else:
st.error(f"❌ 调用失败: {result.get('error')}")
def _render_news_panel():
"""渲染资讯子图测试面板"""
# 会话状态管理
if "news_action" not in st.session_state:
st.session_state.news_action = "auto"
if "news_query" not in st.session_state:
st.session_state.news_query = ""
if "news_result" not in st.session_state:
st.session_state.news_result = None
if "news_confirm" not in st.session_state:
st.session_state.news_confirm = False
# 选择 Action
action_col1, action_col2 = st.columns([1, 2])
with action_col1:
action = st.selectbox(
"操作",
options=["auto", "query", "analyze", "keywords", "report"],
index=["auto", "query", "analyze", "keywords", "report"].index(st.session_state.news_action),
key="news_action_selector"
)
with action_col2:
query = st.text_input("查询内容/URL", value=st.session_state.news_query, key="news_query_input")
# 按钮行
btn_col1, btn_col2, btn_col3 = st.columns([1, 1, 1])
with btn_col1:
if st.button("▶️ 运行", key="news_run", use_container_width=True):
st.session_state.news_action = action
st.session_state.news_query = query
with st.spinner("调用子图中..."):
result = api_client.call_news_subgraph(action, query)
st.session_state.news_result = result
st.session_state.news_confirm = False
st.rerun()
# 显示结果
if st.session_state.news_result:
result = st.session_state.news_result
if result.get("success"):
st.success("✅ 调用成功")
st.markdown("### 结果")
st.markdown(result.get("result", ""))
# 确定/取消/继续按钮
confirm_col1, confirm_col2, confirm_col3 = st.columns([1, 1, 1])
with confirm_col1:
if st.button("✅ 确定", key="news_confirm", use_container_width=True):
st.session_state.news_confirm = True
st.info("已确认结果")
with confirm_col2:
if st.button("❌ 取消", key="news_cancel", use_container_width=True):
st.session_state.news_result = None
st.rerun()
with confirm_col3:
if st.button("⏭️ 继续", key="news_continue", use_container_width=True):
st.session_state.news_confirm = True
st.info("已继续")
# 显示原始数据(可选)
with st.expander("🔍 原始数据", expanded=False):
st.json(result.get("raw_data", {}))
else:
st.error(f"❌ 调用失败: {result.get('error')}")
def _render_contact_panel():
"""渲染通讯录子图测试面板"""
# 会话状态管理
if "contact_action" not in st.session_state:
st.session_state.contact_action = "auto"
if "contact_query" not in st.session_state:
st.session_state.contact_query = ""
if "contact_result" not in st.session_state:
st.session_state.contact_result = None
if "contact_confirm" not in st.session_state:
st.session_state.contact_confirm = False
# 选择 Action
action_col1, action_col2 = st.columns([1, 2])
with action_col1:
action = st.selectbox(
"操作",
options=["auto", "list", "add", "emails", "draft", "sniff"],
index=["auto", "list", "add", "emails", "draft", "sniff"].index(st.session_state.contact_action),
key="contact_action_selector"
)
with action_col2:
query = st.text_input("查询内容", value=st.session_state.contact_query, key="contact_query_input")
# 按钮行
btn_col1, btn_col2, btn_col3 = st.columns([1, 1, 1])
with btn_col1:
if st.button("▶️ 运行", key="contact_run", use_container_width=True):
st.session_state.contact_action = action
st.session_state.contact_query = query
with st.spinner("调用子图中..."):
result = api_client.call_contact_subgraph(action, query)
st.session_state.contact_result = result
st.session_state.contact_confirm = False
st.rerun()
# 显示结果
if st.session_state.contact_result:
result = st.session_state.contact_result
if result.get("success"):
st.success("✅ 调用成功")
st.markdown("### 结果")
st.markdown(result.get("result", ""))
# 确定/取消/继续按钮
confirm_col1, confirm_col2, confirm_col3 = st.columns([1, 1, 1])
with confirm_col1:
if st.button("✅ 确定", key="contact_confirm", use_container_width=True):
st.session_state.contact_confirm = True
st.info("已确认结果")
with confirm_col2:
if st.button("❌ 取消", key="contact_cancel", use_container_width=True):
st.session_state.contact_result = None
st.rerun()
with confirm_col3:
if st.button("⏭️ 继续", key="contact_continue", use_container_width=True):
st.session_state.contact_confirm = True
st.info("已继续")
# 显示原始数据(可选)
with st.expander("🔍 原始数据", expanded=False):
st.json(result.get("raw_data", {}))
else:
st.error(f"❌ 调用失败: {result.get('error')}")