function_utils
get_typed_annotation
Get the type annotation of a parameter.
Arguments:
annotation
- The annotation of the parameterglobalns
- The global namespace of the function
Returns:
The type annotation of the parameter
get_typed_signature
Get the signature of a function with type annotations.
Arguments:
call
- The function to get the signature for
Returns:
The signature of the function with type annotations
get_typed_return_annotation
Get the return annotation of a function.
Arguments:
call
- The function to get the return annotation for
Returns:
The return annotation of the function
get_param_annotations
Get the type annotations of the parameters of a function
Arguments:
typed_signature
- The signature of the function with type annotations
Returns:
A dictionary of the type annotations of the parameters of the function
Parameters
Parameters of a function as defined by the OpenAI API
Function
A function as defined by the OpenAI API
ToolFunction
A function under tool as defined by the OpenAI API.
get_parameter_json_schema
Get a JSON schema for a parameter as defined by the OpenAI API
Arguments:
k
- The name of the parameterv
- The type of the parameterdefault_values
- The default values of the parameters of the function
Returns:
A Pydanitc model for the parameter
get_required_params
Get the required parameters of a function
Arguments:
signature
- The signature of the function as returned by inspect.signature
Returns:
A list of the required parameters of the function
get_default_values
Get default values of parameters of a function
Arguments:
signature
- The signature of the function as returned by inspect.signature
Returns:
A dictionary of the default values of the parameters of the function
get_parameters
Get the parameters of a function as defined by the OpenAI API
Arguments:
required
- The required parameters of the functionhints
- The type hints of the function as returned by typing.get_type_hints
Returns:
A Pydantic model for the parameters of the function
get_missing_annotations
Get the missing annotations of a function
Ignores the parameters with default values as they are not required to be annotated, but logs a warning.
Arguments:
typed_signature
- The signature of the function with type annotationsrequired
- The required parameters of the function
Returns:
A set of the missing annotations of the function
get_function_schema
Get a JSON schema for a function as defined by the OpenAI API
Arguments:
f
- The function to get the JSON schema forname
- The name of the functiondescription
- The description of the function
Returns:
A JSON schema for the function
Raises:
TypeError
- If the function is not annotated
Examples:
get_load_param_if_needed_function
Get a function to load a parameter if it is a Pydantic model
Arguments:
t
- The type annotation of the parameter
Returns:
A function to load the parameter if it is a Pydantic model, otherwise None
load_basemodels_if_needed
A decorator to load the parameters of a function if they are Pydantic models
Arguments:
func
- The function with annotated parameters
Returns:
A function that loads the parameters before calling the original function