Catch json error for new_memories_with_action (#2324)

This commit is contained in:
Dev Khant
2025-03-07 13:12:00 +05:30
committed by GitHub
parent c6fbba6a4d
commit 07d2f11081

View File

@@ -194,13 +194,21 @@ class Memory(MemoryBase):
function_calling_prompt = get_update_memory_messages(retrieved_old_memory, new_retrieved_facts) function_calling_prompt = get_update_memory_messages(retrieved_old_memory, new_retrieved_facts)
new_memories_with_actions = self.llm.generate_response( try:
messages=[{"role": "user", "content": function_calling_prompt}], new_memories_with_actions = self.llm.generate_response(
response_format={"type": "json_object"}, messages=[{"role": "user", "content": function_calling_prompt}],
) response_format={"type": "json_object"},
)
except Exception as e:
logging.error(f"Error in new_memories_with_actions: {e}")
new_memories_with_actions = []
new_memories_with_actions = remove_code_blocks(new_memories_with_actions) try:
new_memories_with_actions = json.loads(new_memories_with_actions) new_memories_with_actions = remove_code_blocks(new_memories_with_actions)
new_memories_with_actions = json.loads(new_memories_with_actions)
except Exception as e:
logging.error(f"Invalid JSON response: {e}")
new_memories_with_actions = []
returned_memories = [] returned_memories = []
try: try: