Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch JSON error in summary_memory.py #3996

Merged
merged 4 commits into from
May 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions autogpt/memory_management/summary_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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"
Expand Down