From 611f0691a0f9c8a2f3d4cec27ab54908856e42e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=92=E9=85=92=E7=9A=84=E6=9D=8E=E7=99=BD?= <670939375@qq.com> Date: Sun, 24 Aug 2025 14:26:16 +0800 Subject: [PATCH] At the same time, activate the search function to achieve. --- .../insight_engine_streamlit_app.py | 53 ++++++++----------- SingleEngineApp/media_engine_streamlit_app.py | 53 ++++++++----------- SingleEngineApp/query_engine_streamlit_app.py | 53 ++++++++----------- templates/index.html | 24 +++------ 4 files changed, 72 insertions(+), 111 deletions(-) diff --git a/SingleEngineApp/insight_engine_streamlit_app.py b/SingleEngineApp/insight_engine_streamlit_app.py index b5a01f3..b0b9cf9 100644 --- a/SingleEngineApp/insight_engine_streamlit_app.py +++ b/SingleEngineApp/insight_engine_streamlit_app.py @@ -47,42 +47,33 @@ def main(): max_reflections = 2 max_content_length = 500000 # Kimi支持长文本 - # 主界面 - col1, col2 = st.columns([2, 1]) - - with col1: - st.header("研究查询") - - # 如果有自动查询,使用它作为默认值 - default_query = auto_query if auto_query else "" - - query = st.text_area( - "请输入您要研究的问题", - value=default_query, - placeholder="例如:2025年人工智能发展趋势", - height=100 - ) - - with col2: - st.header("状态信息") - if 'agent' in st.session_state and hasattr(st.session_state.agent, 'state'): - progress = st.session_state.agent.get_progress_summary() - st.metric("总段落数", progress['total_paragraphs']) - st.metric("已完成", progress['completed_paragraphs']) - st.progress(progress['progress_percentage'] / 100) - else: - st.info("尚未开始研究") - - # 执行按钮 - col1_btn, col2_btn, col3_btn = st.columns([1, 1, 1]) - with col2_btn: - start_research = st.button("开始研究", type="primary", use_container_width=True) + # 简化的研究查询展示区域 + st.header("研究查询") + # 如果有自动查询,使用它作为默认值,否则显示占位符 + display_query = auto_query if auto_query else "等待从主页面接收搜索查询..." + + # 只读的查询展示区域 + st.text_area( + "当前查询", + value=display_query, + height=100, + disabled=True, + help="查询内容由主页面的搜索框控制" + ) + # 自动搜索逻辑 + start_research = False + query = auto_query + if auto_search and auto_query and 'auto_search_executed' not in st.session_state: st.session_state.auto_search_executed = True start_research = True - query = auto_query + st.success(f"🚀 接收到搜索请求:{auto_query}") + st.info("正在启动研究...") + elif auto_query and not auto_search: + st.info(f"📝 当前查询:{auto_query}") + st.warning("等待搜索启动信号...") # 验证配置 if start_research: diff --git a/SingleEngineApp/media_engine_streamlit_app.py b/SingleEngineApp/media_engine_streamlit_app.py index 75aa873..5a3f1fc 100644 --- a/SingleEngineApp/media_engine_streamlit_app.py +++ b/SingleEngineApp/media_engine_streamlit_app.py @@ -47,42 +47,33 @@ def main(): max_reflections = 2 max_content_length = 20000 - # 主界面 - col1, col2 = st.columns([2, 1]) - - with col1: - st.header("研究查询") - - # 如果有自动查询,使用它作为默认值 - default_query = auto_query if auto_query else "" - - query = st.text_area( - "请输入您要研究的问题", - value=default_query, - placeholder="例如:2025年人工智能发展趋势", - height=100 - ) - - with col2: - st.header("状态信息") - if 'agent' in st.session_state and hasattr(st.session_state.agent, 'state'): - progress = st.session_state.agent.get_progress_summary() - st.metric("总段落数", progress['total_paragraphs']) - st.metric("已完成", progress['completed_paragraphs']) - st.progress(progress['progress_percentage'] / 100) - else: - st.info("尚未开始研究") - - # 执行按钮 - col1_btn, col2_btn, col3_btn = st.columns([1, 1, 1]) - with col2_btn: - start_research = st.button("开始研究", type="primary", use_container_width=True) + # 简化的研究查询展示区域 + st.header("研究查询") + # 如果有自动查询,使用它作为默认值,否则显示占位符 + display_query = auto_query if auto_query else "等待从主页面接收搜索查询..." + + # 只读的查询展示区域 + st.text_area( + "当前查询", + value=display_query, + height=100, + disabled=True, + help="查询内容由主页面的搜索框控制" + ) + # 自动搜索逻辑 + start_research = False + query = auto_query + if auto_search and auto_query and 'auto_search_executed' not in st.session_state: st.session_state.auto_search_executed = True start_research = True - query = auto_query + st.success(f"🚀 接收到搜索请求:{auto_query}") + st.info("正在启动研究...") + elif auto_query and not auto_search: + st.info(f"📝 当前查询:{auto_query}") + st.warning("等待搜索启动信号...") # 验证配置 if start_research: diff --git a/SingleEngineApp/query_engine_streamlit_app.py b/SingleEngineApp/query_engine_streamlit_app.py index 10d8745..1593571 100644 --- a/SingleEngineApp/query_engine_streamlit_app.py +++ b/SingleEngineApp/query_engine_streamlit_app.py @@ -47,42 +47,33 @@ def main(): max_reflections = 2 max_content_length = 20000 - # 主界面 - col1, col2 = st.columns([2, 1]) - - with col1: - st.header("研究查询") - - # 如果有自动查询,使用它作为默认值 - default_query = auto_query if auto_query else "" - - query = st.text_area( - "请输入您要研究的问题", - value=default_query, - placeholder="例如:2025年人工智能发展趋势", - height=100 - ) - - with col2: - st.header("状态信息") - if 'agent' in st.session_state and hasattr(st.session_state.agent, 'state'): - progress = st.session_state.agent.get_progress_summary() - st.metric("总段落数", progress['total_paragraphs']) - st.metric("已完成", progress['completed_paragraphs']) - st.progress(progress['progress_percentage'] / 100) - else: - st.info("尚未开始研究") - - # 执行按钮 - col1_btn, col2_btn, col3_btn = st.columns([1, 1, 1]) - with col2_btn: - start_research = st.button("开始研究", type="primary", use_container_width=True) + # 简化的研究查询展示区域 + st.header("研究查询") + # 如果有自动查询,使用它作为默认值,否则显示占位符 + display_query = auto_query if auto_query else "等待从主页面接收搜索查询..." + + # 只读的查询展示区域 + st.text_area( + "当前查询", + value=display_query, + height=100, + disabled=True, + help="查询内容由主页面的搜索框控制" + ) + # 自动搜索逻辑 + start_research = False + query = auto_query + if auto_search and auto_query and 'auto_search_executed' not in st.session_state: st.session_state.auto_search_executed = True start_research = True - query = auto_query + st.success(f"🚀 接收到搜索请求:{auto_query}") + st.info("正在启动研究...") + elif auto_query and not auto_search: + st.info(f"📝 当前查询:{auto_query}") + st.warning("等待搜索启动信号...") # 验证配置 if start_research: diff --git a/templates/index.html b/templates/index.html index 5df72ef..be9ded0 100644 --- a/templates/index.html +++ b/templates/index.html @@ -400,32 +400,20 @@ preloadIframes(); } - // 向所有运行中的应用发送搜索请求(通过新窗口方式避免刷新现有iframe) + // 向所有运行中的应用发送搜索请求(通过刷新iframe传递参数) let totalRunning = 0; const ports = { insight: 8501, media: 8502, query: 8503 }; Object.keys(appStatus).forEach(app => { - if (appStatus[app] === 'running') { + if (appStatus[app] === 'running' && preloadedIframes[app]) { totalRunning++; - // 为每个应用创建一个临时的搜索iframe,避免干扰主iframe - const searchIframe = document.createElement('iframe'); - searchIframe.style.display = 'none'; - searchIframe.style.position = 'absolute'; - searchIframe.style.top = '-9999px'; - + // 构建搜索URL const searchUrl = `http://localhost:${ports[app]}?query=${encodeURIComponent(query)}&auto_search=true`; console.log(`向 ${app} 发送搜索请求: ${searchUrl}`); - searchIframe.src = searchUrl; - document.body.appendChild(searchIframe); - - // 几秒后移除临时iframe - setTimeout(() => { - if (searchIframe.parentNode) { - searchIframe.parentNode.removeChild(searchIframe); - } - }, 5000); + // 直接更新主iframe的src来传递搜索参数 + preloadedIframes[app].src = searchUrl; } }); @@ -436,7 +424,7 @@ } else { button.disabled = false; button.innerHTML = '搜索'; - showMessage(`已向 ${totalRunning} 个应用发送搜索请求`, 'success'); + showMessage(`搜索请求已发送到 ${totalRunning} 个应用,页面将刷新以开始研究`, 'success'); } }