-
Notifications
You must be signed in to change notification settings - Fork 5.1k
fix: rename DEFER_PYDANTIC_BUILD to OPENAI_PYDANTIC_DEFER_BUILD #3720
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 |
|---|---|---|
|
|
@@ -86,6 +86,15 @@ def get_final_response(self) -> ParsedResponse[TextFormatT]: | |
|
|
||
| return response | ||
|
|
||
| def get_abort_reconciliation_items(self) -> List[Dict[str, Any]]: | ||
| """Returns a list of synthetic function_call_output items for any pending tool calls. | ||
|
|
||
| This should be used if the stream is closed before it has been read to completion | ||
| to ensure that the conversation state remains consistent. | ||
| """ | ||
| return self._state.get_abort_reconciliation_items() | ||
|
|
||
|
|
||
| def until_done(self) -> Self: | ||
| """Blocks until the stream has been consumed.""" | ||
| consume_sync_iterator(self) | ||
|
|
@@ -188,6 +197,15 @@ async def get_final_response(self) -> ParsedResponse[TextFormatT]: | |
|
|
||
| return response | ||
|
|
||
| def get_abort_reconciliation_items(self) -> List[Dict[str, Any]]: | ||
| """Returns a list of synthetic function_call_output items for any pending tool calls. | ||
|
|
||
| This should be used if the stream is closed before it has been read to completion | ||
| to ensure that the conversation state remains consistent. | ||
| """ | ||
| return self._state.get_abort_reconciliation_items() | ||
|
|
||
|
|
||
| async def until_done(self) -> Self: | ||
| """Blocks until the stream has been consumed.""" | ||
| await consume_async_iterator(self) | ||
|
|
@@ -340,6 +358,11 @@ def accumulate_event(self, event: RawResponseStreamEvent) -> ParsedResponseSnaps | |
| ) | ||
| else: | ||
| snapshot.output.append(event.item) | ||
| elif event.type == "response.output_item.done": | ||
| # The JS SDK tracks this to know which tool calls are "complete" from the model's perspective. | ||
| # In the Python SDK, ParsedResponseFunctionToolCall is updated via deltas, | ||
| # but we can use this to mark it as done if needed. | ||
| pass | ||
| elif event.type == "response.content_part.added": | ||
| output = snapshot.output[event.output_index] | ||
| if output.type == "message": | ||
|
|
@@ -369,4 +392,35 @@ def _create_initial_response(self, event: RawResponseStreamEvent) -> ParsedRespo | |
| if event.type != "response.created": | ||
| raise RuntimeError(f"Expected to have received `response.created` before `{event.type}`") | ||
|
|
||
| return construct_type_unchecked(type_=ParsedResponseSnapshot, value=event.response.to_dict()) | ||
| snapshot = construct_type_unchecked(type_=ParsedResponseSnapshot, value=event.response.to_dict()) | ||
| if snapshot.output is None: | ||
| snapshot.output = [] | ||
| return snapshot | ||
|
|
||
|
|
||
| def get_abort_reconciliation_items(self) -> List[Dict[str, Any]]: | ||
| """Returns a list of synthetic function_call_output items for any pending tool calls. | ||
|
|
||
| This is used to reconcile the conversation state if the stream is aborted | ||
| after the model has generated a tool call but before it was completed. | ||
| """ | ||
| snapshot = self.__current_snapshot | ||
| if not snapshot: | ||
| return [] | ||
|
|
||
| items: List[Dict[str, Any]] = [] | ||
| for output in snapshot.output: | ||
| if output.type == "function_call": | ||
|
Comment on lines
+412
to
+413
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 a streamed response contains both a Useful? React with 👍 / 👎. |
||
| # We consider it "pending" if we haven't received a corresponding result yet. | ||
| # In the Responses API, results are submitted in a separate turn or turn-part. | ||
| # If we are in the middle of a stream that generated a function_call, | ||
| # and the stream is aborted, we should mark it as incomplete. | ||
| items.append({ | ||
| "type": "function_call_output", | ||
| "call_id": output.call_id, | ||
| "name": output.name, | ||
| "status": "incomplete", | ||
| "output": "aborted" | ||
| }) | ||
| return items | ||
|
|
||
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.
This environment-variable rename also adds a public
ResponseStreammethod plus substantial reconciliation state machinery that is unrelated to the stated fix and has no focused synchronous or asynchronous tests. BecauseResponseStreamis re-exported fromopenai.lib.streaming.responses, merging this commit would silently expand the supported SDK API with unvalidated semantics; move these_responses.pychanges to the dedicated feature change instead.AGENTS.md reference: AGENTS.md:L5-L8
Useful? React with 👍 / 👎.