helpers
Class info¶
🛈 DocStrings¶
Module for creating OpenAI function schemas from Python functions.
determine_function_type
¶
Determine the type of the function.
Source code in src/schemez/functionschema/helpers.py
get_param_type
¶
Get the Python type for a parameter based on its schema details.
Source code in src/schemez/functionschema/helpers.py
is_optional_type
¶
Check if a type is Optional[T] or T | None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typ
|
type
|
Type to check |
required |
Returns:
| Type | Description |
|---|---|
TypeGuard[type]
|
True if the type is Optional, False otherwise |
Source code in src/schemez/functionschema/helpers.py
pydantic_model_to_signature
¶
Convert a Pydantic model to an inspect.Signature.
Model fields are represented as keyword-only parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type[BaseModel]
|
The Pydantic model to convert. |
required |
return_type
|
type
|
The return type of the function. |
required |
Source code in src/schemez/functionschema/helpers.py
resolve_type_annotation
¶
resolve_type_annotation(
typ: Any,
description: str | None = None,
default: Any = empty,
is_parameter: bool = True,
defs: dict[str, Any] | None = None,
) -> Property
Resolve a type annotation into an OpenAI schema type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typ
|
Any
|
Type to resolve |
required |
description
|
str | None
|
Optional description |
None
|
default
|
Any
|
Default value if any |
empty
|
is_parameter
|
bool
|
Whether this is for a parameter (affects dict schema) |
True
|
defs
|
dict[str, Any] | None
|
Collects the definitions of recursive types, referenced as
|
None
|
Source code in src/schemez/functionschema/helpers.py
types_match
¶
Check if annotation matches exclude_type using various strategies.