schemez 1.2.2__py3-none-any.whl → 1.2.4__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.
Potentially problematic release.
This version of schemez might be problematic. Click here for more details.
- schemez/functionschema.py +9 -11
- schemez/helpers.py +5 -40
- schemez/schema.py +5 -4
- schemez/tool_executor/executor.py +7 -6
- schemez/tool_executor/helpers.py +2 -2
- {schemez-1.2.2.dist-info → schemez-1.2.4.dist-info}/METADATA +1 -1
- {schemez-1.2.2.dist-info → schemez-1.2.4.dist-info}/RECORD +9 -9
- {schemez-1.2.2.dist-info → schemez-1.2.4.dist-info}/WHEEL +1 -1
- {schemez-1.2.2.dist-info → schemez-1.2.4.dist-info}/licenses/LICENSE +0 -0
schemez/functionschema.py
CHANGED
|
@@ -12,7 +12,6 @@ import decimal
|
|
|
12
12
|
import enum
|
|
13
13
|
import inspect
|
|
14
14
|
import ipaddress
|
|
15
|
-
import logging
|
|
16
15
|
from pathlib import Path
|
|
17
16
|
import re
|
|
18
17
|
import types
|
|
@@ -23,6 +22,7 @@ from uuid import UUID
|
|
|
23
22
|
import docstring_parser
|
|
24
23
|
import pydantic
|
|
25
24
|
|
|
25
|
+
from schemez import log
|
|
26
26
|
from schemez.typedefs import (
|
|
27
27
|
OpenAIFunctionDefinition,
|
|
28
28
|
OpenAIFunctionTool,
|
|
@@ -34,7 +34,7 @@ if typing.TYPE_CHECKING:
|
|
|
34
34
|
from schemez.typedefs import Property
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
logger =
|
|
37
|
+
logger = log.get_logger(__name__)
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
class FunctionType(enum.StrEnum):
|
|
@@ -119,6 +119,9 @@ class FunctionSchema(pydantic.BaseModel):
|
|
|
119
119
|
required = self.parameters.get("required", self.required)
|
|
120
120
|
|
|
121
121
|
for name, details in properties.items():
|
|
122
|
+
if name.startswith("_"): # TODO: kwarg for renaming instead perhaps?
|
|
123
|
+
logger.debug("Skipping parameter %s due to leading underscore", name)
|
|
124
|
+
continue
|
|
122
125
|
# Get base type
|
|
123
126
|
if "enum" in details:
|
|
124
127
|
values = tuple(details["enum"]) # type: ignore
|
|
@@ -246,19 +249,14 @@ class FunctionSchema(pydantic.BaseModel):
|
|
|
246
249
|
RuntimeError: If datamodel-codegen is not available
|
|
247
250
|
subprocess.CalledProcessError: If code generation fails
|
|
248
251
|
"""
|
|
252
|
+
import shutil
|
|
249
253
|
import subprocess
|
|
250
254
|
import tempfile
|
|
251
255
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
subprocess.run(
|
|
255
|
-
["datamodel-codegen", "--version"],
|
|
256
|
-
check=True,
|
|
257
|
-
capture_output=True,
|
|
258
|
-
)
|
|
259
|
-
except (subprocess.CalledProcessError, FileNotFoundError) as e:
|
|
256
|
+
# Check if datamodel-codegen is available
|
|
257
|
+
if not shutil.which("datamodel-codegen"):
|
|
260
258
|
msg = "datamodel-codegen not available"
|
|
261
|
-
raise RuntimeError(msg)
|
|
259
|
+
raise RuntimeError(msg)
|
|
262
260
|
|
|
263
261
|
name = class_name or f"{self.name.title()}Response"
|
|
264
262
|
|
schemez/helpers.py
CHANGED
|
@@ -4,8 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import importlib
|
|
7
|
-
import os
|
|
8
7
|
from pathlib import Path
|
|
8
|
+
import shutil
|
|
9
9
|
import subprocess
|
|
10
10
|
import sys
|
|
11
11
|
import tempfile
|
|
@@ -15,7 +15,6 @@ from pydantic import BaseModel
|
|
|
15
15
|
from pydantic_core import to_json
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
StrPath = str | os.PathLike[str]
|
|
19
18
|
PythonVersion = Literal["3.13", "3.14", "3.15"]
|
|
20
19
|
|
|
21
20
|
if TYPE_CHECKING:
|
|
@@ -177,42 +176,6 @@ def resolve_type_string(type_string: str, safe: bool = True) -> type:
|
|
|
177
176
|
raise ValueError(msg) from e
|
|
178
177
|
|
|
179
178
|
|
|
180
|
-
async def _detect_command(command: str, *, test_flag: str = "--version") -> list[str]:
|
|
181
|
-
"""Detect the correct command prefix for running a command.
|
|
182
|
-
|
|
183
|
-
Tries 'uv run' first, then falls back to direct execution.
|
|
184
|
-
|
|
185
|
-
Args:
|
|
186
|
-
command: The command to detect
|
|
187
|
-
test_flag: Flag to test command availability with
|
|
188
|
-
|
|
189
|
-
Returns:
|
|
190
|
-
Command prefix list (empty for direct execution)
|
|
191
|
-
|
|
192
|
-
Raises:
|
|
193
|
-
RuntimeError: If command is not available
|
|
194
|
-
"""
|
|
195
|
-
cmd_prefixes = [["uv", "run"], []]
|
|
196
|
-
|
|
197
|
-
for prefix in cmd_prefixes:
|
|
198
|
-
try:
|
|
199
|
-
proc = await asyncio.create_subprocess_exec(
|
|
200
|
-
*prefix,
|
|
201
|
-
command,
|
|
202
|
-
test_flag,
|
|
203
|
-
stdout=asyncio.subprocess.PIPE,
|
|
204
|
-
stderr=asyncio.subprocess.PIPE,
|
|
205
|
-
)
|
|
206
|
-
await proc.communicate()
|
|
207
|
-
if proc.returncode == 0:
|
|
208
|
-
return prefix
|
|
209
|
-
except FileNotFoundError:
|
|
210
|
-
continue
|
|
211
|
-
|
|
212
|
-
msg = f"{command} not available (tried both 'uv run' and direct execution)"
|
|
213
|
-
raise RuntimeError(msg)
|
|
214
|
-
|
|
215
|
-
|
|
216
179
|
async def model_to_python_code(
|
|
217
180
|
model: type[BaseModel] | dict[str, Any],
|
|
218
181
|
*,
|
|
@@ -236,7 +199,10 @@ async def model_to_python_code(
|
|
|
236
199
|
RuntimeError: If datamodel-codegen is not available
|
|
237
200
|
subprocess.CalledProcessError: If code generation fails
|
|
238
201
|
"""
|
|
239
|
-
|
|
202
|
+
# Check if datamodel-codegen is available
|
|
203
|
+
if not shutil.which("datamodel-codegen"):
|
|
204
|
+
msg = "datamodel-codegen not available"
|
|
205
|
+
raise RuntimeError(msg)
|
|
240
206
|
|
|
241
207
|
if isinstance(model, dict):
|
|
242
208
|
schema = model
|
|
@@ -271,7 +237,6 @@ async def model_to_python_code(
|
|
|
271
237
|
|
|
272
238
|
try: # Generate model using datamodel-codegen
|
|
273
239
|
proc = await asyncio.create_subprocess_exec(
|
|
274
|
-
*working_prefix,
|
|
275
240
|
"datamodel-codegen",
|
|
276
241
|
*args,
|
|
277
242
|
stdout=asyncio.subprocess.PIPE,
|
schemez/schema.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import os
|
|
6
5
|
from typing import TYPE_CHECKING, Any, Literal, Self
|
|
7
6
|
|
|
8
7
|
import anyenv
|
|
@@ -15,9 +14,9 @@ if TYPE_CHECKING:
|
|
|
15
14
|
|
|
16
15
|
from llmling_agent.agent.agent import AgentType
|
|
17
16
|
from llmling_agent.models.content import BaseContent
|
|
17
|
+
from upath.types import JoinablePathLike
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
StrPath = str | os.PathLike[str]
|
|
21
20
|
SourceType = Literal["pdf", "image"]
|
|
22
21
|
PythonVersion = Literal["3.13", "3.14", "3.15"]
|
|
23
22
|
|
|
@@ -43,7 +42,9 @@ class Schema(BaseModel):
|
|
|
43
42
|
return merge_models(self, other)
|
|
44
43
|
|
|
45
44
|
@classmethod
|
|
46
|
-
def from_yaml(
|
|
45
|
+
def from_yaml(
|
|
46
|
+
cls, content: str, inherit_path: JoinablePathLike | None = None
|
|
47
|
+
) -> Self:
|
|
47
48
|
"""Create from YAML string."""
|
|
48
49
|
import yamling
|
|
49
50
|
|
|
@@ -233,7 +234,7 @@ class Schema(BaseModel):
|
|
|
233
234
|
)
|
|
234
235
|
return yamling.dump_yaml(text)
|
|
235
236
|
|
|
236
|
-
def save(self, path:
|
|
237
|
+
def save(self, path: JoinablePathLike, overwrite: bool = False) -> None:
|
|
237
238
|
"""Save configuration to a YAML file.
|
|
238
239
|
|
|
239
240
|
Args:
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
|
-
import logging
|
|
7
6
|
from pathlib import Path
|
|
8
7
|
import time
|
|
9
8
|
from typing import TYPE_CHECKING, Any
|
|
@@ -12,6 +11,7 @@ from pydantic import BaseModel
|
|
|
12
11
|
from pydantic_core import from_json
|
|
13
12
|
from upath import UPath
|
|
14
13
|
|
|
14
|
+
from schemez import log
|
|
15
15
|
from schemez.functionschema import FunctionSchema
|
|
16
16
|
from schemez.tool_executor.helpers import clean_generated_code, generate_input_model
|
|
17
17
|
|
|
@@ -20,11 +20,12 @@ if TYPE_CHECKING:
|
|
|
20
20
|
from collections.abc import Callable, Sequence
|
|
21
21
|
|
|
22
22
|
from fastapi import FastAPI
|
|
23
|
+
from upath.types import JoinablePathLike
|
|
23
24
|
|
|
24
25
|
from schemez.tool_executor.types import ToolHandler
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
logger =
|
|
28
|
+
logger = log.get_logger(__name__)
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
class HttpToolExecutor:
|
|
@@ -32,7 +33,7 @@ class HttpToolExecutor:
|
|
|
32
33
|
|
|
33
34
|
def __init__(
|
|
34
35
|
self,
|
|
35
|
-
schemas: Sequence[dict[str, Any] |
|
|
36
|
+
schemas: Sequence[dict[str, Any] | UPath],
|
|
36
37
|
handler: ToolHandler,
|
|
37
38
|
base_url: str = "http://localhost:8000",
|
|
38
39
|
):
|
|
@@ -61,7 +62,7 @@ class HttpToolExecutor:
|
|
|
61
62
|
match schema:
|
|
62
63
|
case dict():
|
|
63
64
|
loaded_schemas.append(schema)
|
|
64
|
-
case str() | Path():
|
|
65
|
+
case str() | Path() | UPath():
|
|
65
66
|
text = UPath(schema).read_text("utf-8")
|
|
66
67
|
loaded_schemas.append(from_json(text))
|
|
67
68
|
case _:
|
|
@@ -264,7 +265,7 @@ from datetime import datetime
|
|
|
264
265
|
uvicorn.run(app, host=host, port=port)
|
|
265
266
|
return None
|
|
266
267
|
|
|
267
|
-
async def save_to_files(self, output_dir:
|
|
268
|
+
async def save_to_files(self, output_dir: JoinablePathLike) -> dict[str, UPath]:
|
|
268
269
|
"""Save generated code to files.
|
|
269
270
|
|
|
270
271
|
Args:
|
|
@@ -273,7 +274,7 @@ from datetime import datetime
|
|
|
273
274
|
Returns:
|
|
274
275
|
Dictionary mapping file types to paths
|
|
275
276
|
"""
|
|
276
|
-
output_dir =
|
|
277
|
+
output_dir = UPath(output_dir)
|
|
277
278
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
278
279
|
|
|
279
280
|
saved_files = {}
|
schemez/tool_executor/helpers.py
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import logging
|
|
6
5
|
import time
|
|
7
6
|
|
|
7
|
+
from schemez import log
|
|
8
8
|
from schemez.helpers import model_to_python_code
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
logger =
|
|
11
|
+
logger = log.get_logger(__name__)
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
async def generate_input_model(schema_dict: dict) -> tuple[str, str]:
|
|
@@ -5,21 +5,21 @@ schemez/convert.py,sha256=3sOxOgDaFzV7uiOUSM6_Sy0YlafIlZRSevs5y2vT1Kw,4403
|
|
|
5
5
|
schemez/create_type.py,sha256=wrdqdzXtfxZfsgp9IroldoYGTJs_Rdli8TiscqhV2bI,11647
|
|
6
6
|
schemez/docstrings.py,sha256=kmd660wcomXzKac0SSNYxPRNbVCUovrpmE9jwnVRS6c,4115
|
|
7
7
|
schemez/executable.py,sha256=YM4WcmRyJ9CpzKpNgS0A-Ri0Jd7mAzfHmoaXONI-mIs,7134
|
|
8
|
-
schemez/functionschema.py,sha256=
|
|
9
|
-
schemez/helpers.py,sha256=
|
|
8
|
+
schemez/functionschema.py,sha256=D5nJIOQYwfOwuNSHLIoqNZtYkA1Y0DIFH18qMI6--ik,26141
|
|
9
|
+
schemez/helpers.py,sha256=YFx7UKYDI_sn5sVGAzzl5rcB26iBvLatvZlEFsQM5rc,7874
|
|
10
10
|
schemez/log.py,sha256=i0SDbIfWmuC_nfJdQOYAdUYaR0TBk3Mhu-K3M-lnAM4,364
|
|
11
11
|
schemez/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
schemez/pydantic_types.py,sha256=8vgSl8i2z9n0fB-8AJj-D3TBByEWE5IxItBxQ0XwXFI,1640
|
|
13
|
-
schemez/schema.py,sha256=
|
|
13
|
+
schemez/schema.py,sha256=Qt4INzB22jj-Uu61T-QI-USpNKMEeATdp98zE0Q8pL8,9592
|
|
14
14
|
schemez/schema_generators.py,sha256=Gze7S7dQkTsl_1ckeHLXPxx4jQo7RB6hHQM-5fpAsrA,6973
|
|
15
15
|
schemez/schemadef/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
schemez/schemadef/schemadef.py,sha256=FtD7TOnYxiuYOIfadRHKkkbZn98mWFb0_lKfPsPR-hI,14393
|
|
17
17
|
schemez/tool_executor/__init__.py,sha256=7wLjhA1NGekTMsiIfWLAv6J7qYhWDlanH9DKU4v1c6c,263
|
|
18
|
-
schemez/tool_executor/executor.py,sha256
|
|
19
|
-
schemez/tool_executor/helpers.py,sha256=
|
|
18
|
+
schemez/tool_executor/executor.py,sha256=-uSPfkE5JrpUQWbmD0QdEpAXVBsWiRmCWCcFvDWqtus,10486
|
|
19
|
+
schemez/tool_executor/helpers.py,sha256=zxfI9tUkUx8Dy9fNP89-2kqfV8eZwQ3re2Gmd-oekb0,1476
|
|
20
20
|
schemez/tool_executor/types.py,sha256=l2DxUIEHP9bjLnEaXZ6X428cSviicTDJsc3wfSNqKxg,675
|
|
21
21
|
schemez/typedefs.py,sha256=3OAUQ1nin9nlsOcTPAO5xrsOqVUfwsH_7_cexQYREus,6091
|
|
22
|
-
schemez-1.2.
|
|
23
|
-
schemez-1.2.
|
|
24
|
-
schemez-1.2.
|
|
25
|
-
schemez-1.2.
|
|
22
|
+
schemez-1.2.4.dist-info/licenses/LICENSE,sha256=AteGCH9r177TxxrOFEiOARrastASsf7yW6MQxlAHdwA,1078
|
|
23
|
+
schemez-1.2.4.dist-info/WHEEL,sha256=ELhySV62sOro8I5wRaLaF3TWxhBpkcDkdZUdAYLy_Hk,78
|
|
24
|
+
schemez-1.2.4.dist-info/METADATA,sha256=ycelBanzLf1RK3HpheIamKERJ8lcEMdxmxmecfKotzk,11616
|
|
25
|
+
schemez-1.2.4.dist-info/RECORD,,
|
|
File without changes
|