gen_ai_hub.orchestration_v2.models.tools module¶
Models for tools used in chat completions with function calling.
- gen_ai_hub.orchestration_v2.models.tools.python_type_to_json_type(py_type)¶
Convert a Python type to a JSON Schema type.
- Parameters:
py_type (any) – the Python type to convert
- Returns:
A dictionary representing the JSON Schema type.
- Return type:
dict
- class gen_ai_hub.orchestration_v2.models.tools.ChatCompletionTool(*, type: Literal['function'] = 'function')¶
Bases:
ABCBaseModelBase class for all chat completion tools.
- Parameters:
type (Literal["function"]) – The type of the tool. Currently, only function is supported.
- type_: Literal['function']¶
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': False}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gen_ai_hub.orchestration_v2.models.tools.FunctionObject(*, description: str | None = None, name: str, parameters: dict | None, strict: bool = False, function: Callable | None = None)¶
Bases:
ABCBaseModelRepresents a function. :param name: The name of the function to be called. Must be a-z, A-Z, 0-9,
or contain underscores and dashes, with a maximum length of 64.
- Parameters:
description (str) – A description of what the function does, used by the model to choose when and how to call the function.
parameters (dict) – The parameters the functions accepts, described as a JSON Schema object. Omitting parameters defines a function with an empty parameter list.
strict (bool, optional) – Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the parameters field. Only a subset of JSON Schema is supported when strict is true. Defaults to False.
- description: str | None¶
- name: str¶
- parameters: dict | None¶
- strict: bool¶
- function: Callable | None¶
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': False}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gen_ai_hub.orchestration_v2.models.tools.FunctionTool(*, type: Literal['function'] = 'function', function: FunctionObject)¶
Bases:
ChatCompletionToolRepresents a function tool for OpenAI-like function calling.
- Parameters:
type (Literal["function"]) – The type of the tool. Currently, only function is supported.
function (FunctionObject) – The function to be called.
- type_: Literal['function']¶
- function: FunctionObject¶
- execute(**kwargs: Any) Any¶
Execute the function with the provided arguments.
- async aexecute(**kwargs: Any) Any¶
Asynchronously execute the function with the provided arguments.
- static from_function(func: Callable, *, description: str | None = None, strict: bool = False) FunctionTool¶
Create a FunctionTool from a Python function.
- Parameters:
func (Callable) – The function to be converted to a FunctionTool.
description (Optional[str]) – A description of the function. Defaults to the docstring of the function.
strict (bool) – Whether to enable strict schema adherence when generating the function call.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': False}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- gen_ai_hub.orchestration_v2.models.tools.function_tool(func: Callable | None = None, *, description: str | None = None, strict: bool = False) Callable[[Callable], FunctionTool] | FunctionTool¶
Decorator that converts a function into a FunctionTool.
- Usage:
@function_tool def my_func(…): …
@function_tool() def my_func(…): …