fix(ollama): json format mutates caller's messages list in-place (#5539)
This commit is contained in:
+2
-1
@@ -119,11 +119,12 @@ class OllamaLLM(LLMBase):
|
||||
# Handle JSON response format by using Ollama's native format parameter
|
||||
if response_format and response_format.get("type") == "json_object":
|
||||
params["format"] = "json"
|
||||
# Also add JSON format instruction to the last message as a fallback
|
||||
messages = [dict(m) for m in messages]
|
||||
if messages and messages[-1]["role"] == "user":
|
||||
messages[-1]["content"] += "\n\nPlease respond with valid JSON only."
|
||||
else:
|
||||
messages.append({"role": "user", "content": "Please respond with valid JSON only."})
|
||||
params["messages"] = messages
|
||||
|
||||
# Add options for Ollama (temperature, num_predict, top_p)
|
||||
options = {
|
||||
|
||||
Reference in New Issue
Block a user