Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/openai/lib/_parsing/_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def parse_response(
) -> ParsedResponse[TextFormatT]:
output_list: List[ParsedResponseOutputItem[TextFormatT]] = []

for output in response.output:
for output in (response.output or []):
if output.type == "message":
content_list: List[ParsedContent[TextFormatT]] = []
for item in output.content:
Expand Down
8 changes: 7 additions & 1 deletion src/openai/lib/streaming/responses/_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,15 @@ def accumulate_event(self, event: RawResponseStreamEvent) -> ParsedResponseSnaps
if output.type == "function_call":
output.arguments += event.delta
elif event.type == "response.completed":
completed_response = event.response
if completed_response.output is None and snapshot.output:
completed_response = construct_type_unchecked(
type_=type(event.response),
value={**event.response.to_dict(), "output": [item.to_dict() for item in snapshot.output]},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid finalizing from partial snapshots

When response.completed has output: null, this serializes snapshot.output as if it were the final output, but the snapshot is only partially reconstructed: accumulate_event() folds in added items, content parts, text deltas, and function-call argument deltas, while other finalizing updates such as response.output_item.done (which carries the completed item/status) and custom-tool/code-interpreter/reasoning/annotation done or delta events are just passed through. In those streams, get_final_response() can now return stale or incomplete items, such as messages still marked in_progress or tool-call fields missing their final values, instead of the completed response.

Useful? React with 👍 / 👎.

)
self._completed_response = parse_response(
text_format=self._text_format,
response=event.response,
response=completed_response,
input_tools=self._input_tools,
)

Expand Down