From a3c0a57c96a4794691242b7688fbcb55512abac2 Mon Sep 17 00:00:00 2001 From: yhw17 Date: Wed, 5 Mar 2025 23:30:54 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E4=BF=AE=E5=A4=8D=E6=B5=81=E5=BC=8F?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E7=B4=A2=E5=BC=95=E8=B6=8A=E7=95=8C=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stock_analyzer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stock_analyzer.py b/stock_analyzer.py index 1d92aaa..9e11788 100644 --- a/stock_analyzer.py +++ b/stock_analyzer.py @@ -502,7 +502,8 @@ class StockAnalyzer: try: json_data = json.loads(data_content) - if 'choices' in json_data: + # 检查 choices 列表是否为空 + if 'choices' in json_data and json_data['choices']: delta = json_data['choices'][0].get('delta', {}) content = delta.get('content', '') @@ -516,6 +517,8 @@ class StockAnalyzer: "ai_analysis_chunk": content }) yield chunk_json + else: + logger.warning(f"收到空的 choices 列表: {data_content}") except json.JSONDecodeError as e: logger.error(f"[JSON解析错误] {str(e)}, 行内容: {data_content}") # 忽略无法解析的JSON