Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/openai/_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
def _strip_unsupported_keywords(schema: dict) -> dict:
"""Recursively remove unsupported JSON Schema keywords like `examples`."""
if not isinstance(schema, dict):
return schema
schema.pop("examples", None)
for k, v in schema.items():
schema[k] = _strip_unsupported_keywords(v)
return schema

from __future__ import annotations

Expand Down Expand Up @@ -88,6 +96,11 @@ class OpenAI(SyncAPIClient):
'http://' or 'https://' scheme. For example: 'http://example.com' becomes
'wss://example.com'
"""
if response_format.get("type") == "json_schema":
response_format["json_schema"]["schema"] = _strip_unsupported_keywords(
response_format["json_schema"]["schema"]
)


def __init__(
self,
Expand Down