From 1d590e7b9f3d3987465fff46309c312d9b1ff31f Mon Sep 17 00:00:00 2001 From: Sinyo <38577585+SinyoWong@users.noreply.github.com> Date: Tue, 18 Feb 2025 10:08:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=B3=E8=BF=87=20DeepSeek-R1=20=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E6=B7=B1=E5=BA=A6=E6=80=9D=E8=80=83=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/providers/llm/openai/openai.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/providers/llm/openai/openai.py b/core/providers/llm/openai/openai.py index e574d50de..6090c0c21 100644 --- a/core/providers/llm/openai/openai.py +++ b/core/providers/llm/openai/openai.py @@ -25,12 +25,17 @@ class LLMProvider(LLMProviderBase): messages=dialogue, stream=True ) + is_active = True for chunk in responses: # 检查是否存在有效的choice且content不为空 - if chunk.choices and len(chunk.choices) > 0: - delta = chunk.choices[0].delta - content = getattr(delta, 'content', '') - if content: # 仅在content非空时生成 + delta = chunk.choices[0].delta if chunk.choices else None + content = getattr(delta, 'content', '') if delta else '' + if content: # 仅在content非空时生成 + if '' in content: # 跳过深度思考内容 + is_active = False + elif '' in content: + is_active = True + elif is_active: yield content except Exception as e: logger.bind(tag=TAG).error(f"Error in response generation: {e}")