戒酒的李白

The single-multi-agent framework has been initially completed.

@@ -168,7 +168,8 @@ def start_streamlit_app(app_name, script_path, port): @@ -168,7 +168,8 @@ def start_streamlit_app(app_name, script_path, port):
168 '--server.port', str(port), 168 '--server.port', str(port),
169 '--server.headless', 'true', 169 '--server.headless', 'true',
170 '--browser.gatherUsageStats', 'false', 170 '--browser.gatherUsageStats', 'false',
171 - '--logger.level', 'debug', # 增加日志详细程度 171 + # '--logger.level', 'debug', # 增加日志详细程度
  172 + '--logger.level', 'info',
172 '--server.enableCORS', 'false' 173 '--server.enableCORS', 'false'
173 ] 174 ]
174 175
1 -"""  
2 -Streamlit Web界面  
3 -为DInsight Agent提供友好的Web界面  
4 -"""  
5 -  
6 -import os  
7 -import sys  
8 -import streamlit as st  
9 -from datetime import datetime  
10 -import json  
11 -  
12 -# 添加src目录到Python路径  
13 -sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))  
14 -  
15 -from InsightEngine import DeepSearchAgent, Config  
16 -from config import DEEPSEEK_API_KEY, KIMI_API_KEY, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DB_PORT, DB_CHARSET  
17 -  
18 -  
19 -def main():  
20 - """主函数"""  
21 - st.set_page_config(  
22 - page_title="Insight Agent",  
23 - page_icon="",  
24 - layout="wide"  
25 - )  
26 -  
27 - st.title("Insight Engine")  
28 - st.markdown("本地舆情数据库深度分析AI代理")  
29 -  
30 - # ----- 配置被硬编码 -----  
31 - # 强制使用 Kimi  
32 - llm_provider = "kimi"  
33 - model_name = "kimi-k2-0711-preview"  
34 - # 默认高级配置  
35 - max_reflections = 2  
36 - max_content_length = 500000 # Kimi支持长文本  
37 -  
38 - # 主界面  
39 - col1, col2 = st.columns([2, 1])  
40 -  
41 - with col1:  
42 - st.header("研究查询")  
43 - query = st.text_area(  
44 - "请输入您要研究的问题",  
45 - placeholder="例如:2025年人工智能发展趋势",  
46 - height=100  
47 - )  
48 -  
49 - with col2:  
50 - st.header("状态信息")  
51 - if 'agent' in st.session_state and hasattr(st.session_state.agent, 'state'):  
52 - progress = st.session_state.agent.get_progress_summary()  
53 - st.metric("总段落数", progress['total_paragraphs'])  
54 - st.metric("已完成", progress['completed_paragraphs'])  
55 - st.progress(progress['progress_percentage'] / 100)  
56 - else:  
57 - st.info("尚未开始研究")  
58 -  
59 - # 执行按钮  
60 - col1_btn, col2_btn, col3_btn = st.columns([1, 1, 1])  
61 - with col2_btn:  
62 - start_research = st.button("开始研究", type="primary", use_container_width=True)  
63 -  
64 - # 验证配置  
65 - if start_research:  
66 - if not query.strip():  
67 - st.error("请输入研究查询")  
68 - return  
69 -  
70 - # 由于强制使用Kimi,只检查KIMI_API_KEY  
71 - if not KIMI_API_KEY:  
72 - st.error("请在您的配置文件(config.py)中设置KIMI_API_KEY")  
73 - return  
74 -  
75 - # 自动使用配置文件中的API密钥和数据库配置  
76 - db_host = DB_HOST  
77 - db_user = DB_USER  
78 - db_password = DB_PASSWORD  
79 - db_name = DB_NAME  
80 - db_port = DB_PORT  
81 - db_charset = DB_CHARSET  
82 -  
83 - # 创建配置  
84 - config = Config(  
85 - deepseek_api_key=None,  
86 - openai_api_key=None,  
87 - kimi_api_key=KIMI_API_KEY, # 强制使用配置文件中的Kimi Key  
88 - db_host=db_host,  
89 - db_user=db_user,  
90 - db_password=db_password,  
91 - db_name=db_name,  
92 - db_port=db_port,  
93 - db_charset=db_charset,  
94 - default_llm_provider=llm_provider,  
95 - deepseek_model="deepseek-chat", # 保留默认值以兼容  
96 - openai_model="gpt-4o-mini", # 保留默认值以兼容  
97 - kimi_model=model_name,  
98 - max_reflections=max_reflections,  
99 - max_content_length=max_content_length,  
100 - output_dir="insight_engine_streamlit_reports"  
101 - )  
102 -  
103 - # 执行研究  
104 - execute_research(query, config)  
105 -  
106 -  
107 -def execute_research(query: str, config: Config):  
108 - """执行研究"""  
109 - try:  
110 - # 创建进度条  
111 - progress_bar = st.progress(0)  
112 - status_text = st.empty()  
113 -  
114 - # 初始化Agent  
115 - status_text.text("正在初始化Agent...")  
116 - agent = DeepSearchAgent(config)  
117 - st.session_state.agent = agent  
118 -  
119 - progress_bar.progress(10)  
120 -  
121 - # 生成报告结构  
122 - status_text.text("正在生成报告结构...")  
123 - agent._generate_report_structure(query)  
124 - progress_bar.progress(20)  
125 -  
126 - # 处理段落  
127 - total_paragraphs = len(agent.state.paragraphs)  
128 - for i in range(total_paragraphs):  
129 - status_text.text(f"正在处理段落 {i + 1}/{total_paragraphs}: {agent.state.paragraphs[i].title}")  
130 -  
131 - # 初始搜索和总结  
132 - agent._initial_search_and_summary(i)  
133 - progress_value = 20 + (i + 0.5) / total_paragraphs * 60  
134 - progress_bar.progress(int(progress_value))  
135 -  
136 - # 反思循环  
137 - agent._reflection_loop(i)  
138 - agent.state.paragraphs[i].research.mark_completed()  
139 -  
140 - progress_value = 20 + (i + 1) / total_paragraphs * 60  
141 - progress_bar.progress(int(progress_value))  
142 -  
143 - # 生成最终报告  
144 - status_text.text("正在生成最终报告...")  
145 - final_report = agent._generate_final_report()  
146 - progress_bar.progress(90)  
147 -  
148 - # 保存报告  
149 - status_text.text("正在保存报告...")  
150 - agent._save_report(final_report)  
151 - progress_bar.progress(100)  
152 -  
153 - status_text.text("研究完成!")  
154 -  
155 - # 显示结果  
156 - display_results(agent, final_report)  
157 -  
158 - except Exception as e:  
159 - st.error(f"研究过程中发生错误: {str(e)}")  
160 -  
161 -  
162 -def display_results(agent: DeepSearchAgent, final_report: str):  
163 - """显示研究结果"""  
164 - st.header("研究结果")  
165 -  
166 - # 结果标签页(已移除下载选项)  
167 - tab1, tab2 = st.tabs(["最终报告", "详细信息"])  
168 -  
169 - with tab1:  
170 - st.markdown(final_report)  
171 -  
172 - with tab2:  
173 - # 段落详情  
174 - st.subheader("段落详情")  
175 - for i, paragraph in enumerate(agent.state.paragraphs):  
176 - with st.expander(f"段落 {i + 1}: {paragraph.title}"):  
177 - st.write("**预期内容:**", paragraph.content)  
178 - st.write("**最终内容:**", paragraph.research.latest_summary[:300] + "..."  
179 - if len(paragraph.research.latest_summary) > 300  
180 - else paragraph.research.latest_summary)  
181 - st.write("**搜索次数:**", paragraph.research.get_search_count())  
182 - st.write("**反思次数:**", paragraph.research.reflection_iteration)  
183 -  
184 - # 搜索历史  
185 - st.subheader("搜索历史")  
186 - all_searches = []  
187 - for paragraph in agent.state.paragraphs:  
188 - all_searches.extend(paragraph.research.search_history)  
189 -  
190 - if all_searches:  
191 - for i, search in enumerate(all_searches):  
192 - with st.expander(f"搜索 {i + 1}: {search.query}"):  
193 - st.write("**URL:**", search.url)  
194 - st.write("**标题:**", search.title)  
195 - st.write("**内容预览:**",  
196 - search.content[:200] + "..." if len(search.content) > 200 else search.content)  
197 - if search.score:  
198 - st.write("**相关度评分:**", search.score)  
199 -  
200 -  
201 -if __name__ == "__main__":  
202 - main()  
1 -"""  
2 -Streamlit Web界面  
3 -为DInsight Agent提供友好的Web界面  
4 -"""  
5 -  
6 -import os  
7 -import sys  
8 -import streamlit as st  
9 -from datetime import datetime  
10 -import json  
11 -  
12 -# 添加src目录到Python路径  
13 -sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))  
14 -  
15 -from InsightEngine import DeepSearchAgent, Config  
16 -from config import DEEPSEEK_API_KEY, KIMI_API_KEY, DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DB_PORT, DB_CHARSET  
17 -  
18 -  
19 -def main():  
20 - """主函数"""  
21 - st.set_page_config(  
22 - page_title="Insight Agent",  
23 - page_icon="",  
24 - layout="wide"  
25 - )  
26 -  
27 - st.title("Insight Engine")  
28 - st.markdown("本地舆情数据库深度分析AI代理")  
29 -  
30 - # ----- 配置被硬编码 -----  
31 - # 强制使用 Kimi  
32 - llm_provider = "kimi"  
33 - model_name = "kimi-k2-0711-preview"  
34 - # 默认高级配置  
35 - max_reflections = 2  
36 - max_content_length = 500000 # Kimi支持长文本  
37 -  
38 - # 主界面  
39 - col1, col2 = st.columns([2, 1])  
40 -  
41 - with col1:  
42 - st.header("研究查询")  
43 - query = st.text_area(  
44 - "请输入您要研究的问题",  
45 - placeholder="例如:2025年人工智能发展趋势",  
46 - height=100  
47 - )  
48 -  
49 - with col2:  
50 - st.header("状态信息")  
51 - if 'agent' in st.session_state and hasattr(st.session_state.agent, 'state'):  
52 - progress = st.session_state.agent.get_progress_summary()  
53 - st.metric("总段落数", progress['total_paragraphs'])  
54 - st.metric("已完成", progress['completed_paragraphs'])  
55 - st.progress(progress['progress_percentage'] / 100)  
56 - else:  
57 - st.info("尚未开始研究")  
58 -  
59 - # 执行按钮  
60 - col1_btn, col2_btn, col3_btn = st.columns([1, 1, 1])  
61 - with col2_btn:  
62 - start_research = st.button("开始研究", type="primary", use_container_width=True)  
63 -  
64 - # 验证配置  
65 - if start_research:  
66 - if not query.strip():  
67 - st.error("请输入研究查询")  
68 - return  
69 -  
70 - # 由于强制使用Kimi,只检查KIMI_API_KEY  
71 - if not KIMI_API_KEY:  
72 - st.error("请在您的配置文件(config.py)中设置KIMI_API_KEY")  
73 - return  
74 -  
75 - # 自动使用配置文件中的API密钥和数据库配置  
76 - db_host = DB_HOST  
77 - db_user = DB_USER  
78 - db_password = DB_PASSWORD  
79 - db_name = DB_NAME  
80 - db_port = DB_PORT  
81 - db_charset = DB_CHARSET  
82 -  
83 - # 创建配置  
84 - config = Config(  
85 - deepseek_api_key=None,  
86 - openai_api_key=None,  
87 - kimi_api_key=KIMI_API_KEY, # 强制使用配置文件中的Kimi Key  
88 - db_host=db_host,  
89 - db_user=db_user,  
90 - db_password=db_password,  
91 - db_name=db_name,  
92 - db_port=db_port,  
93 - db_charset=db_charset,  
94 - default_llm_provider=llm_provider,  
95 - deepseek_model="deepseek-chat", # 保留默认值以兼容  
96 - openai_model="gpt-4o-mini", # 保留默认值以兼容  
97 - kimi_model=model_name,  
98 - max_reflections=max_reflections,  
99 - max_content_length=max_content_length,  
100 - output_dir="insight_engine_streamlit_reports"  
101 - )  
102 -  
103 - # 执行研究  
104 - execute_research(query, config)  
105 -  
106 -  
107 -def execute_research(query: str, config: Config):  
108 - """执行研究"""  
109 - try:  
110 - # 创建进度条  
111 - progress_bar = st.progress(0)  
112 - status_text = st.empty()  
113 -  
114 - # 初始化Agent  
115 - status_text.text("正在初始化Agent...")  
116 - agent = DeepSearchAgent(config)  
117 - st.session_state.agent = agent  
118 -  
119 - progress_bar.progress(10)  
120 -  
121 - # 生成报告结构  
122 - status_text.text("正在生成报告结构...")  
123 - agent._generate_report_structure(query)  
124 - progress_bar.progress(20)  
125 -  
126 - # 处理段落  
127 - total_paragraphs = len(agent.state.paragraphs)  
128 - for i in range(total_paragraphs):  
129 - status_text.text(f"正在处理段落 {i + 1}/{total_paragraphs}: {agent.state.paragraphs[i].title}")  
130 -  
131 - # 初始搜索和总结  
132 - agent._initial_search_and_summary(i)  
133 - progress_value = 20 + (i + 0.5) / total_paragraphs * 60  
134 - progress_bar.progress(int(progress_value))  
135 -  
136 - # 反思循环  
137 - agent._reflection_loop(i)  
138 - agent.state.paragraphs[i].research.mark_completed()  
139 -  
140 - progress_value = 20 + (i + 1) / total_paragraphs * 60  
141 - progress_bar.progress(int(progress_value))  
142 -  
143 - # 生成最终报告  
144 - status_text.text("正在生成最终报告...")  
145 - final_report = agent._generate_final_report()  
146 - progress_bar.progress(90)  
147 -  
148 - # 保存报告  
149 - status_text.text("正在保存报告...")  
150 - agent._save_report(final_report)  
151 - progress_bar.progress(100)  
152 -  
153 - status_text.text("研究完成!")  
154 -  
155 - # 显示结果  
156 - display_results(agent, final_report)  
157 -  
158 - except Exception as e:  
159 - st.error(f"研究过程中发生错误: {str(e)}")  
160 -  
161 -  
162 -def display_results(agent: DeepSearchAgent, final_report: str):  
163 - """显示研究结果"""  
164 - st.header("研究结果")  
165 -  
166 - # 结果标签页(已移除下载选项)  
167 - tab1, tab2 = st.tabs(["最终报告", "详细信息"])  
168 -  
169 - with tab1:  
170 - st.markdown(final_report)  
171 -  
172 - with tab2:  
173 - # 段落详情  
174 - st.subheader("段落详情")  
175 - for i, paragraph in enumerate(agent.state.paragraphs):  
176 - with st.expander(f"段落 {i + 1}: {paragraph.title}"):  
177 - st.write("**预期内容:**", paragraph.content)  
178 - st.write("**最终内容:**", paragraph.research.latest_summary[:300] + "..."  
179 - if len(paragraph.research.latest_summary) > 300  
180 - else paragraph.research.latest_summary)  
181 - st.write("**搜索次数:**", paragraph.research.get_search_count())  
182 - st.write("**反思次数:**", paragraph.research.reflection_iteration)  
183 -  
184 - # 搜索历史  
185 - st.subheader("搜索历史")  
186 - all_searches = []  
187 - for paragraph in agent.state.paragraphs:  
188 - all_searches.extend(paragraph.research.search_history)  
189 -  
190 - if all_searches:  
191 - for i, search in enumerate(all_searches):  
192 - with st.expander(f"搜索 {i + 1}: {search.query}"):  
193 - st.write("**URL:**", search.url)  
194 - st.write("**标题:**", search.title)  
195 - st.write("**内容预览:**",  
196 - search.content[:200] + "..." if len(search.content) > 200 else search.content)  
197 - if search.score:  
198 - st.write("**相关度评分:**", search.score)  
199 -  
200 -  
201 -if __name__ == "__main__":  
202 - main()  
@@ -22,10 +22,11 @@ @@ -22,10 +22,11 @@
22 22
23 .container { 23 .container {
24 max-width: 100vw; 24 max-width: 100vw;
25 - min-height: 100vh; 25 + height: 100vh; /* 固定高度为视口高度 */
26 display: flex; 26 display: flex;
27 flex-direction: column; 27 flex-direction: column;
28 border: 2px solid #000000; 28 border: 2px solid #000000;
  29 + overflow: hidden; /* 防止整体滚动 */
29 } 30 }
30 31
31 /* 搜索框区域 */ 32 /* 搜索框区域 */
@@ -117,6 +118,7 @@ @@ -117,6 +118,7 @@
117 flex-direction: column; 118 flex-direction: column;
118 background-color: #ffffff; 119 background-color: #ffffff;
119 min-height: 0; /* 允许子元素缩小 */ 120 min-height: 0; /* 允许子元素缩小 */
  121 + overflow: hidden; /* 防止内容溢出 */
120 } 122 }
121 123
122 /* 应用切换按钮 */ 124 /* 应用切换按钮 */
@@ -178,10 +180,10 @@ @@ -178,10 +180,10 @@
178 font-family: 'Courier New', monospace; 180 font-family: 'Courier New', monospace;
179 font-size: 12px; 181 font-size: 12px;
180 overflow-y: auto; 182 overflow-y: auto;
  183 + overflow-x: hidden;
181 white-space: pre-wrap; 184 white-space: pre-wrap;
182 word-break: break-all; 185 word-break: break-all;
183 min-height: 0; /* 允许内容缩小 */ 186 min-height: 0; /* 允许内容缩小 */
184 - max-height: 100%; /* 限制最大高度 */  
185 } 187 }
186 188
187 .console-line { 189 .console-line {