diff --git a/autogpt/json_utils/utilities.py b/autogpt/json_utils/utilities.py index 01848871..e492d302 100644 --- a/autogpt/json_utils/utilities.py +++ b/autogpt/json_utils/utilities.py @@ -67,29 +67,3 @@ def validate_json( logger.debug("The JSON object is valid.") return True - - -def validate_json_string(json_string: str, schema_name: str) -> dict | None: - """ - :type schema_name: object - :param schema_name: str - :type json_object: object - """ - - try: - json_loaded = json.loads(json_string) - if not validate_json(json_loaded, schema_name): - return None - return json_loaded - except: - return None - - -def is_string_valid_json(json_string: str, schema_name: str) -> bool: - """ - :type schema_name: object - :param schema_name: str - :type json_object: object - """ - - return validate_json_string(json_string, schema_name) is not None diff --git a/autogpt/memory/message_history.py b/autogpt/memory/message_history.py index be524125..897cee15 100644 --- a/autogpt/memory/message_history.py +++ b/autogpt/memory/message_history.py @@ -9,11 +9,7 @@ if TYPE_CHECKING: from autogpt.agent import Agent from autogpt.config import Config -from autogpt.json_utils.utilities import ( - LLM_DEFAULT_RESPONSE_FORMAT, - extract_json_from_response, - is_string_valid_json, -) +from autogpt.json_utils.utilities import extract_json_from_response from autogpt.llm.base import ChatSequence, Message, MessageRole, MessageType from autogpt.llm.providers.openai import OPEN_AI_CHAT_MODELS from autogpt.llm.utils import count_string_tokens, create_chat_completion @@ -105,8 +101,8 @@ class MessageHistory: ) result_message = messages[i + 1] try: - assert is_string_valid_json( - ai_message.content, LLM_DEFAULT_RESPONSE_FORMAT + assert ( + extract_json_from_response(ai_message.content) != {} ), "AI response is not a valid JSON object" assert result_message.type == "action_result"