Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

Fix json parsing with new memories (#3456)

Parshva Daftarid38e3f196267
diff --git a/mem0/llms/ollama.py b/mem0/llms/ollama.py
index 9c5b0f36f..f91a26f40 100644
--- a/mem0/llms/ollama.py
+++ b/mem0/llms/ollama.py
@@ -91,9 +91,9 @@ class OllamaLLM(LLMBase):
"messages": messages,
}
- # Handle JSON response format by modifying the system prompt
+ # Handle JSON response format by using Ollama's native format parameter
if response_format and response_format.get("type") == "json_object":
- # Add JSON format instruction to the last message or create a system message
+ params["format"] = "json"
if messages and messages[-1]["role"] == "user":
messages[-1]["content"] += "\n\nPlease respond with valid JSON only."
else: