Skip to content

Commit 0f8c20a

Browse files
committed
Avoid side effects if chat message contains images
1 parent cb81f52 commit 0f8c20a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ollama/_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import urllib.parse
88
from os import PathLike
99
from pathlib import Path
10+
from copy import deepcopy
1011
from hashlib import sha256
1112
from base64 import b64encode, b64decode
1213

@@ -164,6 +165,8 @@ def chat(
164165
if not model:
165166
raise RequestError('must provide a model')
166167

168+
messages = deepcopy(messages)
169+
167170
for message in messages or []:
168171
if not isinstance(message, dict):
169172
raise TypeError('messages must be a list of Message or dict-like objects')
@@ -446,6 +449,8 @@ async def chat(
446449
if not model:
447450
raise RequestError('must provide a model')
448451

452+
messages = deepcopy(messages)
453+
449454
for message in messages or []:
450455
if not isinstance(message, dict):
451456
raise TypeError('messages must be a list of strings')

0 commit comments

Comments
 (0)