From 0cb9571db7a0a92b0c8d252c6fc37096ee962af6 Mon Sep 17 00:00:00 2001 From: root <953994191@qq.com> Date: Mon, 27 Apr 2026 15:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=89=8D=E7=AB=AF=E5=AD=90?= =?UTF-8?q?=E5=9B=BE=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 sidebar.py 中的子图测试面板 - 删除 subgraph_panel.py 文件 - 删除 api_client.py 中的子图 API 调用代码 --- frontend/src/api_client.py | 83 +------- frontend/src/components/sidebar.py | 11 -- frontend/src/components/subgraph_panel.py | 222 ---------------------- 3 files changed, 8 insertions(+), 308 deletions(-) delete mode 100644 frontend/src/components/subgraph_panel.py diff --git a/frontend/src/api_client.py b/frontend/src/api_client.py index 308996f..c8d4697 100644 --- a/frontend/src/api_client.py +++ b/frontend/src/api_client.py @@ -24,8 +24,7 @@ class APIClient: """ 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]]: """ 获取用户的历史对话列表 @@ -113,8 +112,7 @@ class APIClient: error(f"获取线程摘要异常: {e}") return {"summary": "加载失败", "message_count": 0} - # ==================== 聊天接口 ==================== - + # ==================== 聊天接口 ====================\n def chat_stream( self, message: str, @@ -133,11 +131,11 @@ class APIClient: Yields: SSE 事件字典,类型包括: - - token: 逐字输出 {type: "token", content: "..."} - - tool_start: 工具调用开始 {type: "tool_start", tool: "..."} - - tool_end: 工具调用完成 {type: "tool_end", tool: "..."} - - done: 对话完成 {type: "done", token_usage: {...}, elapsed_time: ...} - - error: 错误信息 {type: "error", message: "..."} + - token: 逐字输出 {type: \"token\", content: \"...\"} + - tool_start: 工具调用开始 {type: \"tool_start\", tool: \"...\"} + - tool_end: 工具调用完成 {type: \"tool_end\", tool: \"...\"} + - done: 对话完成 {type: \"done\", token_usage: {...}, elapsed_time: ...} + - error: 错误信息 {type: \"error\", message: \"...\"} """ payload = { "message": message, @@ -186,8 +184,7 @@ class APIClient: "message": f"请求失败: {str(e)}" } - # ==================== 审核接口 ==================== - + # ==================== 审核接口 ====================\n def get_pending_reviews(self, limit: int = 100) -> List[Dict[str, Any]]: """ 获取待审核列表 @@ -379,70 +376,6 @@ class APIClient: error(f"请求审核异常: {e}") 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_client = APIClient() diff --git a/frontend/src/components/sidebar.py b/frontend/src/components/sidebar.py index 7c570f0..14ca9cd 100644 --- a/frontend/src/components/sidebar.py +++ b/frontend/src/components/sidebar.py @@ -21,17 +21,6 @@ def render_sidebar(): # 底部放用户部分 st.divider() _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(): """渲染用户登录区域""" diff --git a/frontend/src/components/subgraph_panel.py b/frontend/src/components/subgraph_panel.py deleted file mode 100644 index 80e5166..0000000 --- a/frontend/src/components/subgraph_panel.py +++ /dev/null @@ -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')}")