diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 13787787c4..907051ec7d 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.3.5" + ".": "1.3.6" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 0869b3888c..a4c324e4f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,27 @@ # Changelog +## 1.3.6 (2023-11-28) + +Full Changelog: [v1.3.5...v1.3.6](https://github.com/openai/openai-python/compare/v1.3.5...v1.3.6) + +### Bug Fixes + +* **client:** add support for streaming binary responses ([#866](https://github.com/openai/openai-python/issues/866)) ([2470d25](https://github.com/openai/openai-python/commit/2470d251b751e92e8950bc9e3026965e9925ac1c)) + + +### Chores + +* **deps:** bump mypy to v1.7.1 ([#891](https://github.com/openai/openai-python/issues/891)) ([11fcb2a](https://github.com/openai/openai-python/commit/11fcb2a3cd4205b307c13c65ad47d9e315b0084d)) +* **internal:** send more detailed x-stainless headers ([#877](https://github.com/openai/openai-python/issues/877)) ([69e0549](https://github.com/openai/openai-python/commit/69e054947d587ff2548b101ece690d21d3c38f74)) +* revert binary streaming change ([#875](https://github.com/openai/openai-python/issues/875)) ([0a06d6a](https://github.com/openai/openai-python/commit/0a06d6a078c5ee898dae75bab4988e1a1936bfbf)) + + +### Documentation + +* **readme:** minor updates ([#894](https://github.com/openai/openai-python/issues/894)) ([5458457](https://github.com/openai/openai-python/commit/54584572df4c2a086172d812c6acb84e3405328b)) +* **readme:** update examples ([#893](https://github.com/openai/openai-python/issues/893)) ([124da87](https://github.com/openai/openai-python/commit/124da8720c44d40c083d29179f46a265761c1f4f)) +* update readme code snippet ([#890](https://github.com/openai/openai-python/issues/890)) ([c522f21](https://github.com/openai/openai-python/commit/c522f21e2a685454185d57e462e74a28499460f9)) + ## 1.3.5 (2023-11-21) Full Changelog: [v1.3.4...v1.3.5](https://github.com/openai/openai-python/compare/v1.3.4...v1.3.5) diff --git a/README.md b/README.md index 33ec6add52..83392e9585 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ stream = client.chat.completions.create( ) for chunk in stream: if chunk.choices[0].delta.content is not None: - print(chunk.choices[0].delta.content, end="") + print(part.choices[0].delta.content) ``` The async client uses the exact same interface. @@ -113,7 +113,7 @@ stream = await client.chat.completions.create( ) async for chunk in stream: if chunk.choices[0].delta.content is not None: - print(chunk.choices[0].delta.content, end="") + print(part.choices[0].delta.content) ``` ## Module-level client @@ -252,7 +252,7 @@ completion = client.chat.completions.create( "content": "Can you generate an example json object describing a fruit?", } ], - model="gpt-3.5-turbo", + model="gpt-3.5-turbo-1106", response_format={"type": "json_object"}, ) ``` diff --git a/pyproject.toml b/pyproject.toml index f17def16b6..daa765a7c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openai" -version = "1.3.5" +version = "1.3.6" description = "The official Python library for the openai API" readme = "README.md" license = "Apache-2.0" @@ -13,6 +13,7 @@ dependencies = [ "typing-extensions>=4.5, <5", "anyio>=3.5.0, <4", "distro>=1.7.0, <2", + "sniffio", "tqdm > 4" ] requires-python = ">= 3.7.1" @@ -48,7 +49,7 @@ openai = "openai.cli:main" managed = true dev-dependencies = [ "pyright==1.1.332", - "mypy==1.6.1", + "mypy==1.7.1", "black==23.3.0", "respx==0.19.2", "pytest==7.1.1", diff --git a/requirements-dev.lock b/requirements-dev.lock index 0747babdc5..683454d678 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -16,10 +16,10 @@ azure-identity==1.15.0 black==23.3.0 certifi==2023.7.22 cffi==1.16.0 -charset-normalizer==3.3.1 +charset-normalizer==3.3.2 click==8.1.7 colorlog==6.7.0 -cryptography==41.0.5 +cryptography==41.0.7 dirty-equals==0.6.0 distlib==0.3.7 distro==1.8.0 @@ -31,15 +31,15 @@ httpx==0.23.0 idna==3.4 iniconfig==2.0.0 isort==5.10.1 -msal==1.24.1 +msal==1.25.0 msal-extensions==1.0.0 -mypy==1.6.1 +mypy==1.7.1 mypy-extensions==1.0.0 nodeenv==1.8.0 nox==2023.4.22 -numpy==1.26.1 +numpy==1.26.2 packaging==23.2 -pandas==2.1.1 +pandas==2.1.3 pandas-stubs==2.1.1.230928 pathspec==0.11.2 platformdirs==3.11.0 @@ -68,7 +68,7 @@ types-pytz==2023.3.1.1 types-tqdm==4.66.0.2 typing-extensions==4.8.0 tzdata==2023.3 -urllib3==2.0.7 +urllib3==2.1.0 virtualenv==20.24.5 # The following packages are considered to be unsafe in a requirements file: setuptools==68.2.2 diff --git a/src/openai/_client.py b/src/openai/_client.py index aa00073281..202162070b 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -20,7 +20,7 @@ ProxiesTypes, RequestOptions, ) -from ._utils import is_given, is_mapping +from ._utils import is_given, is_mapping, get_async_library from ._version import __version__ from ._streaming import Stream as Stream from ._streaming import AsyncStream as AsyncStream @@ -147,6 +147,7 @@ def auth_headers(self) -> dict[str, str]: def default_headers(self) -> dict[str, str | Omit]: return { **super().default_headers, + "X-Stainless-Async": "false", "OpenAI-Organization": self.organization if self.organization is not None else Omit(), **self._custom_headers, } @@ -356,6 +357,7 @@ def auth_headers(self) -> dict[str, str]: def default_headers(self) -> dict[str, str | Omit]: return { **super().default_headers, + "X-Stainless-Async": f"async:{get_async_library()}", "OpenAI-Organization": self.organization if self.organization is not None else Omit(), **self._custom_headers, } diff --git a/src/openai/_utils/__init__.py b/src/openai/_utils/__init__.py index d3397212de..400ca9b828 100644 --- a/src/openai/_utils/__init__.py +++ b/src/openai/_utils/__init__.py @@ -25,6 +25,7 @@ from ._utils import deepcopy_minimal as deepcopy_minimal from ._utils import extract_type_arg as extract_type_arg from ._utils import is_required_type as is_required_type +from ._utils import get_async_library as get_async_library from ._utils import is_annotated_type as is_annotated_type from ._utils import maybe_coerce_float as maybe_coerce_float from ._utils import get_required_header as get_required_header diff --git a/src/openai/_utils/_utils.py b/src/openai/_utils/_utils.py index 4b51dcb2e8..d2bfc91a70 100644 --- a/src/openai/_utils/_utils.py +++ b/src/openai/_utils/_utils.py @@ -18,6 +18,8 @@ from pathlib import Path from typing_extensions import Required, Annotated, TypeGuard, get_args, get_origin +import sniffio + from .._types import Headers, NotGiven, FileTypes, NotGivenOr, HeadersLike from .._compat import is_union as _is_union from .._compat import parse_date as parse_date @@ -406,3 +408,10 @@ def get_required_header(headers: HeadersLike, header: str) -> str: return value raise ValueError(f"Could not find {header} header") + + +def get_async_library() -> str: + try: + return sniffio.current_async_library() + except Exception: + return "false" diff --git a/src/openai/_version.py b/src/openai/_version.py index 1ef6479491..bf8fdd1b4f 100644 --- a/src/openai/_version.py +++ b/src/openai/_version.py @@ -1,4 +1,4 @@ # File generated from our OpenAPI spec by Stainless. __title__ = "openai" -__version__ = "1.3.5" # x-release-please-version +__version__ = "1.3.6" # x-release-please-version