diff options
author | Reinier van der Leer <pwuts@agpt.co> | 2024-01-29 15:03:09 +0100 |
---|---|---|
committer | Reinier van der Leer <pwuts@agpt.co> | 2024-01-29 15:03:09 +0100 |
commit | 25b9e290a5f87aea419637ec7c2b0b595484c25c (patch) | |
tree | a5ed1cc1e55548bafe3181af5029d91d28df4abe | |
parent | feat(agent/llm): Add support for `gpt-4-0125-preview` (diff) | |
download | Auto-GPT-25b9e290a5f87aea419637ec7c2b0b595484c25c.tar.gz Auto-GPT-25b9e290a5f87aea419637ec7c2b0b595484c25c.tar.bz2 Auto-GPT-25b9e290a5f87aea419637ec7c2b0b595484c25c.zip |
fix(agent/json_utils): Make `extract_dict_from_response` more robust
* Accommodate for both ```json and ```JSON blocks in responses
-rw-r--r-- | autogpts/autogpt/autogpt/json_utils/utilities.py | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/autogpts/autogpt/autogpt/json_utils/utilities.py b/autogpts/autogpt/autogpt/json_utils/utilities.py index e5445dcb8..0521372e0 100644 --- a/autogpts/autogpt/autogpt/json_utils/utilities.py +++ b/autogpts/autogpt/autogpt/json_utils/utilities.py @@ -9,13 +9,11 @@ logger = logging.getLogger(__name__) def extract_dict_from_response(response_content: str) -> dict[str, Any]: # Sometimes the response includes the JSON in a code block with ``` - pattern = r"```([\s\S]*?)```" + pattern = r"```(?:json|JSON)*([\s\S]*?)```" match = re.search(pattern, response_content) if match: response_content = match.group(1).strip() - # Remove language names in code blocks - response_content = response_content.lstrip("json") else: # The string may contain JSON. json_pattern = r"{[\s\S]*}" |