mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-02-11 17:24:20 +01:00
lint: Address linting issues from #5458
- Fixed linting issues in `json_utils/utilities.py` and `test_json_utils.py`
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user