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.

lint: Address linting issues from #5458

Reinier van der Leerca6e9e5e3476
diff --git a/autogpts/autogpt/autogpt/json_utils/utilities.py b/autogpts/autogpt/autogpt/json_utils/utilities.py
index 028eb67cc4..6f9683972f 100644
--- a/autogpts/autogpt/autogpt/json_utils/utilities.py
+++ b/autogpts/autogpt/autogpt/json_utils/utilities.py
@@ -1,7 +1,7 @@
"""Utilities for the json_fixes package."""
-import re
import ast
import logging
+import re
from typing import Any
logger = logging.getLogger(__name__)
@@ -9,7 +9,7 @@ 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"```([\s\S]*?)```"
match = re.search(pattern, response_content)
if match:
@@ -18,7 +18,7 @@ def extract_dict_from_response(response_content: str) -> dict[str, Any]:
response_content = response_content.lstrip("json")
else:
# The string may contain JSON.
- json_pattern = r'{.*}'
+ json_pattern = r"{.*}"
match = re.search(json_pattern, response_content)
if match:
diff --git a/autogpts/autogpt/tests/unit/test_utils.py b/autogpts/autogpt/tests/unit/test_utils.py
index f56e2b9735..9a783ce4d3 100644
--- a/autogpts/autogpt/tests/unit/test_utils.py
+++ b/autogpts/autogpt/tests/unit/test_utils.py
@@ -194,14 +194,18 @@ def test_extract_json_from_response_wrapped_in_code_block(valid_json_response: d
extract_dict_from_response(emulated_response_from_openai) == valid_json_response
)
-def test_extract_json_from_response_wrapped_in_code_block_with_language(valid_json_response: dict):
+
+def test_extract_json_from_response_wrapped_in_code_block_with_language(
+ valid_json_response: dict,
+):
emulated_response_from_openai = "```json" + str(valid_json_response) + "```"
assert (
extract_dict_from_response(emulated_response_from_openai) == valid_json_response
)
+
def test_extract_json_from_response_json_contained_in_string(valid_json_response: dict):
emulated_response_from_openai = "sentence1" + str(valid_json_response) + "sentence2"
assert (
extract_dict_from_response(emulated_response_from_openai) == valid_json_response
- )
\ No newline at end of file
+ )