schema_generators
Class info¶
🛈 DocStrings¶
create_constructor_schema
¶
create_constructor_schema(cls: type) -> FunctionSchema
Create OpenAI function schema from class constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type
|
Class to create schema for |
required |
Returns:
| Type | Description |
|---|---|
FunctionSchema
|
OpenAI function schema for class constructor |
Source code in src/schemez/functionschema/schema_generators.py
create_schemas_from_callables
¶
create_schemas_from_callables(
callables: dict[str, Callable[..., Any]],
prefix: str | Literal[False] | None = None,
exclude_private: bool = True,
) -> dict[str, FunctionSchema]
Generate OpenAI function schemas from a dictionary of callables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callables
|
dict[str, Callable[..., Any]]
|
Dictionary mapping names to callable objects |
required |
prefix
|
str | Literal[False] | None
|
Schema name prefix to prepend to function names. If None, no prefix. If False, use raw name. If string, uses that prefix. |
None
|
exclude_private
|
bool
|
Whether to exclude callables starting with underscore |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, FunctionSchema]
|
Dictionary mapping qualified names to FunctionSchema objects |
Example
def foo(x: int) -> str: ... def bar(y: float) -> int: ... callables = {'foo': foo, 'bar': bar} schemas = create_schemas_from_callables(callables, prefix='math') print(schemas['math.foo'])
Source code in src/schemez/functionschema/schema_generators.py
create_schemas_from_class
¶
create_schemas_from_class(
cls: type, prefix: str | Literal[False] | None = None
) -> dict[str, FunctionSchema]
Generate OpenAI function schemas for all public methods in a class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
type
|
The class to generate schemas from |
required |
prefix
|
str | Literal[False] | None
|
Schema name prefix. If None, uses class name. If False, no prefix. If string, uses that prefix. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, FunctionSchema]
|
Dictionary mapping qualified method names to FunctionSchema objects |
Example
class MyClass: ... def my_method(self, x: int) -> str: ... return str(x) schemas = create_schemas_from_class(MyClass) print(schemas['MyClass.my_method'])
Source code in src/schemez/functionschema/schema_generators.py
create_schemas_from_module
¶
create_schemas_from_module(
module: ModuleType | str,
include_functions: list[str] | None = None,
prefix: str | Literal[False] | None = None,
) -> dict[str, FunctionSchema]
Generate OpenAI function schemas from a Python module's functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module
|
ModuleType | str
|
Either a ModuleType object or string name of module to analyze |
required |
include_functions
|
list[str] | None
|
Optional list of function names to specifically include |
None
|
prefix
|
str | Literal[False] | None
|
Schema name prefix. If None, uses module name. If False, no prefix. If string, uses that prefix. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, FunctionSchema]
|
Dictionary mapping function names to FunctionSchema objects |
Raises:
| Type | Description |
|---|---|
ImportError
|
If module string name cannot be imported |
Example
import math schemas = create_schemas_from_module(math, ['sin', 'cos']) print(schemas['math.sin'])