Skip to content

Commit 243e62f

Browse files
authored
Merge branch 'main' into fix/beta-expose-vector-stores
2 parents 1af19b0 + a3315d9 commit 243e62f

File tree

59 files changed

+646
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+646
-242
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.0"
2+
".": "1.98.0"
33
}

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 111
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-670ea0d2cc44f52a87dd3cadea45632953283e0636ba30788fdbdb22a232ccac.yml
3-
openapi_spec_hash: d8b7d38911fead545adf3e4297956410
4-
config_hash: 5525bda35e48ea6387c6175c4d1651fa
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-721e6ccaa72205ee14c71f8163129920464fb814b95d3df9567a9476bbd9b7fb.yml
3+
openapi_spec_hash: 2115413a21df8b5bf9e4552a74df4312
4+
config_hash: 9606bb315a193bfd8da0459040143242

.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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# Changelog
22

3+
## 1.98.0 (2025-07-30)
4+
5+
Full Changelog: [v1.97.2...v1.98.0](https://github.com/openai/openai-python/compare/v1.97.2...v1.98.0)
6+
7+
### Features
8+
9+
* **api:** manual updates ([88a8036](https://github.com/openai/openai-python/commit/88a8036c5ea186f36c57029ef4501a0833596f56))
10+
11+
## 1.97.2 (2025-07-30)
12+
13+
Full Changelog: [v1.97.1...v1.97.2](https://github.com/openai/openai-python/compare/v1.97.1...v1.97.2)
14+
15+
### Chores
16+
17+
* **client:** refactor streaming slightly to better future proof it ([71c0c74](https://github.com/openai/openai-python/commit/71c0c747132221b798e419bc5a37baf67173d34e))
18+
* **project:** add settings file for vscode ([29c22c9](https://github.com/openai/openai-python/commit/29c22c90fd229983355089f95d0bba9de15efedb))
19+
20+
## 1.97.1 (2025-07-22)
21+
22+
Full Changelog: [v1.97.0...v1.97.1](https://github.com/openai/openai-python/compare/v1.97.0...v1.97.1)
23+
24+
### Bug Fixes
25+
26+
* **parsing:** ignore empty metadata ([58c359f](https://github.com/openai/openai-python/commit/58c359ff67fd6103268e4405600fd58844b6f27b))
27+
* **parsing:** parse extra field types ([d524b7e](https://github.com/openai/openai-python/commit/d524b7e201418ccc9b5c2206da06d1be011808e5))
28+
29+
30+
### Chores
31+
32+
* **api:** event shapes more accurate ([f3a9a92](https://github.com/openai/openai-python/commit/f3a9a9229280ecb7e0b2779dd44290df6d9824ef))
33+
334
## 1.97.0 (2025-07-16)
435

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

api.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,6 @@ from openai.types.responses import (
791791
ResponseOutputTextAnnotationAddedEvent,
792792
ResponsePrompt,
793793
ResponseQueuedEvent,
794-
ResponseReasoningDeltaEvent,
795-
ResponseReasoningDoneEvent,
796794
ResponseReasoningItem,
797795
ResponseReasoningSummaryDeltaEvent,
798796
ResponseReasoningSummaryDoneEvent,

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.0"
3+
version = "1.98.0"
44
description = "The official Python library for the openai API"
55
dynamic = ["readme"]
66
license = "Apache-2.0"

src/openai/_models.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,18 @@ def construct( # pyright: ignore[reportIncompatibleMethodOverride]
233233
else:
234234
fields_values[name] = field_get_default(field)
235235

236+
extra_field_type = _get_extra_fields_type(__cls)
237+
236238
_extra = {}
237239
for key, value in values.items():
238240
if key not in model_fields:
241+
parsed = construct_type(value=value, type_=extra_field_type) if extra_field_type is not None else value
242+
239243
if PYDANTIC_V2:
240-
_extra[key] = value
244+
_extra[key] = parsed
241245
else:
242246
_fields_set.add(key)
243-
fields_values[key] = value
247+
fields_values[key] = parsed
244248

245249
object.__setattr__(m, "__dict__", fields_values)
246250

@@ -395,6 +399,23 @@ def _construct_field(value: object, field: FieldInfo, key: str) -> object:
395399
return construct_type(value=value, type_=type_, metadata=getattr(field, "metadata", None))
396400

397401

402+
def _get_extra_fields_type(cls: type[pydantic.BaseModel]) -> type | None:
403+
if not PYDANTIC_V2:
404+
# TODO
405+
return None
406+
407+
schema = cls.__pydantic_core_schema__
408+
if schema["type"] == "model":
409+
fields = schema["schema"]
410+
if fields["type"] == "model-fields":
411+
extras = fields.get("extras_schema")
412+
if extras and "cls" in extras:
413+
# mypy can't narrow the type
414+
return extras["cls"] # type: ignore[no-any-return]
415+
416+
return None
417+
418+
398419
def is_basemodel(type_: type) -> bool:
399420
"""Returns whether or not the given type is either a `BaseModel` or a union of `BaseModel`"""
400421
if is_union(type_):
@@ -464,7 +485,7 @@ def construct_type(*, value: object, type_: object, metadata: Optional[List[Any]
464485
type_ = type_.__value__ # type: ignore[unreachable]
465486

466487
# unwrap `Annotated[T, ...]` -> `T`
467-
if metadata is not None:
488+
if metadata is not None and len(metadata) > 0:
468489
meta: tuple[Any, ...] = tuple(metadata)
469490
elif is_annotated_type(type_):
470491
meta = get_args(type_)[1:]

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.0" # x-release-please-version
4+
__version__ = "1.98.0" # x-release-please-version

0 commit comments

Comments
 (0)