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: 7 additions & 6 deletions src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
from ._constants import RAW_RESPONSE_HEADER

if TYPE_CHECKING:
from pydantic_core.core_schema import ModelField, ModelSchema, LiteralSchema, ModelFieldsSchema
from pydantic_core.core_schema import ModelField, LiteralSchema

__all__ = ["BaseModel", "GenericModel"]

Expand Down Expand Up @@ -700,18 +700,19 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,

def _extract_field_schema_pv2(model: type[BaseModel], field_name: str) -> ModelField | None:
schema = model.__pydantic_core_schema__
if schema["type"] == "definitions":
schema_type = schema["type"]
if schema_type == "definitions":
schema = schema["schema"]
schema_type = schema["type"]

if schema["type"] != "model":
if schema_type != "model":
return None

schema = cast("ModelSchema", schema)
fields_schema = schema["schema"]
if fields_schema["type"] != "model-fields":
fields_schema_type = fields_schema["type"]
if fields_schema_type != "model-fields":
return None

fields_schema = cast("ModelFieldsSchema", fields_schema)
field = fields_schema["fields"].get(field_name)
if not field:
return None
Expand Down