Skip to content

The agent engineering platform.

ollama[patch]: add model_name to response metadata (#30706)

ccurmee3f15f0a4742
diff --git a/libs/partners/ollama/langchain_ollama/chat_models.py b/libs/partners/ollama/langchain_ollama/chat_models.py
index f9c6ca060d..3801fc4d0d 100644
--- a/libs/partners/ollama/langchain_ollama/chat_models.py
+++ b/libs/partners/ollama/langchain_ollama/chat_models.py
@@ -743,6 +743,10 @@ class ChatOllama(BaseChatModel):
dict(stream_resp) if stream_resp.get("done") is True else None
),
)
+ if chunk.generation_info and (
+ model := chunk.generation_info.get("model")
+ ):
+ chunk.generation_info["model_name"] = model # backwards compat
if self.extract_reasoning:
message, is_thinking = self._extract_reasoning(
chunk.message, is_thinking
@@ -791,6 +795,10 @@ class ChatOllama(BaseChatModel):
dict(stream_resp) if stream_resp.get("done") is True else None
),
)
+ if chunk.generation_info and (
+ model := chunk.generation_info.get("model")
+ ):
+ chunk.generation_info["model_name"] = model # backwards compat
if self.extract_reasoning:
message, is_thinking = self._extract_reasoning(
chunk.message, is_thinking