_remove_a_key
_remove_title_recursively
get_openai_function_schema
get_openai_tool_schema()
in future versions. It parses the
function’s parameters and docstring to construct a JSON schema-like
dictionary.
Parameters:
- func (Callable): The OpenAI function to generate the schema for.
get_openai_tool_schema
- func (Callable): The Python function to be converted into an OpenAI JSON schema.
sanitize_and_enforce_required
- Removes invalid ‘default’ fields from the parameters schema.
- Ensures all fields are marked as required or have null type for optional fields.
- Recursively adds additionalProperties: false to all nested objects.
- parameters_dict (dict): The dictionary representing the function schema.
generate_docstring
- code (str): The source code of the function.
- model (Optional[BaseModelBackend]): An optional language model backend instance. If not provided, a default gpt-4o-mini is used.
FunctionTool
- func (Callable): The function to call. The tool schema is parsed from the function signature and docstring by default.
- openai_tool_schema (Optional[Dict[str, Any]], optional): A user-defined OpenAI tool schema to override the default result. (default: :obj:
None
) - synthesize_schema (Optional[bool], optional): Whether to enable the use of a schema assistant model to automatically synthesize the schema if validation fails or no valid schema is provided. (default: :obj:
False
) - synthesize_schema_model (Optional[BaseModelBackend], optional): An assistant model (e.g., an LLM model) used to synthesize the schema if
synthesize_schema
is enabled and no valid schema is provided. (default: :obj:None
) - synthesize_schema_max_retries (int, optional): The maximum number of attempts to retry schema synthesis using the schema assistant model if the previous attempts fail. (default: 2)
- synthesize_output (Optional[bool], optional): Flag for enabling synthesis output mode, where output is synthesized based on the function’s execution. (default: :obj:
False
) - synthesize_output_model (Optional[BaseModelBackend], optional): Model used for output synthesis in synthesis mode. (default: :obj:
None
) - synthesize_output_format (Optional[Type[BaseModel]], optional): Format for the response when synthesizing output. (default: :obj:
None
)
init
call
is_async
validate_openai_tool_schema
ToolAssistantToolsFunction
.
This function checks if the provided :obj:openai_tool_schema
adheres
to the specifications required by OpenAI’s
:obj:ToolAssistantToolsFunction
. It ensures that the function
description and parameters are correctly formatted according to JSON
Schema specifications.
Parameters:
- openai_tool_schema (Dict[str, Any]): The OpenAI tool schema to validate.
get_openai_tool_schema
set_openai_tool_schema
- schema (Dict[str, Any]): The OpenAI tool schema to set.
get_openai_function_schema
set_openai_function_schema
- openai_function_schema (Dict[str, Any]): The function schema to set within the OpenAI tool schema.
get_function_name
set_function_name
- name (str): The name of the function to set.
get_function_description
set_function_description
- description (str): The description for the function.
get_parameter_description
- param_name (str): The name of the parameter to get the description.
set_parameter_description
- param_name (str): The name of the parameter to set the description for.
- description (str): The description for the parameter.
get_parameter
- param_name (str): The name of the parameter to get the schema.
set_parameter
- param_name (str): The name of the parameter to set the schema for.
- value (Dict[str, Any]): The schema to set for the parameter.
synthesize_openai_tool_schema
max_retries
times in case of failure.
Parameters:
- max_retries (Optional[int], optional): The maximum number of retries for schema synthesis and validation if the process fails. (default: :obj:
None
)
synthesize_execution_output
- args (Optional[tuple]): Positional arguments to pass to the function during synthesis. (default: :obj:
None
) - kwargs (Optional[Dict[str, Any]]): Keyword arguments to pass to the function during synthesis. (default: :obj:
None
)
parameters
parameters
parameters
. It will
firstly check if the input parameters schema is valid. If invalid,
the method will raise :obj:jsonschema.exceptions.SchemaError
.
Parameters:
- value (Dict[str, Any]): the new dictionary value for the function’s parameters.