Commit dbc6023
authored
Build streamed OpenAI events before serializing them (#1586)
* Fall back to model_dump_json for OpenAI payload serialization
OpenAI response and stream event types whose pydantic serializer is a
lazily-built MockValSer cannot be serialized by the generic any-schema
serializer, raising PydanticSerializationError (e.g. when streaming via
WorkflowStreamClient). The model's own model_dump_json() handles them.
Fixes #1585
* Dispatch pydantic models to their own serializer
OpenAI's BaseModel sets defer_build=True, so a model's serializer is a
MockValSer placeholder until pydantic's lazy build runs. The generic any-schema
serializer reaches for that placeholder directly without triggering the build
and raises PydanticSerializationError. Route pydantic models through their own
model_dump_json (which triggers the build) by type instead of catching the
error; non-model values continue through the generic serializer unchanged.
* Build streamed events at the source instead of in the converter
Force the deferred pydantic build on each streamed event before it is published
or returned, so it serializes regardless of build state. This also covers the
activity's list return value, which the payload converter serializes generically
and cannot build on its own. Drop the now-redundant to_payload override.1 parent 8d66724 commit dbc6023
1 file changed
Lines changed: 3 additions & 0 deletions
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
396 | 399 | | |
397 | 400 | | |
398 | 401 | | |
| |||
0 commit comments