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', cache_control: CacheControl | None = None)

Bases: ABCBaseModel

A tool the model may call, identified by type "function".

Parameters:
  • type (Literal["function"]) – The type of the tool. Currently, only function is supported.

  • cache_control – Prompt-caching directive.

type_: Literal['function']
cache_control: CacheControl | 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.FunctionObject(*, description: str | None = None, name: str, parameters: dict | None, strict: bool = False, function: Callable | None = None)

Bases: ABCBaseModel

A function definition used inside a FunctionTool.

Parameters:
  • name – Function name. Must match ^[a-zA-Z0-9_-]+$, max 64 chars.

  • description – What the function does; used by the model to decide when to call it.

  • parameters – JSON Schema object describing accepted parameters.

  • strict – When True, the model follows the schema exactly. 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', cache_control: CacheControl | None = None, function: FunctionObject)

Bases: ChatCompletionTool

A callable function tool for OpenAI-style function calling.

Inherits all fields from ChatCompletionTool:

Parameters:
  • type – Always "function". Serialized via the type alias.

  • cache_control – Prompt-caching directive.

Additional args:

function: The function definition — name, description, parameters schema,

and optional strict flag. See FunctionObject.

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].

type_: Literal['function']
cache_control: CacheControl | None
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(…): …