Skip to content

The agent engineering platform.

partners: (langchain-deepseek) fix deepseek-r1 always returns an empty `reasoning_content` when reasoning (#31065)

唐小鸭50fa524a6dba
diff --git a/libs/partners/deepseek/langchain_deepseek/chat_models.py b/libs/partners/deepseek/langchain_deepseek/chat_models.py
index 9166e61cfa..155b192c19 100644
--- a/libs/partners/deepseek/langchain_deepseek/chat_models.py
+++ b/libs/partners/deepseek/langchain_deepseek/chat_models.py
@@ -255,12 +255,14 @@ class ChatDeepSeek(BaseChatOpenAI):
if (choices := chunk.get("choices")) and generation_chunk:
top = choices[0]
if isinstance(generation_chunk.message, AIMessageChunk):
- if reasoning_content := top.get("delta", {}).get("reasoning_content"):
+ if (
+ reasoning_content := top.get("delta", {}).get("reasoning_content")
+ ) is not None:
generation_chunk.message.additional_kwargs["reasoning_content"] = (
reasoning_content
)
# Handle use via OpenRouter
- elif reasoning := top.get("delta", {}).get("reasoning"):
+ elif (reasoning := top.get("delta", {}).get("reasoning")) is not None:
generation_chunk.message.additional_kwargs["reasoning_content"] = (
reasoning
)