Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(agent/json_utils): Decode as JSON rather than Python objects

Reinier van der Leer956cdc77fa8e
diff --git a/autogpts/autogpt/autogpt/json_utils/utilities.py b/autogpts/autogpt/autogpt/json_utils/utilities.py
index 0521372e02..2bc0eb2c87 100644
--- a/autogpts/autogpt/autogpt/json_utils/utilities.py
+++ b/autogpts/autogpt/autogpt/json_utils/utilities.py
@@ -1,5 +1,5 @@
"""Utilities for the json_fixes package."""
-import ast
+import json
import logging
import re
from typing import Any
@@ -22,9 +22,7 @@ def extract_dict_from_response(response_content: str) -> dict[str, Any]:
if match:
response_content = match.group()
- # Response content comes from OpenAI as a Python `str(content_dict)`.
- # `literal_eval` does the reverse of `str(dict)`.
- result = ast.literal_eval(response_content)
+ result = json.loads(response_content)
if not isinstance(result, dict):
raise ValueError(
f"Response '''{response_content}''' evaluated to "