mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-11 16:01:33 +00:00
fix(ollama): Fix handling message content lists (#32881)
The Ollama chat model adapter does not support all of the possible message content formats. That leads to Ollama model adapter crashing on some messages from different models (e.g. Gemini 2.5 Flash). These changes should fix one known scenario - when `content` is a list containing a string.
This commit is contained in:
committed by
GitHub
parent
b274416441
commit
181bb91ce0
@@ -661,8 +661,10 @@ class ChatOllama(BaseChatModel):
|
||||
if isinstance(message.content, str):
|
||||
content = message.content
|
||||
else:
|
||||
for content_part in cast(list[dict], message.content):
|
||||
if content_part.get("type") == "text":
|
||||
for content_part in message.content:
|
||||
if isinstance(content_part, str):
|
||||
content += f"\n{content_part}"
|
||||
elif content_part.get("type") == "text":
|
||||
content += f"\n{content_part['text']}"
|
||||
elif content_part.get("type") == "tool_use":
|
||||
continue
|
||||
|
Reference in New Issue
Block a user