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.
refactor(agent/utils): Clean up `JSONSchema.validate_object` signature & docstring
Reinier van der Leercf033504c2a7
diff --git a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.pyindex 72916e1fa8..0234c59a5e 100644--- a/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py+++ b/autogpts/autogpt/autogpt/agents/prompt_strategies/one_shot.py@@ -392,10 +392,7 @@ class OneShotAgentPromptStrategy(PromptStrategy):f"{json.dumps(assistant_reply_dict, indent=4)}")- _, errors = self.response_schema.validate_object(- object=assistant_reply_dict,- logger=self.logger,- )+ _, errors = self.response_schema.validate_object(assistant_reply_dict)if errors:raise InvalidAgentResponseError("Validation of response failed:\n "diff --git a/autogpts/autogpt/autogpt/core/utils/json_schema.py b/autogpts/autogpt/autogpt/core/utils/json_schema.pyindex c9f9026e0b..d72b509dd0 100644--- a/autogpts/autogpt/autogpt/core/utils/json_schema.py+++ b/autogpts/autogpt/autogpt/core/utils/json_schema.py@@ -1,9 +1,8 @@import enum-from logging import Loggerfrom textwrap import indent-from typing import Literal, Optional+from typing import Optional-from jsonschema import Draft7Validator+from jsonschema import Draft7Validator, ValidationErrorfrom pydantic import BaseModel@@ -84,27 +83,24 @@ class JSONSchema(BaseModel):v.required = k in schema_node["required"]return properties- def validate_object(- self, object: object, logger: Logger- ) -> tuple[Literal[True], None] | tuple[Literal[False], list]:+ def validate_object(self, object: object) -> tuple[bool, list[ValidationError]]:"""- Validates a dictionary object against the JSONSchema.+ Validates an object or a value against the JSONSchema.Params:- object: The dictionary object to validate.+ object: The value/object to validate.schema (JSONSchema): The JSONSchema to validate against.Returns:- tuple: A tuple where the first element is a boolean indicating whether the- object is valid or not, and the second element is a list of errors found- in the object, or None if the object is valid.+ bool: Indicates whether the given value or object is valid for the schema.+ list[ValidationError]: The issues with the value or object (if any)."""validator = Draft7Validator(self.to_dict())if errors := sorted(validator.iter_errors(object), key=lambda e: e.path):return False, errors- return True, None+ return True, []def to_typescript_object_interface(self, interface_name: str = "") -> str:if self.type != JSONSchema.Type.OBJECT: