Parameter Objects

class Parameter(BaseModel)
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

def 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 FunctionSchema()
Class that consumes a function and can return a schema required by different LLMs for function calling.

__init__

def __init__(function: Union[Callable, BaseModel])
Initialize the FunctionSchema. Arguments:
  • function (Union[Callable, BaseModel]): The function to consume.

to_ollama

def 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

def get_schema_list(
        items: List[Union[BaseModel, Callable]]) -> List[Dict[str, Any]]
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

def get_schema(item: Union[BaseModel, Callable]) -> Dict[str, Any]
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

def convert_python_type_to_json_type(param_type: str) -> str
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

async def route_and_execute(query: str, llm: BaseLLM,
                            functions: List[Callable], layer) -> Any
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.