Parameter for a function.
Arguments:
name
(str
): The name of the parameter.description
(Optional[str]
): The description of the parameter.type
(str
): The type of the parameter.default
(Any
): The default value of the parameter.required
(bool
): Whether the parameter is required.Convert the parameter to a dictionary for an Ollama-compatible function schema.
Returns:
Dict[str, Any]
: The parameter in dictionary format.
Class that consumes a function and can return a schema required by different LLMs for function calling.
Initialize the FunctionSchema.
Arguments:
function
(Union[Callable, BaseModel]
): The function to consume.Convert the FunctionSchema to an Ollama-compatible function schema dictionary.
Returns:
Dict[str, Any]
: The function schema in dictionary format.
Get a list of function schemas from a list of functions or Pydantic BaseModels.
Arguments:
items
(List[Union[BaseModel, Callable]]
): The functions or BaseModels to get the schemas for.Returns:
List[Dict[str, Any]]
: A list of function schemas.
Get a function schema from a function or Pydantic BaseModel.
Arguments:
item
(Union[BaseModel, Callable]
): The function or BaseModel to get the schema for.Returns:
Dict[str, Any]
: The function schema.
Convert a Python type to a JSON type.
Arguments:
param_type
(str
): The type of the parameter.Returns:
str
: The JSON type.
Route and execute a function.
Arguments:
query
(str
): The query to route and execute.llm
(BaseLLM
): The LLM to use.functions
(List[Callable]
): The functions to execute.layer
(Layer
): The layer to use.Returns:
Any
: The result of the function.