Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
hoonman authored Jan 13, 2025
2 parents 4e5f49c + 33e4085 commit b92ec0e
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.59.3"
".": "1.59.6"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 69
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-02200a58ed631064b6419711da99fefd6e97bdbbeb577a80a1a6e0c8dbcb18f5.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-b5b0e2c794b012919701c3fd43286af10fa25d33ceb8a881bec2636028f446e0.yml
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
# Changelog

## 1.59.6 (2025-01-09)

Full Changelog: [v1.59.5...v1.59.6](https://github.com/openai/openai-python/compare/v1.59.5...v1.59.6)

### Bug Fixes

* correctly handle deserialising `cls` fields ([#2002](https://github.com/openai/openai-python/issues/2002)) ([089c820](https://github.com/openai/openai-python/commit/089c820c8a5d20e9db6a171f0a4f11b481fe8465))


### Chores

* **internal:** spec update ([#2000](https://github.com/openai/openai-python/issues/2000)) ([36548f8](https://github.com/openai/openai-python/commit/36548f871763fdd7b5ce44903d186bc916331549))

## 1.59.5 (2025-01-08)

Full Changelog: [v1.59.4...v1.59.5](https://github.com/openai/openai-python/compare/v1.59.4...v1.59.5)

### Bug Fixes

* **client:** only call .close() when needed ([#1992](https://github.com/openai/openai-python/issues/1992)) ([bdfd699](https://github.com/openai/openai-python/commit/bdfd699b99522e83f7610b5f98e36fe43ddf8338))


### Documentation

* fix typos ([#1995](https://github.com/openai/openai-python/issues/1995)) ([be694a0](https://github.com/openai/openai-python/commit/be694a097d6cf2668f08ecf94c882773b2ee1f84))
* fix typos ([#1996](https://github.com/openai/openai-python/issues/1996)) ([714aed9](https://github.com/openai/openai-python/commit/714aed9d7eb74a19f6e502fb6d4fe83399f82851))
* more typo fixes ([#1998](https://github.com/openai/openai-python/issues/1998)) ([7bd92f0](https://github.com/openai/openai-python/commit/7bd92f06a75f11f6afc2d1223d2426e186cc74cb))
* **readme:** moved period to inside parentheses ([#1980](https://github.com/openai/openai-python/issues/1980)) ([e7fae94](https://github.com/openai/openai-python/commit/e7fae948f2ba8db23461e4374308417570196847))

## 1.59.4 (2025-01-07)

Full Changelog: [v1.59.3...v1.59.4](https://github.com/openai/openai-python/compare/v1.59.3...v1.59.4)

### Chores

* add missing isclass check ([#1988](https://github.com/openai/openai-python/issues/1988)) ([61d9072](https://github.com/openai/openai-python/commit/61d9072fbace58d64910ec7378c3686ac555972e))
* add missing isclass check for structured outputs ([bcbf013](https://github.com/openai/openai-python/commit/bcbf013e8d825b8b5f88172313dfb6e0313ca34c))
* **internal:** bump httpx dependency ([#1990](https://github.com/openai/openai-python/issues/1990)) ([288c2c3](https://github.com/openai/openai-python/commit/288c2c30dc405cbaa89924f9243442300e95e100))


### Documentation

* **realtime:** fix event reference link ([9b6885d](https://github.com/openai/openai-python/commit/9b6885d50f8d65ba5009642046727d291e0f14fa))

## 1.59.3 (2025-01-03)

Full Changelog: [v1.59.2...v1.59.3](https://github.com/openai/openai-python/compare/v1.59.2...v1.59.3)
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ The Realtime API enables you to build low-latency, multi-modal conversational ex

Under the hood the SDK uses the [`websockets`](https://websockets.readthedocs.io/en/stable/) library to manage connections.

The Realtime API works through a combination of client-sent events and server-sent events. Clients can send events to do things like update session configuration or send text and audio inputs. Server events confirm when audio responses have completed, or when a text response from the model has been received. A full event reference can be found [here](platform.openai.com/docs/api-reference/realtime-client-events) and a guide can be found [here](https://platform.openai.com/docs/guides/realtime).
The Realtime API works through a combination of client-sent events and server-sent events. Clients can send events to do things like update session configuration or send text and audio inputs. Server events confirm when audio responses have completed, or when a text response from the model has been received. A full event reference can be found [here](https://platform.openai.com/docs/api-reference/realtime-client-events) and a guide can be found [here](https://platform.openai.com/docs/guides/realtime).

Basic text based example:

Expand Down Expand Up @@ -469,7 +469,7 @@ except openai.APIStatusError as e:
print(e.response)
```

Error codes are as followed:
Error codes are as follows:

| Status Code | Error Type |
| ----------- | -------------------------- |
Expand Down Expand Up @@ -611,7 +611,7 @@ completion = response.parse() # get the object that `chat.completions.create()`
print(completion)
```

These methods return an [`LegacyAPIResponse`](https://github.com/openai/openai-python/tree/main/src/openai/_legacy_response.py) object. This is a legacy class as we're changing it slightly in the next major version.
These methods return a [`LegacyAPIResponse`](https://github.com/openai/openai-python/tree/main/src/openai/_legacy_response.py) object. This is a legacy class as we're changing it slightly in the next major version.

For the sync client this will mostly be the same with the exception
of `content` & `text` will be methods instead of properties. In the
Expand Down Expand Up @@ -655,8 +655,7 @@ If you need to access undocumented endpoints, params, or response properties, th
#### Undocumented endpoints

To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
http verbs. Options on the client will be respected (such as retries) will be respected when making this
request.
http verbs. Options on the client will be respected (such as retries) when making this request.

```py
import httpx
Expand Down Expand Up @@ -800,7 +799,7 @@ openai <TAB>
This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:

1. Changes that only affect static types, without breaking runtime behavior.
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals)_.
2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
3. Changes that we do not expect to impact the vast majority of users in practice.

We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "openai"
version = "1.59.3"
version = "1.59.6"
description = "The official Python library for the openai API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down Expand Up @@ -67,8 +67,7 @@ dev-dependencies = [
"types-tqdm > 4",
"types-pyaudio > 0",
"trio >=0.22.2",
"nest_asyncio==1.6.0"

"nest_asyncio==1.6.0",
]

[tool.rye.scripts]
Expand Down
5 changes: 2 additions & 3 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.25.2
httpx==0.28.1
# via openai
# via respx
idna==3.4
Expand Down Expand Up @@ -137,7 +137,7 @@ pytz==2023.3.post1
requests==2.31.0
# via azure-core
# via msal
respx==0.20.2
respx==0.22.0
rich==13.7.1
# via inline-snapshot
ruff==0.6.9
Expand All @@ -149,7 +149,6 @@ six==1.16.0
# via python-dateutil
sniffio==1.3.0
# via anyio
# via httpx
# via openai
# via trio
sortedcontainers==2.4.0
Expand Down
3 changes: 1 addition & 2 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ h11==0.14.0
# via httpcore
httpcore==1.0.2
# via httpx
httpx==0.25.2
httpx==0.28.1
# via openai
idna==3.4
# via anyio
Expand All @@ -52,7 +52,6 @@ six==1.16.0
# via python-dateutil
sniffio==1.3.0
# via anyio
# via httpx
# via openai
tqdm==4.66.5
# via openai
Expand Down
6 changes: 6 additions & 0 deletions src/openai/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ def __init__(self, **kwargs: Any) -> None:

class SyncHttpxClientWrapper(DefaultHttpxClient):
def __del__(self) -> None:
if self.is_closed:
return

try:
self.close()
except Exception:
Expand Down Expand Up @@ -1351,6 +1354,9 @@ def __init__(self, **kwargs: Any) -> None:

class AsyncHttpxClientWrapper(DefaultAsyncHttpxClient):
def __del__(self) -> None:
if self.is_closed:
return

try:
# TODO(someday): support non asyncio runtimes here
asyncio.get_running_loop().create_task(self.aclose())
Expand Down
14 changes: 9 additions & 5 deletions src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ def __str__(self) -> str:
@classmethod
@override
def construct( # pyright: ignore[reportIncompatibleMethodOverride]
cls: Type[ModelT],
__cls: Type[ModelT],
_fields_set: set[str] | None = None,
**values: object,
) -> ModelT:
m = cls.__new__(cls)
m = __cls.__new__(__cls)
fields_values: dict[str, object] = {}

config = get_model_config(cls)
config = get_model_config(__cls)
populate_by_name = (
config.allow_population_by_field_name
if isinstance(config, _ConfigProtocol)
Expand All @@ -221,7 +221,7 @@ def construct( # pyright: ignore[reportIncompatibleMethodOverride]
if _fields_set is None:
_fields_set = set()

model_fields = get_model_fields(cls)
model_fields = get_model_fields(__cls)
for name, field in model_fields.items():
key = field.alias
if key is None or (key not in values and populate_by_name):
Expand Down Expand Up @@ -513,7 +513,11 @@ def construct_type(*, value: object, type_: object) -> object:
_, items_type = get_args(type_) # Dict[_, items_type]
return {key: construct_type(value=item, type_=items_type) for key, item in value.items()}

if not is_literal_type(type_) and (issubclass(origin, BaseModel) or issubclass(origin, GenericModel)):
if (
not is_literal_type(type_)
and inspect.isclass(origin)
and (issubclass(origin, BaseModel) or issubclass(origin, GenericModel))
):
if is_list(value):
return [cast(Any, type_).construct(**entry) if is_mapping(entry) else entry for entry in value]

Expand Down
2 changes: 1 addition & 1 deletion src/openai/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

__title__ = "openai"
__version__ = "1.59.3" # x-release-please-version
__version__ = "1.59.6" # x-release-please-version
2 changes: 2 additions & 0 deletions src/openai/lib/_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def resolve_ref(*, root: dict[str, object], ref: str) -> object:


def is_basemodel_type(typ: type) -> TypeGuard[type[pydantic.BaseModel]]:
if not inspect.isclass(typ):
return False
return issubclass(typ, pydantic.BaseModel)


Expand Down
10 changes: 10 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,3 +844,13 @@ class Model(BaseModel):
assert m.alias == "foo"
assert isinstance(m.union, str)
assert m.union == "bar"


@pytest.mark.skipif(not PYDANTIC_V2, reason="TypeAliasType is not supported in Pydantic v1")
def test_field_named_cls() -> None:
class Model(BaseModel):
cls: str

m = construct_type(value={"cls": "foo"}, type_=Model)
assert isinstance(m, Model)
assert isinstance(m.cls, str)

0 comments on commit b92ec0e

Please sign in to comment.