semantic_router.utils.function_call
Parameter Objects
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.
to_ollama
Convert the parameter to a dictionary for an Ollama-compatible function schema.
Returns:
Dict[str, Any]
: The parameter in dictionary format.
FunctionSchema Objects
Class that consumes a function and can return a schema required by different LLMs for function calling.
__init__
Initialize the FunctionSchema.
Arguments:
function
(Union[Callable, BaseModel]
): The function to consume.
to_ollama
Convert the FunctionSchema to an Ollama-compatible function schema dictionary.
Returns:
Dict[str, Any]
: The function schema in dictionary format.
get_schema_list
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_schema
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_python_type_to_json_type
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
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.