-
Notifications
You must be signed in to change notification settings - Fork 5.1k
fix(responses): handle null output in parse_response #3586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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": | ||
| response = event.response | ||
| if not response.output and snapshot.output: | ||
| # Some backends send `response.completed` with a null/empty `output` | ||
| # even though prior `response.output_item.added` / delta events already | ||
| # populated it on the snapshot; prefer the accumulated snapshot in that case. | ||
| response = response.model_copy(update={"output": snapshot.output}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this null-output path is reached under supported Pydantic 1.x ( Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the stream includes the normal Useful? React with 👍 / 👎. |
||
| self._completed_response = parse_response( | ||
| text_format=self._text_format, | ||
| response=event.response, | ||
| response=response, | ||
| input_tools=self._input_tools, | ||
| ) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using
responses.stream()against a backend that sendsresponse.completed.response.output = nullafter priorresponse.output_item.added/ text-delta events, this fallback makesparse_response()treat the completed response as having no output.ResponseStreamStatehas already accumulated those items in its snapshot, soget_final_response().outputandoutput_textbecome empty even though the stream delivered content; the null-completion path should parse the accumulated snapshot rather than unconditionally replacing it with[].Useful? React with 👍 / 👎.