From 3b92cdfa5490b50a72811bec2f6e54e070847961 Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Mon, 13 Nov 2023 11:19:50 -0700 Subject: [PATCH 01/10] docs(readme): fix broken azure_ad notebook link (#781) The notebook link in the main README pointed an old directory. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e8bf6ecec..f3698a9ff4 100644 --- a/README.md +++ b/README.md @@ -489,7 +489,7 @@ In addition to the options provided in the base `OpenAI` client, the following o - `azure_ad_token` - `azure_ad_token_provider` -An example of using the client with Azure Active Directory can be found [here](https://github.com/openai/openai-python/blob/v1/examples/azure_ad.py). +An example of using the client with Azure Active Directory can be found [here](https://github.com/openai/openai-python/blob/main/examples/azure_ad.py). ## Versioning From 7c3b48fa93875e7afc81843c60853cb2a29bc3ef Mon Sep 17 00:00:00 2001 From: nikkie Date: Tue, 14 Nov 2023 03:54:56 +0900 Subject: [PATCH 02/10] Fix typo in docstring of _types.NotGiven (#794) --- src/openai/_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openai/_types.py b/src/openai/_types.py index 0d05be9493..9e962a1078 100644 --- a/src/openai/_types.py +++ b/src/openai/_types.py @@ -279,8 +279,8 @@ class NotGiven: ```py def get(timeout: Union[int, NotGiven, None] = NotGiven()) -> Response: ... - get(timout=1) # 1s timeout - get(timout=None) # No timeout + get(timeout=1) # 1s timeout + get(timeout=None) # No timeout get() # Default timeout behavior, which may not be statically known at the method definition. ``` """ From cbef7030c7b21a0c766fe83c62657cea1cd8d31c Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:15:18 +0000 Subject: [PATCH 03/10] chore: fix typo in docs and add request header for function calls (#807) --- src/openai/cli/_errors.py | 4 ++-- src/openai/cli/_utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/openai/cli/_errors.py b/src/openai/cli/_errors.py index ac2a3780d0..2bf06070d6 100644 --- a/src/openai/cli/_errors.py +++ b/src/openai/cli/_errors.py @@ -4,7 +4,7 @@ import pydantic -from ._utils import Colours, organization_info +from ._utils import Colors, organization_info from .._exceptions import APIError, OpenAIError @@ -20,4 +20,4 @@ def display_error(err: CLIError | APIError | pydantic.ValidationError) -> None: if isinstance(err, SilentCLIError): return - sys.stderr.write("{}{}Error:{} {}\n".format(organization_info(), Colours.FAIL, Colours.ENDC, err)) + sys.stderr.write("{}{}Error:{} {}\n".format(organization_info(), Colors.FAIL, Colors.ENDC, err)) diff --git a/src/openai/cli/_utils.py b/src/openai/cli/_utils.py index 027ab08de3..673eed613c 100644 --- a/src/openai/cli/_utils.py +++ b/src/openai/cli/_utils.py @@ -9,7 +9,7 @@ from .._models import BaseModel -class Colours: +class Colors: HEADER = "\033[95m" OKBLUE = "\033[94m" OKGREEN = "\033[92m" From 0acc07dd8281ba881f91689b8a5e4254e8743fbc Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 13 Nov 2023 19:54:29 +0000 Subject: [PATCH 04/10] chore(internal): fix devcontainer interpeter path (#810) --- .devcontainer/devcontainer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b9da964dc1..bbeb30b148 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,6 +17,7 @@ "settings": { "terminal.integrated.shell.linux": "/bin/bash", "python.pythonPath": ".venv/bin/python", + "python.defaultInterpreterPath": ".venv/bin/python", "python.typeChecking": "basic", "terminal.integrated.env.linux": { "PATH": "/home/vscode/.rye/shims:${env:PATH}" From 0bc211fd46f4fcc1f7687bdfdce26894b679cb4f Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:44:11 +0000 Subject: [PATCH 05/10] fix(breaking!): correct broken type names in moderation categories (#811) Migration: - `self_minus_harm_intent` -> `self_harm_intent` - `self_minus_harm_instructions` -> `self_harm_instructions` - `self_minus_harm` -> `self_harm` --- src/openai/types/moderation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openai/types/moderation.py b/src/openai/types/moderation.py index bf586fc24a..3602a46985 100644 --- a/src/openai/types/moderation.py +++ b/src/openai/types/moderation.py @@ -35,20 +35,20 @@ class Categories(BaseModel): orientation, disability status, or caste. """ - self_minus_harm: bool = FieldInfo(alias="self-harm") + self_harm: bool = FieldInfo(alias="self-harm") """ Content that promotes, encourages, or depicts acts of self-harm, such as suicide, cutting, and eating disorders. """ - self_minus_harm_instructions: bool = FieldInfo(alias="self-harm/instructions") + self_harm_instructions: bool = FieldInfo(alias="self-harm/instructions") """ Content that encourages performing acts of self-harm, such as suicide, cutting, and eating disorders, or that gives instructions or advice on how to commit such acts. """ - self_minus_harm_intent: bool = FieldInfo(alias="self-harm/intent") + self_harm_intent: bool = FieldInfo(alias="self-harm/intent") """ Content where the speaker expresses that they are engaging or intend to engage in acts of self-harm, such as suicide, cutting, and eating disorders. @@ -84,13 +84,13 @@ class CategoryScores(BaseModel): hate_threatening: float = FieldInfo(alias="hate/threatening") """The score for the category 'hate/threatening'.""" - self_minus_harm: float = FieldInfo(alias="self-harm") + self_harm: float = FieldInfo(alias="self-harm") """The score for the category 'self-harm'.""" - self_minus_harm_instructions: float = FieldInfo(alias="self-harm/instructions") + self_harm_instructions: float = FieldInfo(alias="self-harm/instructions") """The score for the category 'self-harm/instructions'.""" - self_minus_harm_intent: float = FieldInfo(alias="self-harm/intent") + self_harm_intent: float = FieldInfo(alias="self-harm/intent") """The score for the category 'self-harm/intent'.""" sexual: float From 9bb3c4ed88c890db2605a793aa39fffa1d84e8ef Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Tue, 14 Nov 2023 03:48:14 +0000 Subject: [PATCH 06/10] feat(api): add gpt-3.5-turbo-1106 (#813) --- src/openai/resources/chat/completions.py | 8 ++++++++ src/openai/types/chat/completion_create_params.py | 1 + 2 files changed, 9 insertions(+) diff --git a/src/openai/resources/chat/completions.py b/src/openai/resources/chat/completions.py index ff36424442..d0657b2f73 100644 --- a/src/openai/resources/chat/completions.py +++ b/src/openai/resources/chat/completions.py @@ -51,6 +51,7 @@ def create( "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", @@ -221,6 +222,7 @@ def create( "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", @@ -391,6 +393,7 @@ def create( "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", @@ -561,6 +564,7 @@ def create( "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", @@ -648,6 +652,7 @@ async def create( "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", @@ -818,6 +823,7 @@ async def create( "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", @@ -988,6 +994,7 @@ async def create( "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", @@ -1158,6 +1165,7 @@ async def create( "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", diff --git a/src/openai/types/chat/completion_create_params.py b/src/openai/types/chat/completion_create_params.py index 51c864588b..69fe250eca 100644 --- a/src/openai/types/chat/completion_create_params.py +++ b/src/openai/types/chat/completion_create_params.py @@ -44,6 +44,7 @@ class CompletionCreateParamsBase(TypedDict, total=False): "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", + "gpt-3.5-turbo-1106", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", From bd8e32a380218d0c9ff43643ccc1a25b3c35120d Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Tue, 14 Nov 2023 04:00:24 +0000 Subject: [PATCH 07/10] docs: add azure env vars (#814) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f3698a9ff4..e7e65828b8 100644 --- a/README.md +++ b/README.md @@ -483,10 +483,10 @@ print(completion.model_dump_json(indent=2)) In addition to the options provided in the base `OpenAI` client, the following options are provided: -- `azure_endpoint` +- `azure_endpoint` (or the `AZURE_OPENAI_ENDPOINT` environment variable) - `azure_deployment` -- `api_version` -- `azure_ad_token` +- `api_version` (or the `OPENAI_API_VERSION` environment variable) +- `azure_ad_token` (or the `AZURE_OPENAI_AD_TOKEN` environment variable) - `azure_ad_token_provider` An example of using the client with Azure Active Directory can be found [here](https://github.com/openai/openai-python/blob/main/examples/azure_ad.py). From 8407a27e848ae611eb087c8d10632447d7c55498 Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Tue, 14 Nov 2023 19:03:55 +0900 Subject: [PATCH 08/10] docs: fix code comment typo (#790) specifc -> specific --- src/openai/_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openai/_models.py b/src/openai/_models.py index ebaef99454..6d5aad5963 100644 --- a/src/openai/_models.py +++ b/src/openai/_models.py @@ -149,7 +149,7 @@ def construct( if not PYDANTIC_V2: # we define aliases for some of the new pydantic v2 methods so # that we can just document these methods without having to specify - # a specifc pydantic version as some users may not know which + # a specific pydantic version as some users may not know which # pydantic version they are currently using @override From ca5fdc6ca006a3550cc5eeea70dd3d96b9ba305a Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 15 Nov 2023 16:54:17 +0000 Subject: [PATCH 09/10] feat(client): support reading the base url from an env variable (#829) --- README.md | 1 + src/openai/_client.py | 4 ++++ tests/test_client.py | 12 ++++++++++++ tests/utils.py | 17 ++++++++++++++++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7e65828b8..82eeb57ccb 100644 --- a/README.md +++ b/README.md @@ -437,6 +437,7 @@ import httpx from openai import OpenAI client = OpenAI( + # Or use the `OPENAI_BASE_URL` env var base_url="http://my.test.server.example.com:8083", http_client=httpx.Client( proxies="http://my.test.proxy.example.com", diff --git a/src/openai/_client.py b/src/openai/_client.py index 7820d5f96d..6664dc4233 100644 --- a/src/openai/_client.py +++ b/src/openai/_client.py @@ -99,6 +99,8 @@ def __init__( organization = os.environ.get("OPENAI_ORG_ID") self.organization = organization + if base_url is None: + base_url = os.environ.get("OPENAI_BASE_URL") if base_url is None: base_url = f"https://api.openai.com/v1" @@ -307,6 +309,8 @@ def __init__( organization = os.environ.get("OPENAI_ORG_ID") self.organization = organization + if base_url is None: + base_url = os.environ.get("OPENAI_BASE_URL") if base_url is None: base_url = f"https://api.openai.com/v1" diff --git a/tests/test_client.py b/tests/test_client.py index e3daa4d2b1..e295d193e8 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -26,6 +26,8 @@ make_request_options, ) +from .utils import update_env + base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") api_key = "My API Key" @@ -399,6 +401,11 @@ class Model2(BaseModel): assert isinstance(response, Model1) assert response.foo == 1 + def test_base_url_env(self) -> None: + with update_env(OPENAI_BASE_URL="http://localhost:5000/from/env"): + client = OpenAI(api_key=api_key, _strict_response_validation=True) + assert client.base_url == "http://localhost:5000/from/env/" + @pytest.mark.parametrize( "client", [ @@ -932,6 +939,11 @@ class Model2(BaseModel): assert isinstance(response, Model1) assert response.foo == 1 + def test_base_url_env(self) -> None: + with update_env(OPENAI_BASE_URL="http://localhost:5000/from/env"): + client = AsyncOpenAI(api_key=api_key, _strict_response_validation=True) + assert client.base_url == "http://localhost:5000/from/env/" + @pytest.mark.parametrize( "client", [ diff --git a/tests/utils.py b/tests/utils.py index 3cccab223a..b513794017 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,7 +1,9 @@ from __future__ import annotations +import os import traceback -from typing import Any, TypeVar, cast +import contextlib +from typing import Any, TypeVar, Iterator, cast from datetime import date, datetime from typing_extensions import Literal, get_args, get_origin, assert_type @@ -103,3 +105,16 @@ def _assert_list_type(type_: type[object], value: object) -> None: inner_type = get_args(type_)[0] for entry in value: assert_type(inner_type, entry) # type: ignore + + +@contextlib.contextmanager +def update_env(**new_env: str) -> Iterator[None]: + old = os.environ.copy() + + try: + os.environ.update(new_env) + + yield None + finally: + os.environ.clear() + os.environ.update(old) From 32e0f1852ab2f143674398eed546c76c80d53aaa Mon Sep 17 00:00:00 2001 From: Stainless Bot <107565488+stainless-bot@users.noreply.github.com> Date: Wed, 15 Nov 2023 16:55:00 +0000 Subject: [PATCH 10/10] release: 1.3.0 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 27 +++++++++++++++++++++++++++ pyproject.toml | 2 +- src/openai/_version.py | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 862a05b695..2a8f4ffddf 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.2.4" + ".": "1.3.0" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e1e8a331f9..fceac1bb0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 1.3.0 (2023-11-15) + +Full Changelog: [v1.2.4...v1.3.0](https://github.com/openai/openai-python/compare/v1.2.4...v1.3.0) + +### Features + +* **api:** add gpt-3.5-turbo-1106 ([#813](https://github.com/openai/openai-python/issues/813)) ([9bb3c4e](https://github.com/openai/openai-python/commit/9bb3c4ed88c890db2605a793aa39fffa1d84e8ef)) +* **client:** support reading the base url from an env variable ([#829](https://github.com/openai/openai-python/issues/829)) ([ca5fdc6](https://github.com/openai/openai-python/commit/ca5fdc6ca006a3550cc5eeea70dd3d96b9ba305a)) + + +### Bug Fixes + +* **breaking!:** correct broken type names in moderation categories ([#811](https://github.com/openai/openai-python/issues/811)) ([0bc211f](https://github.com/openai/openai-python/commit/0bc211fd46f4fcc1f7687bdfdce26894b679cb4f)) + + +### Chores + +* fix typo in docs and add request header for function calls ([#807](https://github.com/openai/openai-python/issues/807)) ([cbef703](https://github.com/openai/openai-python/commit/cbef7030c7b21a0c766fe83c62657cea1cd8d31c)) +* **internal:** fix devcontainer interpeter path ([#810](https://github.com/openai/openai-python/issues/810)) ([0acc07d](https://github.com/openai/openai-python/commit/0acc07dd8281ba881f91689b8a5e4254e8743fbc)) + + +### Documentation + +* add azure env vars ([#814](https://github.com/openai/openai-python/issues/814)) ([bd8e32a](https://github.com/openai/openai-python/commit/bd8e32a380218d0c9ff43643ccc1a25b3c35120d)) +* fix code comment typo ([#790](https://github.com/openai/openai-python/issues/790)) ([8407a27](https://github.com/openai/openai-python/commit/8407a27e848ae611eb087c8d10632447d7c55498)) +* **readme:** fix broken azure_ad notebook link ([#781](https://github.com/openai/openai-python/issues/781)) ([3b92cdf](https://github.com/openai/openai-python/commit/3b92cdfa5490b50a72811bec2f6e54e070847961)) + ## 1.2.4 (2023-11-13) Full Changelog: [v1.2.3...v1.2.4](https://github.com/openai/openai-python/compare/v1.2.3...v1.2.4) diff --git a/pyproject.toml b/pyproject.toml index dc08634e4a..83c54f81ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "openai" -version = "1.2.4" +version = "1.3.0" description = "The official Python library for the openai API" readme = "README.md" license = "Apache-2.0" diff --git a/src/openai/_version.py b/src/openai/_version.py index f22b1aae3f..79690d85e5 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.2.4" # x-release-please-version +__version__ = "1.3.0" # x-release-please-version