From 2ad289b374f7830116bc29284ea73b3f66aa54bc Mon Sep 17 00:00:00 2001 From: iomgaa Date: Tue, 26 Aug 2025 23:37:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DAI=20API=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=A4=84=E7=90=86=E5=92=8Ctoken=E9=99=90=E5=88=B6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将max_tokens从100增加到1000,确保AI能生成完整的JSON响应 - 增加AI响应content为None的异常处理,避免NoneType错误 - 解决JSON解析失败导致任务类型全部返回none的问题 --- src/parse.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parse.py b/src/parse.py index a418715..9203132 100644 --- a/src/parse.py +++ b/src/parse.py @@ -222,7 +222,7 @@ class PDFParser: {"role": "system", "content": system_prompt}, {"role": "user", "content": user_prompt} ], - "max_tokens": 100, # 需要返回更复杂的JSON格式 + "max_tokens": 1000, # 增加token数量以确保完整JSON响应 "temperature": 0.1 # 降低随机性 } @@ -236,7 +236,13 @@ class PDFParser: if response.status_code == 200: result = response.json() - ai_response = result['choices'][0]['message']['content'].strip() + # 检查AI响应内容是否为None + content = result.get('choices', [{}])[0].get('message', {}).get('content') + if content is None: + logging.error(f"AI API返回的content为None,可能是服务器问题") + return {'is_medical': False, 'task_type': 'none', 'medical_confidence': 0.0, 'task_confidence': 0.0} + + ai_response = content.strip() try: # 解析JSON响应