schemez 1.1.1__py3-none-any.whl → 1.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- schemez/__init__.py +21 -0
- schemez/bind_kwargs.py +193 -0
- schemez/convert.py +1 -1
- schemez/create_type.py +340 -0
- schemez/executable.py +211 -0
- schemez/functionschema.py +772 -0
- schemez/helpers.py +9 -5
- schemez/log.py +17 -0
- schemez/schema_generators.py +215 -0
- schemez/tool_executor/__init__.py +8 -0
- schemez/tool_executor/executor.py +322 -0
- schemez/tool_executor/helpers.py +46 -0
- schemez/tool_executor/types.py +28 -0
- schemez/typedefs.py +205 -0
- schemez-1.2.2.dist-info/METADATA +340 -0
- schemez-1.2.2.dist-info/RECORD +25 -0
- {schemez-1.1.1.dist-info → schemez-1.2.2.dist-info}/WHEEL +1 -1
- schemez-1.2.2.dist-info/licenses/LICENSE +22 -0
- schemez-1.1.1.dist-info/METADATA +0 -85
- schemez-1.1.1.dist-info/RECORD +0 -13
schemez/typedefs.py
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import inspect
|
4
|
+
from typing import Any, Literal, NotRequired, TypedDict
|
5
|
+
|
6
|
+
|
7
|
+
class PropertyBase(TypedDict, total=False):
|
8
|
+
"""Base schema property with common fields."""
|
9
|
+
|
10
|
+
type: str
|
11
|
+
description: str
|
12
|
+
format: str
|
13
|
+
default: Any
|
14
|
+
enum: NotRequired[list[Any]]
|
15
|
+
|
16
|
+
|
17
|
+
class SimpleProperty(PropertyBase):
|
18
|
+
"""Schema property for primitive types."""
|
19
|
+
|
20
|
+
type: Literal["string", "number", "integer", "boolean"]
|
21
|
+
enum: NotRequired[list[Any]]
|
22
|
+
|
23
|
+
|
24
|
+
class ArrayProperty(PropertyBase):
|
25
|
+
"""Schema property for array types."""
|
26
|
+
|
27
|
+
type: Literal["array"]
|
28
|
+
items: Property
|
29
|
+
|
30
|
+
|
31
|
+
class ObjectProperty(PropertyBase):
|
32
|
+
"""Schema property for nested object types."""
|
33
|
+
|
34
|
+
type: Literal["object"]
|
35
|
+
properties: NotRequired[dict[str, Property]]
|
36
|
+
required: NotRequired[list[str]]
|
37
|
+
additionalProperties: NotRequired[bool]
|
38
|
+
|
39
|
+
|
40
|
+
Property = ArrayProperty | ObjectProperty | SimpleProperty
|
41
|
+
|
42
|
+
|
43
|
+
class ToolParameters(TypedDict):
|
44
|
+
"""Schema for function parameters."""
|
45
|
+
|
46
|
+
type: Literal["object"]
|
47
|
+
properties: dict[str, Property]
|
48
|
+
required: NotRequired[list[str]]
|
49
|
+
|
50
|
+
|
51
|
+
class OpenAIFunctionDefinition(TypedDict):
|
52
|
+
"""Schema for the function definition part of an OpenAI tool.
|
53
|
+
|
54
|
+
This represents the inner "function" object that contains the actual
|
55
|
+
function metadata and parameters.
|
56
|
+
"""
|
57
|
+
|
58
|
+
name: str
|
59
|
+
description: str
|
60
|
+
parameters: ToolParameters
|
61
|
+
|
62
|
+
|
63
|
+
class OpenAIFunctionTool(TypedDict):
|
64
|
+
"""Complete OpenAI tool definition for function calling.
|
65
|
+
|
66
|
+
This represents the top-level tool object that wraps a function definition
|
67
|
+
and identifies it as a function tool type.
|
68
|
+
"""
|
69
|
+
|
70
|
+
type: Literal["function"]
|
71
|
+
function: OpenAIFunctionDefinition
|
72
|
+
|
73
|
+
|
74
|
+
def _create_simple_property(
|
75
|
+
type_str: Literal["string", "number", "integer", "boolean"],
|
76
|
+
description: str | None = None,
|
77
|
+
enum_values: list[Any] | None = None,
|
78
|
+
default: Any = None,
|
79
|
+
fmt: str | None = None,
|
80
|
+
) -> SimpleProperty:
|
81
|
+
"""Create a simple property."""
|
82
|
+
prop: SimpleProperty = {"type": type_str}
|
83
|
+
if description is not None:
|
84
|
+
prop["description"] = description
|
85
|
+
if enum_values is not None:
|
86
|
+
prop["enum"] = enum_values
|
87
|
+
if default is not inspect.Parameter.empty and default is not None:
|
88
|
+
prop["default"] = default
|
89
|
+
if fmt is not None:
|
90
|
+
prop["format"] = fmt
|
91
|
+
return prop
|
92
|
+
|
93
|
+
|
94
|
+
def _create_array_property(
|
95
|
+
items: Property,
|
96
|
+
description: str | None = None,
|
97
|
+
) -> ArrayProperty:
|
98
|
+
"""Create an array property."""
|
99
|
+
prop: ArrayProperty = {
|
100
|
+
"type": "array",
|
101
|
+
"items": items,
|
102
|
+
}
|
103
|
+
if description is not None:
|
104
|
+
prop["description"] = description
|
105
|
+
return prop
|
106
|
+
|
107
|
+
|
108
|
+
def _create_object_property(
|
109
|
+
description: str | None = None,
|
110
|
+
properties: dict[str, Property] | None = None,
|
111
|
+
required: list[str] | None = None,
|
112
|
+
additional_properties: bool | None = None,
|
113
|
+
) -> ObjectProperty:
|
114
|
+
"""Create an object property.
|
115
|
+
|
116
|
+
Args:
|
117
|
+
description: Optional property description
|
118
|
+
properties: Optional dict of property definitions
|
119
|
+
required: Optional list of required property names
|
120
|
+
additional_properties: Whether to allow additional properties
|
121
|
+
|
122
|
+
Returns:
|
123
|
+
Object property definition
|
124
|
+
"""
|
125
|
+
prop: ObjectProperty = {"type": "object"}
|
126
|
+
if description is not None:
|
127
|
+
prop["description"] = description
|
128
|
+
if properties is not None:
|
129
|
+
prop["properties"] = properties
|
130
|
+
if required is not None:
|
131
|
+
prop["required"] = required
|
132
|
+
if additional_properties is not None:
|
133
|
+
prop["additionalProperties"] = additional_properties
|
134
|
+
return prop
|
135
|
+
|
136
|
+
|
137
|
+
def _convert_complex_property(
|
138
|
+
prop: dict[str, Any],
|
139
|
+
description: str | None = None,
|
140
|
+
) -> Property:
|
141
|
+
"""Convert complex schema properties to simple OpenAI-compatible types.
|
142
|
+
|
143
|
+
Args:
|
144
|
+
prop: Complex property definition
|
145
|
+
description: Optional property description
|
146
|
+
|
147
|
+
Returns:
|
148
|
+
Simplified Property compatible with OpenAI
|
149
|
+
"""
|
150
|
+
if "anyOf" in prop or "oneOf" in prop:
|
151
|
+
types = []
|
152
|
+
for subschema in prop.get("anyOf", prop.get("oneOf", [])):
|
153
|
+
if isinstance(subschema, dict):
|
154
|
+
types.append(subschema.get("type")) # noqa: PERF401
|
155
|
+
|
156
|
+
# If null is allowed, treat as optional string
|
157
|
+
if "null" in types:
|
158
|
+
return _create_simple_property(
|
159
|
+
type_str="string",
|
160
|
+
description=description or prop.get("description"),
|
161
|
+
default=None,
|
162
|
+
)
|
163
|
+
|
164
|
+
# Get first non-null type or default to string
|
165
|
+
first_type = next((t for t in types if t != "null"), "string")
|
166
|
+
if first_type not in {"string", "number", "integer", "boolean"}:
|
167
|
+
first_type = "string"
|
168
|
+
|
169
|
+
return _create_simple_property(
|
170
|
+
type_str=first_type, # type: ignore # Valid since we checked above
|
171
|
+
description=description or prop.get("description"),
|
172
|
+
default=prop.get("default"),
|
173
|
+
)
|
174
|
+
|
175
|
+
if prop.get("type") == "array":
|
176
|
+
items = prop.get("items", {"type": "string"})
|
177
|
+
if isinstance(items, dict):
|
178
|
+
items = _convert_complex_property(items)
|
179
|
+
return _create_array_property(
|
180
|
+
items=items,
|
181
|
+
description=description or prop.get("description"),
|
182
|
+
)
|
183
|
+
|
184
|
+
if prop.get("type") == "object":
|
185
|
+
sub_props = prop.get("properties", {})
|
186
|
+
cleaned_props = {
|
187
|
+
name: _convert_complex_property(p) for name, p in sub_props.items()
|
188
|
+
}
|
189
|
+
return _create_object_property(
|
190
|
+
description=description or prop.get("description"),
|
191
|
+
properties=cleaned_props,
|
192
|
+
required=prop.get("required"),
|
193
|
+
)
|
194
|
+
|
195
|
+
type_str = prop.get("type", "string")
|
196
|
+
if type_str not in {"string", "number", "integer", "boolean"}:
|
197
|
+
type_str = "string"
|
198
|
+
|
199
|
+
return _create_simple_property(
|
200
|
+
type_str=type_str, # type: ignore # Valid since we checked above
|
201
|
+
description=description or prop.get("description"),
|
202
|
+
enum_values=prop.get("enum"),
|
203
|
+
default=prop.get("default"),
|
204
|
+
fmt=prop.get("format"),
|
205
|
+
)
|
@@ -0,0 +1,340 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: schemez
|
3
|
+
Version: 1.2.2
|
4
|
+
Summary: Pydantic shim for config stuff
|
5
|
+
Keywords:
|
6
|
+
Author: Philipp Temminghoff
|
7
|
+
Author-email: Philipp Temminghoff <philipptemminghoff@googlemail.com>
|
8
|
+
License-Expression: MIT
|
9
|
+
License-File: LICENSE
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
11
|
+
Classifier: Framework :: Pydantic
|
12
|
+
Classifier: Framework :: Pydantic :: 2
|
13
|
+
Classifier: Intended Audience :: Developers
|
14
|
+
Classifier: Operating System :: OS Independent
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
20
|
+
Classifier: Topic :: Documentation
|
21
|
+
Classifier: Topic :: Software Development
|
22
|
+
Classifier: Topic :: Utilities
|
23
|
+
Classifier: Typing :: Typed
|
24
|
+
Requires-Dist: docstring-parser>=0.17.0
|
25
|
+
Requires-Dist: griffe>=1.7.3
|
26
|
+
Requires-Dist: pydantic
|
27
|
+
Requires-Dist: universal-pathlib>=0.2.6
|
28
|
+
Requires-Dist: llmling-agent ; extra == 'ai'
|
29
|
+
Requires-Dist: anyenv>=0.4.14 ; extra == 'ai'
|
30
|
+
Requires-Dist: datamodel-code-generator ; extra == 'codegen'
|
31
|
+
Requires-Dist: fastapi>=0.118.2 ; extra == 'tool-execution'
|
32
|
+
Requires-Dist: yamling ; extra == 'yaml'
|
33
|
+
Requires-Python: >=3.13
|
34
|
+
Project-URL: Code coverage, https://app.codecov.io/gh/phil65/schemez
|
35
|
+
Project-URL: Discussions, https://github.com/phil65/schemez/discussions
|
36
|
+
Project-URL: Documentation, https://phil65.github.io/schemez/
|
37
|
+
Project-URL: Issues, https://github.com/phil65/schemez/issues
|
38
|
+
Project-URL: Source, https://github.com/phil65/schemez
|
39
|
+
Provides-Extra: ai
|
40
|
+
Provides-Extra: codegen
|
41
|
+
Provides-Extra: tool-execution
|
42
|
+
Provides-Extra: yaml
|
43
|
+
Description-Content-Type: text/markdown
|
44
|
+
|
45
|
+
# Schemez
|
46
|
+
|
47
|
+
[](https://pypi.org/project/schemez/)
|
48
|
+
[](https://pypi.org/project/schemez/)
|
49
|
+
[](https://pypi.org/project/schemez/)
|
50
|
+
[](https://pypi.org/project/schemez/)
|
51
|
+
[](https://pypi.org/project/schemez/)
|
52
|
+
[](https://pypi.org/project/schemez/)
|
53
|
+
[](https://pypi.org/project/schemez/)
|
54
|
+
[](https://github.com/phil65/schemez/releases)
|
55
|
+
[](https://github.com/phil65/schemez/graphs/contributors)
|
56
|
+
[](https://github.com/phil65/schemez/discussions)
|
57
|
+
[](https://github.com/phil65/schemez/forks)
|
58
|
+
[](https://github.com/phil65/schemez/issues)
|
59
|
+
[](https://github.com/phil65/schemez/pulls)
|
60
|
+
[](https://github.com/phil65/schemez/watchers)
|
61
|
+
[](https://github.com/phil65/schemez/stars)
|
62
|
+
[](https://github.com/phil65/schemez)
|
63
|
+
[](https://github.com/phil65/schemez/commits)
|
64
|
+
[](https://github.com/phil65/schemez/releases)
|
65
|
+
[](https://github.com/phil65/schemez)
|
66
|
+
[](https://github.com/phil65/schemez)
|
67
|
+
[](https://codecov.io/gh/phil65/schemez/)
|
68
|
+
[](https://pyup.io/repos/github/phil65/schemez/)
|
69
|
+
|
70
|
+
[Read the documentation!](https://phil65.github.io/schemez/)
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
# OpenAI Function Schema Generator
|
75
|
+
|
76
|
+
Convert Python functions to OpenAI-compatible function schemas automatically.
|
77
|
+
|
78
|
+
## Installation
|
79
|
+
|
80
|
+
```bash
|
81
|
+
pip install schemez
|
82
|
+
```
|
83
|
+
|
84
|
+
## Basic Usage
|
85
|
+
|
86
|
+
```python
|
87
|
+
from schemez import create_schema
|
88
|
+
from typing import Literal
|
89
|
+
|
90
|
+
def get_weather(
|
91
|
+
location: str,
|
92
|
+
unit: Literal["C", "F"] = "C",
|
93
|
+
detailed: bool = False,
|
94
|
+
) -> dict[str, str | float]:
|
95
|
+
"""Get the weather for a location.
|
96
|
+
|
97
|
+
Args:
|
98
|
+
location: City or address to get weather for
|
99
|
+
unit: Temperature unit (Celsius or Fahrenheit)
|
100
|
+
detailed: Include extended forecast
|
101
|
+
"""
|
102
|
+
return {"temp": 22.5, "conditions": "sunny"}
|
103
|
+
|
104
|
+
# Create schema
|
105
|
+
schema = create_schema(get_weather)
|
106
|
+
|
107
|
+
# The schema.model_dump_openai() returns a TypedDict with the complete OpenAI tool definition:
|
108
|
+
# OpenAIFunctionTool = TypedDict({
|
109
|
+
# "type": Literal["function"],
|
110
|
+
# "function": OpenAIFunctionDefinition
|
111
|
+
# })
|
112
|
+
|
113
|
+
# Use with OpenAI
|
114
|
+
from openai import OpenAI
|
115
|
+
|
116
|
+
client = OpenAI()
|
117
|
+
response = client.chat.completions.create(
|
118
|
+
model="gpt-4",
|
119
|
+
messages=[{"role": "user", "content": "What's the weather in London?"}],
|
120
|
+
tools=[schema.model_dump_openai()], # Schema includes the type: "function" wrapper
|
121
|
+
tool_choice="auto"
|
122
|
+
)
|
123
|
+
```
|
124
|
+
|
125
|
+
> **Note**: This library supports the OpenAI API v1 format (openai>=1.0.0). For older
|
126
|
+
> versions of the OpenAI package that use the legacy functions API, you'll need to
|
127
|
+
> unwrap the function definition using `schema.model_dump_openai()["function"]`.
|
128
|
+
```
|
129
|
+
|
130
|
+
## Supported Types
|
131
|
+
|
132
|
+
### Basic Types
|
133
|
+
```python
|
134
|
+
def func(
|
135
|
+
text: str, # -> "type": "string"
|
136
|
+
number: int, # -> "type": "integer"
|
137
|
+
amount: float, # -> "type": "number"
|
138
|
+
enabled: bool, # -> "type": "boolean"
|
139
|
+
anything: Any, # -> "type": "string"
|
140
|
+
) -> None: ...
|
141
|
+
```
|
142
|
+
|
143
|
+
### Container Types
|
144
|
+
```python
|
145
|
+
def func(
|
146
|
+
items: list[str], # -> "type": "array", "items": {"type": "string"}
|
147
|
+
numbers: set[int], # -> same as list
|
148
|
+
mapping: dict[str, Any], # -> "type": "object", "additionalProperties": true
|
149
|
+
nested: list[dict[str, int]], # -> nested array/object types
|
150
|
+
sequence: Sequence[str], # -> "type": "array"
|
151
|
+
collection: Collection[int], # -> "type": "array"
|
152
|
+
) -> None: ...
|
153
|
+
```
|
154
|
+
|
155
|
+
### Enums and Literals
|
156
|
+
```python
|
157
|
+
class Color(Enum):
|
158
|
+
RED = "red"
|
159
|
+
BLUE = "blue"
|
160
|
+
|
161
|
+
def func(
|
162
|
+
color: Color, # -> "type": "string", "enum": ["red", "blue"]
|
163
|
+
mode: Literal["fast", "slow"], # -> "type": "string", "enum": ["fast", "slow"]
|
164
|
+
) -> None: ...
|
165
|
+
```
|
166
|
+
|
167
|
+
### Optional and Union Types
|
168
|
+
```python
|
169
|
+
def func(
|
170
|
+
opt1: str | None, # -> "type": "string"
|
171
|
+
opt2: int | None, # -> "type": "integer"
|
172
|
+
union: str | int, # -> "type": "string" (first type)
|
173
|
+
) -> None: ...
|
174
|
+
```
|
175
|
+
|
176
|
+
### Custom Types
|
177
|
+
```python
|
178
|
+
@dataclass
|
179
|
+
class User:
|
180
|
+
name: str
|
181
|
+
age: int
|
182
|
+
|
183
|
+
def func(
|
184
|
+
user: User, # -> "type": "object"
|
185
|
+
data: JsonDict, # -> "type": "object"
|
186
|
+
) -> None: ...
|
187
|
+
```
|
188
|
+
|
189
|
+
### Type Aliases
|
190
|
+
```python
|
191
|
+
JsonValue = dict[str, Any] | list[Any] | str | int | float | bool | None
|
192
|
+
JsonDict = dict[str, JsonValue]
|
193
|
+
|
194
|
+
def func(
|
195
|
+
data: JsonDict, # -> "type": "object"
|
196
|
+
values: list[JsonValue], # -> "type": "array"
|
197
|
+
) -> None: ...
|
198
|
+
```
|
199
|
+
|
200
|
+
### Recursive Types
|
201
|
+
```python
|
202
|
+
def func(
|
203
|
+
tree: dict[str, "dict[str, Any] | str"], # -> "type": "object"
|
204
|
+
nested: dict[str, list["dict[str, Any]"]], # -> "type": "object"
|
205
|
+
) -> None: ...
|
206
|
+
```
|
207
|
+
|
208
|
+
## Generated Schema Example
|
209
|
+
|
210
|
+
```python
|
211
|
+
{
|
212
|
+
"type": "function",
|
213
|
+
"function": {
|
214
|
+
"name": "get_weather",
|
215
|
+
"description": "Get the weather for a location.",
|
216
|
+
"parameters": {
|
217
|
+
"type": "object",
|
218
|
+
"properties": {
|
219
|
+
"location": {
|
220
|
+
"type": "string",
|
221
|
+
"description": "City or address to get weather for"
|
222
|
+
},
|
223
|
+
"unit": {
|
224
|
+
"type": "string",
|
225
|
+
"enum": ["C", "F"],
|
226
|
+
"description": "Temperature unit (Celsius or Fahrenheit)",
|
227
|
+
"default": "C"
|
228
|
+
},
|
229
|
+
"detailed": {
|
230
|
+
"type": "boolean",
|
231
|
+
"description": "Include extended forecast",
|
232
|
+
"default": false
|
233
|
+
}
|
234
|
+
},
|
235
|
+
"required": ["location"]
|
236
|
+
}
|
237
|
+
}
|
238
|
+
}
|
239
|
+
```
|
240
|
+
|
241
|
+
## Schema Generators
|
242
|
+
|
243
|
+
### Module Schemas
|
244
|
+
|
245
|
+
You can generate schemas for all public functions in a module using `create_schemas_from_module`:
|
246
|
+
|
247
|
+
```python
|
248
|
+
from schemez import create_schemas_from_module
|
249
|
+
import math
|
250
|
+
|
251
|
+
# Generate schemas for all public functions
|
252
|
+
schemas = create_schemas_from_module(math)
|
253
|
+
|
254
|
+
# Generate schemas for specific functions only
|
255
|
+
schemas = create_schemas_from_module(math, include_functions=['sin', 'cos'])
|
256
|
+
|
257
|
+
# Import module by string name
|
258
|
+
schemas = create_schemas_from_module('math')
|
259
|
+
```
|
260
|
+
|
261
|
+
### Class Schemas
|
262
|
+
|
263
|
+
Generate schemas for all public methods in a class using `create_schemas_from_class`:
|
264
|
+
|
265
|
+
```python
|
266
|
+
from schemez import create_schemas_from_class
|
267
|
+
|
268
|
+
class Calculator:
|
269
|
+
def add(self, x: int, y: int) -> int:
|
270
|
+
"""Add two numbers.
|
271
|
+
|
272
|
+
Args:
|
273
|
+
x: First number
|
274
|
+
y: Second number
|
275
|
+
|
276
|
+
Returns:
|
277
|
+
Sum of x and y
|
278
|
+
"""
|
279
|
+
return x + y
|
280
|
+
|
281
|
+
@classmethod
|
282
|
+
def multiply(cls, x: int, y: int) -> int:
|
283
|
+
"""Multiply two numbers.
|
284
|
+
|
285
|
+
Args:
|
286
|
+
x: First number
|
287
|
+
y: Second number
|
288
|
+
|
289
|
+
Returns:
|
290
|
+
Product of x and y
|
291
|
+
"""
|
292
|
+
return x * y
|
293
|
+
|
294
|
+
@staticmethod
|
295
|
+
def divide(x: float, y: float) -> float:
|
296
|
+
"""Divide two numbers.
|
297
|
+
|
298
|
+
Args:
|
299
|
+
x: Numerator
|
300
|
+
y: Denominator
|
301
|
+
|
302
|
+
Returns:
|
303
|
+
Result of x divided by y
|
304
|
+
"""
|
305
|
+
return x / y
|
306
|
+
|
307
|
+
# Generate schemas for all public methods
|
308
|
+
schemas = create_schemas_from_class(Calculator)
|
309
|
+
|
310
|
+
# Access individual method schemas
|
311
|
+
add_schema = schemas['Calculator.add']
|
312
|
+
multiply_schema = schemas['Calculator.multiply']
|
313
|
+
divide_schema = schemas['Calculator.divide']
|
314
|
+
```
|
315
|
+
|
316
|
+
The schema generators support:
|
317
|
+
|
318
|
+
- Regular functions
|
319
|
+
- Regular instance methods (bound and unbound)
|
320
|
+
- Class methods
|
321
|
+
- Static methods
|
322
|
+
- Decorated functions / methods
|
323
|
+
- Async functions / methods
|
324
|
+
- Property methods
|
325
|
+
- Basically all stdlib typing features as well as many stdlib types
|
326
|
+
- Method docstrings for descriptions
|
327
|
+
- Default values
|
328
|
+
- Return type hints
|
329
|
+
|
330
|
+
|
331
|
+
## Diferences to pydantic schema generation
|
332
|
+
|
333
|
+
While Pydantics schema generation preserves detailed type information, `schema.model_dump_openai()`
|
334
|
+
simplifies types to match OpenAI's function calling format. Most special types
|
335
|
+
(datetime, UUID, Path, etc.) are handled similarly by both (we only strip unused information), but we handle enums
|
336
|
+
differently: Instead of preserving enum class information, we extract just the values
|
337
|
+
as a string enum. Union types and Optionals are also handled differently - we typically
|
338
|
+
pick the first type to keep the schema simple and practical for AI interaction.
|
339
|
+
This ensures compatibility with OpenAI's function calling API while maintaining enough
|
340
|
+
type information for the AI to understand the function signature.
|
@@ -0,0 +1,25 @@
|
|
1
|
+
schemez/__init__.py,sha256=KkwJF8pfbzw_4cBxwXuUyXIExqdxS8iumvyAL-JUED4,1669
|
2
|
+
schemez/bind_kwargs.py,sha256=ChyArgNa5R8VdwSJmmrQItMH9Ld6hStWBISw-T1wyws,6228
|
3
|
+
schemez/code.py,sha256=usZLov9i5KpK1W2VJxngUzeetgrINtodiooG_AxN-y4,2072
|
4
|
+
schemez/convert.py,sha256=3sOxOgDaFzV7uiOUSM6_Sy0YlafIlZRSevs5y2vT1Kw,4403
|
5
|
+
schemez/create_type.py,sha256=wrdqdzXtfxZfsgp9IroldoYGTJs_Rdli8TiscqhV2bI,11647
|
6
|
+
schemez/docstrings.py,sha256=kmd660wcomXzKac0SSNYxPRNbVCUovrpmE9jwnVRS6c,4115
|
7
|
+
schemez/executable.py,sha256=YM4WcmRyJ9CpzKpNgS0A-Ri0Jd7mAzfHmoaXONI-mIs,7134
|
8
|
+
schemez/functionschema.py,sha256=kAV3W8_ory2vIlJELaSajQUgo8RcbEdu7ACkYpgWniI,26125
|
9
|
+
schemez/helpers.py,sha256=6PnZfbwiQPZGiuHScqkpT3kA2Wm4O3O79gsGA95l7ow,8888
|
10
|
+
schemez/log.py,sha256=i0SDbIfWmuC_nfJdQOYAdUYaR0TBk3Mhu-K3M-lnAM4,364
|
11
|
+
schemez/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
+
schemez/pydantic_types.py,sha256=8vgSl8i2z9n0fB-8AJj-D3TBByEWE5IxItBxQ0XwXFI,1640
|
13
|
+
schemez/schema.py,sha256=u6SDhYDtfCjgy2Aa-_MDLLNcUfEXbeye4T-W6s3AED8,9558
|
14
|
+
schemez/schema_generators.py,sha256=Gze7S7dQkTsl_1ckeHLXPxx4jQo7RB6hHQM-5fpAsrA,6973
|
15
|
+
schemez/schemadef/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
|
+
schemez/schemadef/schemadef.py,sha256=FtD7TOnYxiuYOIfadRHKkkbZn98mWFb0_lKfPsPR-hI,14393
|
17
|
+
schemez/tool_executor/__init__.py,sha256=7wLjhA1NGekTMsiIfWLAv6J7qYhWDlanH9DKU4v1c6c,263
|
18
|
+
schemez/tool_executor/executor.py,sha256=lQFnVO5J64nFNEsy82jRS-q52PaU3fWsnuQddaLOo6c,10410
|
19
|
+
schemez/tool_executor/helpers.py,sha256=jxBv1G_R8rQU3ACHGgfVEecqO0DSZQ6qUIHcn25Ucc4,1470
|
20
|
+
schemez/tool_executor/types.py,sha256=l2DxUIEHP9bjLnEaXZ6X428cSviicTDJsc3wfSNqKxg,675
|
21
|
+
schemez/typedefs.py,sha256=3OAUQ1nin9nlsOcTPAO5xrsOqVUfwsH_7_cexQYREus,6091
|
22
|
+
schemez-1.2.2.dist-info/licenses/LICENSE,sha256=AteGCH9r177TxxrOFEiOARrastASsf7yW6MQxlAHdwA,1078
|
23
|
+
schemez-1.2.2.dist-info/WHEEL,sha256=ZbtZh9LqsQoZs-WmwRO6z-tavdkb5LzNxvrOv2F_OXE,78
|
24
|
+
schemez-1.2.2.dist-info/METADATA,sha256=hIMu_x6gj7dGIFYuILQvUcMb_IvE10OPP_nLcXKWXSA,11616
|
25
|
+
schemez-1.2.2.dist-info/RECORD,,
|
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024, Philipp Temminghoff
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
schemez-1.1.1.dist-info/METADATA
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.3
|
2
|
-
Name: schemez
|
3
|
-
Version: 1.1.1
|
4
|
-
Summary: Pydantic shim for config stuff
|
5
|
-
Keywords:
|
6
|
-
Author: Philipp Temminghoff
|
7
|
-
Author-email: Philipp Temminghoff <philipptemminghoff@googlemail.com>
|
8
|
-
License: MIT License
|
9
|
-
|
10
|
-
Copyright (c) 2024, Philipp Temminghoff
|
11
|
-
|
12
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
13
|
-
of this software and associated documentation files (the "Software"), to deal
|
14
|
-
in the Software without restriction, including without limitation the rights
|
15
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
16
|
-
copies of the Software, and to permit persons to whom the Software is
|
17
|
-
furnished to do so, subject to the following conditions:
|
18
|
-
|
19
|
-
The above copyright notice and this permission notice shall be included in all
|
20
|
-
copies or substantial portions of the Software.
|
21
|
-
|
22
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
23
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
24
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
25
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
26
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
27
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
28
|
-
SOFTWARE.
|
29
|
-
|
30
|
-
Classifier: Development Status :: 4 - Beta
|
31
|
-
Classifier: Framework :: Pydantic
|
32
|
-
Classifier: Framework :: Pydantic :: 2
|
33
|
-
Classifier: Intended Audience :: Developers
|
34
|
-
Classifier: Operating System :: OS Independent
|
35
|
-
Classifier: Programming Language :: Python :: 3
|
36
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
37
|
-
Classifier: Programming Language :: Python :: 3.12
|
38
|
-
Classifier: Programming Language :: Python :: 3.13
|
39
|
-
Classifier: Programming Language :: Python :: 3.14
|
40
|
-
Classifier: Topic :: Documentation
|
41
|
-
Classifier: Topic :: Software Development
|
42
|
-
Classifier: Topic :: Utilities
|
43
|
-
Classifier: Typing :: Typed
|
44
|
-
Requires-Dist: griffe>=1.7.3
|
45
|
-
Requires-Dist: pydantic
|
46
|
-
Requires-Dist: universal-pathlib>=0.2.6
|
47
|
-
Requires-Dist: llmling-agent ; extra == 'ai'
|
48
|
-
Requires-Dist: anyenv>=0.4.14 ; extra == 'ai'
|
49
|
-
Requires-Dist: yamling ; extra == 'yaml'
|
50
|
-
Requires-Python: >=3.13
|
51
|
-
Project-URL: Code coverage, https://app.codecov.io/gh/phil65/schemez
|
52
|
-
Project-URL: Discussions, https://github.com/phil65/schemez/discussions
|
53
|
-
Project-URL: Documentation, https://phil65.github.io/schemez/
|
54
|
-
Project-URL: Issues, https://github.com/phil65/schemez/issues
|
55
|
-
Project-URL: Source, https://github.com/phil65/schemez
|
56
|
-
Provides-Extra: ai
|
57
|
-
Provides-Extra: yaml
|
58
|
-
Description-Content-Type: text/markdown
|
59
|
-
|
60
|
-
# Schemez
|
61
|
-
|
62
|
-
[](https://pypi.org/project/schemez/)
|
63
|
-
[](https://pypi.org/project/schemez/)
|
64
|
-
[](https://pypi.org/project/schemez/)
|
65
|
-
[](https://pypi.org/project/schemez/)
|
66
|
-
[](https://pypi.org/project/schemez/)
|
67
|
-
[](https://pypi.org/project/schemez/)
|
68
|
-
[](https://pypi.org/project/schemez/)
|
69
|
-
[](https://github.com/phil65/schemez/releases)
|
70
|
-
[](https://github.com/phil65/schemez/graphs/contributors)
|
71
|
-
[](https://github.com/phil65/schemez/discussions)
|
72
|
-
[](https://github.com/phil65/schemez/forks)
|
73
|
-
[](https://github.com/phil65/schemez/issues)
|
74
|
-
[](https://github.com/phil65/schemez/pulls)
|
75
|
-
[](https://github.com/phil65/schemez/watchers)
|
76
|
-
[](https://github.com/phil65/schemez/stars)
|
77
|
-
[](https://github.com/phil65/schemez)
|
78
|
-
[](https://github.com/phil65/schemez/commits)
|
79
|
-
[](https://github.com/phil65/schemez/releases)
|
80
|
-
[](https://github.com/phil65/schemez)
|
81
|
-
[](https://github.com/phil65/schemez)
|
82
|
-
[](https://codecov.io/gh/phil65/schemez/)
|
83
|
-
[](https://pyup.io/repos/github/phil65/schemez/)
|
84
|
-
|
85
|
-
[Read the documentation!](https://phil65.github.io/schemez/)
|