Skip to content

Commit

Permalink
chore(internal): update pydantic compat helper function (#1607)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Aug 6, 2024
1 parent 2c2b74e commit e279088
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/openai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pydantic
from pydantic.fields import FieldInfo

from ._types import StrBytesIntFloat
from ._types import IncEx, StrBytesIntFloat

_T = TypeVar("_T")
_ModelT = TypeVar("_ModelT", bound=pydantic.BaseModel)
Expand Down Expand Up @@ -133,17 +133,20 @@ def model_json(model: pydantic.BaseModel, *, indent: int | None = None) -> str:
def model_dump(
model: pydantic.BaseModel,
*,
exclude: IncEx = None,
exclude_unset: bool = False,
exclude_defaults: bool = False,
) -> dict[str, Any]:
if PYDANTIC_V2:
return model.model_dump(
exclude=exclude,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
)
return cast(
"dict[str, Any]",
model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
exclude=exclude,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
),
Expand Down

0 comments on commit e279088

Please sign in to comment.