mirror of
https://github.com/hwchase17/langchain.git
synced 2026-04-10 22:43:18 +00:00
fix(ollama): prevent _convert_messages_to_ollama_messages from mutating caller list (#36567)
Fixes #36564 The method modifies messages[idx] in-place when converting v1 format content. Add messages = list(messages) to create a shallow copy before any mutations. 1 line change in libs/partners/ollama/langchain_ollama/chat_models.py Co-authored-by: bahtya <bahtyar153@qq.com> Co-authored-by: Mason Daugherty <mason@langchain.dev>
This commit is contained in:
@@ -865,6 +865,7 @@ class ChatOllama(BaseChatModel):
|
||||
Returns:
|
||||
List of messages in Ollama format.
|
||||
"""
|
||||
messages = list(messages) # shallow copy to avoid mutating caller's list
|
||||
for idx, message in enumerate(messages):
|
||||
# Handle message content written in v1 format
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user