diff --git a/mem0/llms/ollama.py b/mem0/llms/ollama.py index 74d59c0d1..af976dc24 100644 --- a/mem0/llms/ollama.py +++ b/mem0/llms/ollama.py @@ -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 = {