Skip to content

Commit 49f6aa8

Browse files
committed
Added JSON deref for APITools. Version bump to 2.2.1.
1 parent dd7a25a commit 49f6aa8

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

poetry.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "rigging"
3-
version = "2.2.0"
3+
version = "2.2.1"
44
description = "LLM Interaction Framework"
55
authors = ["Nick Landers <monoxgas@gmail.com>"]
66
license = "MIT"
@@ -22,6 +22,9 @@ colorama = "^0.4.6"
2222
boto3 = "^1.35.0"
2323
boto3-stubs = { extras = ["s3"], version = "^1.35.0" }
2424
logfire-api = "^3.1.1"
25+
jsonpath-ng = "^1.7.0"
26+
ruamel-yaml = "^0.18.10"
27+
jsonref = "^1.1.0"
2528

2629
vllm = { version = "^0.5.0", optional = true }
2730
transformers = { version = "^4.41.0", optional = true }
@@ -32,8 +35,6 @@ click = { version = "^8.1.7", optional = true }
3235
httpx = { version = "^0.27.0", optional = true }
3336
aiodocker = { version = "^0.22.2", optional = true }
3437
websockets = { version = "^13.0", optional = true }
35-
jsonpath-ng = "^1.7.0"
36-
ruamel-yaml = "^0.18.10"
3738

3839
[tool.poetry.extras]
3940
tracing = ["logfire"]

rigging/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from rigging.tool import ApiTool, Tool
1919
from rigging.util import await_
2020

21-
__version__ = "2.2.0"
21+
__version__ = "2.2.1"
2222

2323
__all__ = [
2424
"get_generator",

rigging/model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pydantic_xml import attr as attr
2222
from pydantic_xml import element as element
2323
from pydantic_xml import wrapped as wrapped
24+
from pydantic_xml.model import XmlEntityInfo
2425
from pydantic_xml.typedefs import EntityLocation, NsMap
2526

2627
from rigging.error import MissingModelError
@@ -131,6 +132,11 @@ def is_simple(cls) -> bool:
131132
if len(field_values) != 1:
132133
return False
133134

135+
# If the field is a pydantic-xml wrapper like element()
136+
# or attr(), we'll assume the user knows what they're doing
137+
if isinstance(field_values[0], XmlEntityInfo):
138+
return False
139+
134140
annotation = field_values[0].annotation
135141
if t.get_origin(annotation) == t.Annotated:
136142
annotation = t.get_args(annotation)[0]

rigging/tool/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pydantic import BaseModel, TypeAdapter, field_validator
1414

1515
from rigging.tracing import tracer
16+
from rigging.util import deref_json
1617

1718
if t.TYPE_CHECKING:
1819
from rigging.message import Message
@@ -145,7 +146,7 @@ def schema(self) -> dict[str, t.Any]:
145146

146147
schema["properties"][name]["description"] = annotation_args[1]
147148

148-
return schema
149+
return deref_json(schema, is_json_schema=True)
149150

150151
@cached_property
151152
def definition(self) -> ToolDefinition:

rigging/util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import typing as t
99
from threading import Thread
1010

11+
import jsonref # type: ignore [import-untyped]
1112
from pydantic import alias_generators
1213

1314
R = t.TypeVar("R")
@@ -66,6 +67,18 @@ def await_(*coros: t.Coroutine[t.Any, t.Any, R]) -> R | list[R]: # type: ignore
6667
return results
6768

6869

70+
# JSON
71+
72+
73+
def deref_json(obj: dict[str, t.Any], *, is_json_schema: bool = False) -> dict[str, t.Any]:
74+
return jsonref.replace_refs( # type: ignore [no-any-return]
75+
obj,
76+
jsonschema=is_json_schema,
77+
proxies=False,
78+
lazy_load=False,
79+
)
80+
81+
6982
# XML Formatting
7083

7184

0 commit comments

Comments
 (0)