From a60512cdae97f21eb25603cd6b04fac699ad2b52 Mon Sep 17 00:00:00 2001 From: Kristian Jackson Date: Fri, 12 May 2023 15:18:15 -0400 Subject: [PATCH] Catch JSON error in summary_memory.py (#3996) Co-authored-by: k-boikov <64261260+k-boikov@users.noreply.github.com> --- autogpt/memory_management/summary_memory.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/autogpt/memory_management/summary_memory.py b/autogpt/memory_management/summary_memory.py index 4e818acf116a..a13b63f3af53 100644 --- a/autogpt/memory_management/summary_memory.py +++ b/autogpt/memory_management/summary_memory.py @@ -6,6 +6,7 @@ from autogpt.config import Config from autogpt.llm.llm_utils import create_chat_completion from autogpt.log_cycle.log_cycle import PROMPT_SUMMARY_FILE_NAME, SUMMARY_FILE_NAME +from autogpt.logs import logger cfg = Config() @@ -75,10 +76,14 @@ def update_running_summary( event["role"] = "you" # Remove "thoughts" dictionary from "content" - content_dict = json.loads(event["content"]) - if "thoughts" in content_dict: - del content_dict["thoughts"] - event["content"] = json.dumps(content_dict) + try: + content_dict = json.loads(event["content"]) + if "thoughts" in content_dict: + del content_dict["thoughts"] + event["content"] = json.dumps(content_dict) + except json.decoder.JSONDecodeError: + if cfg.debug_mode: + logger.error(f"Error: Invalid JSON: {event['content']}\n") elif event["role"].lower() == "system": event["role"] = "your computer"