223 lines
8.9 KiB
Python
223 lines
8.9 KiB
Python
"""
|
|
子图测试面板组件
|
|
包含词典、资讯、通讯录三个子图的测试界面
|
|
使用确定取消继续交互
|
|
"""
|
|
|
|
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')}")
|