From 79036908828f391e0def29596a6b65bc4ef28b56 Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Fri, 20 Mar 2026 00:28:33 +0800 Subject: [PATCH] fix(deep-analyzer): add disable_reasoning parameter to GLM API calls --- kb_workflow/deep_analyzer/__init__.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/kb_workflow/deep_analyzer/__init__.py b/kb_workflow/deep_analyzer/__init__.py index 0052df9..fab047e 100644 --- a/kb_workflow/deep_analyzer/__init__.py +++ b/kb_workflow/deep_analyzer/__init__.py @@ -93,19 +93,28 @@ class SimpleAIClient: base_url = base_url or "https://open.bigmodel.cn/api/coding/paas/v4" url = f"{base_url}/chat/completions" headers = {"Authorization": f"Bearer {api_key}"} - payload = {"model": model, "messages": [{"role": "user", "content": prompt}], "max_tokens": max_tokens} + # GLM-4.5/4.6/4.7/5 默认启用thinking mode,添加 disable_reasoning 参数获取正常响应 + payload = { + "model": model, + "messages": [{"role": "user", "content": prompt}], + "max_tokens": max_tokens, + "disable_reasoning": True # 禁用思考模式,获取直接响应 + } response = requests.post(url, headers=headers, json=payload, timeout=600) response.raise_for_status() data = response.json() message = data.get('choices', [{}])[0].get('message', {}) content = message.get('content', '') - reasoning = message.get('reasoning_content', '') - if not content and reasoning: - sentences = reasoning.strip().split('。') - useful = [s.strip() for s in sentences if s.strip() and len(s.strip()) > 10] - if useful: - return '。'.join(useful[-3:]) + '。' - return reasoning.strip()[:500] + + if not content: + # 如果仍然为空,检查是否有reasoning_content(用于调试) + reasoning = message.get('reasoning_content', '') + if reasoning: + print(f"[DEBUG] Zhipu API返回空的content,但有reasoning_content。") + print(f"[DEBUG] 这可能表示disable_reasoning参数未生效或模型不支持。") + print(f"[DEBUG] reasoning_content前200字符: {reasoning[:200]}") + raise ValueError(f"Zhipu API返回空内容。请检查API配置和模型参数。响应数据: {data}") + return content def _call_minimax(self, prompt: str, max_tokens: int, api_key: str, model: str, base_url: str) -> str: