Skip to content

Commit 48188cc

Browse files
release: 1.97.2 (#2494)
* codegen metadata * fix(parsing): ignore empty metadata * chore(internal): refactor stream event processing to be more future proof * fixup! * fixup! * fixup! * update comment * chore(project): add settings file for vscode * flip logic around * release: 1.97.2 --------- Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com> Co-authored-by: David Meadows <[email protected]>
1 parent e6c6757 commit 48188cc

File tree

7 files changed

+29
-23
lines changed

7 files changed

+29
-23
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.prism.log
2-
.vscode
32
_dev
43

54
__pycache__

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "1.97.1"
2+
".": "1.97.2"
33
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.analysis.importFormat": "relative",
3+
}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 1.97.2 (2025-07-30)
4+
5+
Full Changelog: [v1.97.1...v1.97.2](https://github.com/openai/openai-python/compare/v1.97.1...v1.97.2)
6+
7+
### Chores
8+
9+
* **client:** refactor streaming slightly to better future proof it ([71c0c74](https://github.com/openai/openai-python/commit/71c0c747132221b798e419bc5a37baf67173d34e))
10+
* **project:** add settings file for vscode ([29c22c9](https://github.com/openai/openai-python/commit/29c22c90fd229983355089f95d0bba9de15efedb))
11+
312
## 1.97.1 (2025-07-22)
413

514
Full Changelog: [v1.97.0...v1.97.1](https://github.com/openai/openai-python/compare/v1.97.0...v1.97.1)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "openai"
3-
version = "1.97.1"
3+
version = "1.97.2"
44
description = "The official Python library for the openai API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

src/openai/_streaming.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,11 @@ def __stream__(self) -> Iterator[_T]:
5959
if sse.data.startswith("[DONE]"):
6060
break
6161

62-
if sse.event is None or (
63-
sse.event.startswith("response.") or
64-
sse.event.startswith("transcript.") or
65-
sse.event.startswith("image_edit.") or
66-
sse.event.startswith("image_generation.")
67-
):
62+
# we have to special case the Assistants `thread.` events since we won't have an "event" key in the data
63+
if sse.event and sse.event.startswith("thread."):
6864
data = sse.json()
69-
if is_mapping(data) and data.get("error"):
65+
66+
if sse.event == "error" and is_mapping(data) and data.get("error"):
7067
message = None
7168
error = data.get("error")
7269
if is_mapping(error):
@@ -80,12 +77,10 @@ def __stream__(self) -> Iterator[_T]:
8077
body=data["error"],
8178
)
8279

83-
yield process_data(data=data, cast_to=cast_to, response=response)
84-
80+
yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response)
8581
else:
8682
data = sse.json()
87-
88-
if sse.event == "error" and is_mapping(data) and data.get("error"):
83+
if is_mapping(data) and data.get("error"):
8984
message = None
9085
error = data.get("error")
9186
if is_mapping(error):
@@ -99,7 +94,7 @@ def __stream__(self) -> Iterator[_T]:
9994
body=data["error"],
10095
)
10196

102-
yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response)
97+
yield process_data(data=data, cast_to=cast_to, response=response)
10398

10499
# Ensure the entire stream is consumed
105100
for _sse in iterator:
@@ -166,9 +161,11 @@ async def __stream__(self) -> AsyncIterator[_T]:
166161
if sse.data.startswith("[DONE]"):
167162
break
168163

169-
if sse.event is None or sse.event.startswith("response.") or sse.event.startswith("transcript."):
164+
# we have to special case the Assistants `thread.` events since we won't have an "event" key in the data
165+
if sse.event and sse.event.startswith("thread."):
170166
data = sse.json()
171-
if is_mapping(data) and data.get("error"):
167+
168+
if sse.event == "error" and is_mapping(data) and data.get("error"):
172169
message = None
173170
error = data.get("error")
174171
if is_mapping(error):
@@ -182,12 +179,10 @@ async def __stream__(self) -> AsyncIterator[_T]:
182179
body=data["error"],
183180
)
184181

185-
yield process_data(data=data, cast_to=cast_to, response=response)
186-
182+
yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response)
187183
else:
188184
data = sse.json()
189-
190-
if sse.event == "error" and is_mapping(data) and data.get("error"):
185+
if is_mapping(data) and data.get("error"):
191186
message = None
192187
error = data.get("error")
193188
if is_mapping(error):
@@ -201,7 +196,7 @@ async def __stream__(self) -> AsyncIterator[_T]:
201196
body=data["error"],
202197
)
203198

204-
yield process_data(data={"data": data, "event": sse.event}, cast_to=cast_to, response=response)
199+
yield process_data(data=data, cast_to=cast_to, response=response)
205200

206201
# Ensure the entire stream is consumed
207202
async for _sse in iterator:

src/openai/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

33
__title__ = "openai"
4-
__version__ = "1.97.1" # x-release-please-version
4+
__version__ = "1.97.2" # x-release-please-version

0 commit comments

Comments
 (0)