Skip to content

Commit

Permalink
fix(pydantic v1): avoid warnings error
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Sep 23, 2024
1 parent 45315a7 commit 1e8e7d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/openai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ def model_dump(
exclude: IncEx = None,
exclude_unset: bool = False,
exclude_defaults: bool = False,
warnings: bool = True,
) -> dict[str, Any]:
if PYDANTIC_V2:
return model.model_dump(
exclude=exclude,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
warnings=warnings,
)
return cast(
"dict[str, Any]",
Expand Down
11 changes: 6 additions & 5 deletions src/openai/lib/streaming/_assistants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import httpx

from ..._utils import is_dict, is_list, consume_sync_iterator, consume_async_iterator
from ..._compat import model_dump
from ..._models import construct_type
from ..._streaming import Stream, AsyncStream
from ...types.beta import AssistantStreamEvent
Expand Down Expand Up @@ -906,11 +907,11 @@ def accumulate_run_step(
merged = accumulate_delta(
cast(
"dict[object, object]",
snapshot.model_dump(exclude_unset=True, warnings=False),
model_dump(snapshot, exclude_unset=True, warnings=False),
),
cast(
"dict[object, object]",
data.delta.model_dump(exclude_unset=True, warnings=False),
model_dump(data.delta, exclude_unset=True, warnings=False),
),
)
run_step_snapshots[snapshot.id] = cast(RunStep, construct_type(type_=RunStep, value=merged))
Expand Down Expand Up @@ -948,7 +949,7 @@ def accumulate_event(
construct_type(
# mypy doesn't allow Content for some reason
type_=cast(Any, MessageContent),
value=content_delta.model_dump(exclude_unset=True, warnings=False),
value=model_dump(content_delta, exclude_unset=True, warnings=False),
),
),
)
Expand All @@ -957,11 +958,11 @@ def accumulate_event(
merged = accumulate_delta(
cast(
"dict[object, object]",
block.model_dump(exclude_unset=True, warnings=False),
model_dump(block, exclude_unset=True, warnings=False),
),
cast(
"dict[object, object]",
content_delta.model_dump(exclude_unset=True, warnings=False),
model_dump(content_delta, exclude_unset=True, warnings=False),
),
)
current_message_snapshot.content[content_delta.index] = cast(
Expand Down

0 comments on commit 1e8e7d1

Please sign in to comment.