From 84e4afca66bbb507205c1933007e142539244585 Mon Sep 17 00:00:00 2001 From: raywhoelse <112615585+raywhoelse@users.noreply.github.com> Date: Wed, 17 Jul 2024 23:03:44 +0800 Subject: [PATCH] format code --- camel/agents/chat_agent.py | 3 ++- camel/utils/commons.py | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.py index b04cad08f5..d3a1353fa0 100644 --- a/camel/agents/chat_agent.py +++ b/camel/agents/chat_agent.py @@ -553,7 +553,8 @@ def _structured_output_openai_response(self, output_schema: BaseModel): into the tools for the OpenAI model configuration. Args: - output_schema (BaseModel): The schema representing the expected output structure. + output_schema (BaseModel): The schema representing the expected + output structure. Returns: None diff --git a/camel/utils/commons.py b/camel/utils/commons.py index 0ea7c674a4..a65921061e 100644 --- a/camel/utils/commons.py +++ b/camel/utils/commons.py @@ -325,7 +325,8 @@ def find_and_check_subset(small, big) -> bool: big (dict or list or any): The larger set to compare against. Returns: - bool: True if 'small' is a subset of 'big' at any level, False otherwise. + bool: True if 'small' is a subset of 'big' at any level, False + otherwise. """ # First, check if 'small' is a subset of 'big' directly if is_subset(small, big): @@ -333,7 +334,7 @@ def find_and_check_subset(small, big) -> bool: # If 'big' is a dictionary, recursively check its values if isinstance(big, dict): - for key, value in big.items(): + for value in big.values(): if find_and_check_subset(small, value): return True @@ -359,13 +360,15 @@ def is_subset(small, big) -> bool: bool: True if 'small' is a subset of 'big', False otherwise. """ if isinstance(small, dict) and isinstance(big, dict): - # If both are dictionaries, check if all key-value pairs in 'small' exist in 'big' + # If both are dictionaries, check if all key-value pairs in 'small' + # exist in 'big' for key, value in small.items(): if key not in big or not is_subset(value, big[key]): return False return True elif isinstance(small, list) and isinstance(big, list): - # If both are lists, check if each item in 'small' is a subset of any item in 'big' + # If both are lists, check if each item in 'small' is a subset of any + # item in 'big' for item in small: if not any(is_subset(item, big_item) for big_item in big): return False @@ -451,8 +454,6 @@ def get_pydantic_object_schema(pydantic_params: BaseModel) -> Dict: PYDANTIC_MAJOR_VERSION = get_pydantic_major_version() if PYDANTIC_MAJOR_VERSION == 2: return pydantic_params.model_json_schema() - else: - return pydantic_params.schema() def get_pydantic_major_version() -> int: @@ -487,8 +488,10 @@ def func_string_to_callable(code: str): def json_to_function_code(json_obj): r"""Generate a Python function code from a JSON schema. + Args: - json_obj (dict): The JSON schema object containing properties and required fields, and json format is follow openai tools schema + json_obj (dict): The JSON schema object containing properties and + required fields, and json format is follow openai tools schema Returns: str: The generated Python function code as a string.