aiq.builder.function_info#

Attributes#

Classes#

Functions#

_get_annotated_type(→ type)

_validate_single_fn(→ tuple[type, type])

_validate_stream_fn(→ tuple[type, type])

Module Contents#

logger#
P#
SingleCallableT#
StreamCallableT#
_get_annotated_type(annotated_type: type) type#
_validate_single_fn(
single_fn: SingleCallableT | None,
) tuple[type, type]#
_validate_stream_fn(
stream_fn: StreamCallableT | None,
) tuple[type, type]#
class FunctionDescriptor#
func: collections.abc.Callable#
arg_count: int#
is_coroutine: bool#

Whether the function is a coroutine or not.

is_async_gen: bool#

Whether the function is an async generator or not.

input_type: type | type[None] | None#

The direct annotated input type to the function. If the function has multiple arguments, this will be a tuple of the annotated types. If the function has no annotations, this will be None. If the function has no arguments, this will be NoneType.

input_schema: type[pydantic.BaseModel] | type[None] | None#

The Pydantic schema for the input to the function. This will always be a Pydantic model with the arguments as fields ( even if the function only has one BaseModel input argument). If the function has no input, this will be NoneType. If the function has no annotations, this will be None.

input_type_is_base_model: bool#

True if the input type is a subclass of BaseModel, False otherwise

output_type: type | type[None] | None#

The direct annotated output type to the function. If the function has no annotations, this will be None. If the function has no return type, this will be NoneType.

output_schema: type[pydantic.BaseModel] | type[None] | None#

The Pydantic schema for the output of the function. If the return type is already a BaseModel, the schema will be the same as the output_type. If the function has no return type, this will be NoneType. If the function has no annotations, this will be None.

output_type_is_base_model: bool#

True if the output type is a subclass of BaseModel, False otherwise

is_input_typed: bool#

True if all of the functions input arguments have type annotations, False otherwise

is_output_typed: bool#

True if the function has a return type annotation, False otherwise

converters: list[collections.abc.Callable]#

A list of converters for converting to/from the function’s input/output types. Converters are created when determining the output schema of a function.

get_base_model_function_input() type[pydantic.BaseModel] | type[None] | None#

Returns a BaseModel type which can be used as the function input. If the InputType is a BaseModel, it will be returned, otherwise the InputSchema will be returned. If the function has no input, NoneType will be returned.

get_base_model_function_output(
converters: list[collections.abc.Callable] | None = None,
) type[pydantic.BaseModel] | type[None] | None#

Returns a BaseModel type which can be used as the function output. If the OutputType is a BaseModel, it will be returned, otherwise the OutputSchema will be returned. If the function has no output, NoneType will be returned.

static from_function(func: collections.abc.Callable) FunctionDescriptor#
class FunctionInfo(
*,
single_fn: SingleCallableT | None = None,
stream_fn: StreamCallableT | None = None,
input_schema: type[pydantic.BaseModel] | type[None],
single_output_schema: type[pydantic.BaseModel] | type[None],
stream_output_schema: type[pydantic.BaseModel] | type[None],
description: str | None = None,
converters: list[collections.abc.Callable] | None = None,
)#
single_fn = None#
stream_fn = None#
input_schema#
single_output_schema#
stream_output_schema#
description = None#
converters = None#
single_output_type: type#
stream_output_type: type#
static create(
*,
single_fn: SingleCallableT | None = None,
stream_fn: StreamCallableT | None = None,
input_schema: type[pydantic.BaseModel] | type[None] | None = None,
single_output_schema: type[pydantic.BaseModel] | type[None] | None = None,
stream_output_schema: type[pydantic.BaseModel] | type[None] | None = None,
single_to_stream_fn: collections.abc.Callable[[Any], collections.abc.AsyncGenerator[Any]] | None = None,
stream_to_single_fn: collections.abc.Callable[[collections.abc.AsyncGenerator[Any]], collections.abc.Awaitable[Any]] | None = None,
description: str | None = None,
converters: list[collections.abc.Callable] | None = None,
) FunctionInfo#
static from_fn(
fn: SingleCallableT | StreamCallableT,
*,
input_schema: type[pydantic.BaseModel] | None = None,
description: str | None = None,
converters: list[collections.abc.Callable] | None = None,
) FunctionInfo#

Creates a FunctionInfo object from either a single or stream function. Automatically determines the type of function and creates the appropriate FunctionInfo object. Supports type annotations for conversion functions.

Parameters#

fnSingleCallableT | StreamCallableT

The function to create the FunctionInfo object from

input_schematype[BaseModel] | None, optional

A schema object which defines the input to the function, by default None

descriptionstr | None, optional

A description to set to the function, by default None

converterslist[Callable] | None, optional

A list of converters for converting to/from the function’s input/output types, by default None

Returns#

FunctionInfo

The created FunctionInfo object which can be used to create a Generic AgentIQ function.