Skip to content

Commit 6ac8a3e

Browse files
committed
feat: expose to_strict_json_schema as public API (#2093)
Expose the internal to_strict_json_schema function as a public API so users can generate strict JSON schemas from Pydantic models without relying on private module paths. Changes: - Add to_strict_json_schema export to openai.lib.__init__ - Add to_strict_json_schema export to openai.__init__ - Add test for public API accessibility Closes #2093
1 parent 94c88b8 commit 6ac8a3e

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/openai/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
if not _t.TYPE_CHECKING:
9797
from ._utils._resources_proxy import resources as resources
9898

99-
from .lib import azure as _azure, pydantic_function_tool as pydantic_function_tool
99+
from .lib import azure as _azure, pydantic_function_tool as pydantic_function_tool, to_strict_json_schema as to_strict_json_schema
100100
from .version import VERSION as VERSION
101101
from .lib.azure import AzureOpenAI as AzureOpenAI, AsyncAzureOpenAI as AsyncAzureOpenAI
102102
from .lib._old_api import *

src/openai/lib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from ._tools import pydantic_function_tool as pydantic_function_tool
2+
from ._pydantic import to_strict_json_schema as to_strict_json_schema
23
from ._parsing import ResponseFormatT as ResponseFormatT

tests/lib/test_pydantic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
from .schema_types.query import Query
1313

1414

15+
def test_to_strict_json_schema_public_api() -> None:
16+
"""Test that to_strict_json_schema is accessible as a public API via openai.to_strict_json_schema."""
17+
assert openai.to_strict_json_schema is to_strict_json_schema
18+
19+
1520
def test_most_types() -> None:
1621
if not PYDANTIC_V1:
1722
assert openai.pydantic_function_tool(Query)["function"] == snapshot(

0 commit comments

Comments
 (0)