From 4e0f2c5e7497032ad80f8529de36beb98247186c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=92=B0?= Date: Wed, 8 Jul 2026 17:36:39 +0800 Subject: [PATCH] =?UTF-8?q?improve:=20=E5=A2=9E=E5=BC=BA=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=EF=BC=8C=E6=8D=95=E8=8E=B7TradingAgents?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 捕获stdout输出同步到前端日志 - 添加等待提示(3-8分钟) - 过滤有意义的进度信息 --- web_app.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/web_app.py b/web_app.py index c1aa252..41ef87d 100644 --- a/web_app.py +++ b/web_app.py @@ -518,6 +518,9 @@ def task_status(task_id): def run_analysis(task_id, ticker, date): """后台运行TradingAgents分析。""" + import sys + import io + try: task = tasks[task_id] @@ -534,7 +537,7 @@ def run_analysis(task_id, ticker, date): log(f'📊 开始分析 {ticker} ({date})') log(f'🤖 模型: MiMo-v2.5-pro') - log(f'🌐 数据源: SSH中转代理') + log(f'🌐 数据源: Alpha Vantage + SSH中转代理') from tradingagents.graph.trading_graph import TradingAgentsGraph from tradingagents.default_config import DEFAULT_CONFIG @@ -558,11 +561,40 @@ def run_analysis(task_id, ticker, date): } log('🔧 配置完成,启动分析引擎...') + log('⏳ 分析通常需要3-8分钟,请耐心等待...') - ta = TradingAgentsGraph(debug=True, config=config) + # 捕获stdout输出以获取实时进度 + class LogCapture: + def __init__(self, task): + self.task = task + self.buffer = '' + def write(self, text): + self.buffer += text + if '\n' in self.buffer: + lines = self.buffer.split('\n') + self.buffer = lines[-1] + for line in lines[:-1]: + line = line.strip() + if line and len(line) > 5: + # 只保留有意义的输出 + if any(k in line for k in ['Tool', 'Message', 'Agent', 'failed', 'error', '✅', '❌', '📊', '📈', '💭', '📰', '🔬', '⚠️']): + self.task['logs'].append(f'📋 {line[:100]}') + if len(self.task['logs']) > 50: + self.task['logs'] = self.task['logs'][-50:] + def flush(self): + pass - log('📈 技术分析中...') - state, decision = ta.propagate(ticker, date) + # 临时捕获输出 + old_stdout = sys.stdout + sys.stdout = LogCapture(task) + + try: + ta = TradingAgentsGraph(debug=True, config=config) + + log('📈 技术分析师开始工作...') + state, decision = ta.propagate(ticker, date) + finally: + sys.stdout = old_stdout log(f'✅ 分析完成: {decision}')