executable
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| ExecutableFunction schemez.functionschema.executable Wrapper for executing functions with different calling patterns. |
🛈 DocStrings¶
ExecutableFunction
¶
Wrapper for executing functions with different calling patterns.
Source code in src/schemez/functionschema/executable.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
__init__
¶
__init__(
schema: FunctionSchema,
func: (
Callable[..., T_co]
| Callable[..., Generator[T_co]]
| Callable[..., AsyncGenerator[T_co]]
| Callable[..., AsyncIterator[T_co]]
),
) -> None
Initialize with schema and function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
FunctionSchema
|
OpenAI function schema |
required |
func
|
Callable[..., T_co] | Callable[..., Generator[T_co]] | Callable[..., AsyncGenerator[T_co]] | Callable[..., AsyncIterator[T_co]]
|
The actual function to execute |
required |
Source code in src/schemez/functionschema/executable.py
arun
async
¶
Run the function asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments to pass to the function |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
| Type | Description |
|---|---|
T_co | list[T_co]
|
Function result or list of results for generators |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the function type is unknown |
Source code in src/schemez/functionschema/executable.py
astream
async
¶
Stream results from the function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments to pass to the function |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[T_co]
|
Individual results as they become available |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the function type is unknown |
Source code in src/schemez/functionschema/executable.py
run
¶
Run the function synchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments to pass to the function |
()
|
**kwargs
|
Any
|
Keyword arguments to pass to the function |
{}
|
Returns:
| Type | Description |
|---|---|
T_co | list[T_co]
|
Either a single result or list of results for generators |
Inside a running event loop, coroutines run on a worker thread's own loop
(blocking the caller); use arun from async code.
Source code in src/schemez/functionschema/executable.py
create_executable
¶
create_executable(func: Callable[..., Generator[T_co]]) -> ExecutableFunction[T_co]
create_executable(func: Callable[..., AsyncGenerator[T_co]]) -> ExecutableFunction[T_co]
create_executable(func: Callable[..., T_co]) -> ExecutableFunction[T_co]
create_executable(
func: (
Callable[..., T_co] | Callable[..., Generator[T_co]] | Callable[..., AsyncGenerator[T_co]]
),
) -> ExecutableFunction[T_co]
Create an executable function wrapper with schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., T_co] | Callable[..., Generator[T_co]] | Callable[..., AsyncGenerator[T_co]]
|
Function to wrap |
required |
Returns:
| Type | Description |
|---|---|
ExecutableFunction[T_co]
|
Executable wrapper with schema |