Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 1.3.0 #808

Merged
merged 10 commits into from
Nov 15, 2023
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
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.2.4"
".": "1.3.0"
}
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -483,13 +484,13 @@ 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/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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/openai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/openai/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
"""
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.

__title__ = "openai"
__version__ = "1.2.4" # x-release-please-version
__version__ = "1.3.0" # x-release-please-version
4 changes: 2 additions & 2 deletions src/openai/cli/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pydantic

from ._utils import Colours, organization_info
from ._utils import Colors, organization_info
from .._exceptions import APIError, OpenAIError


Expand All @@ -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))
2 changes: 1 addition & 1 deletion src/openai/cli/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .._models import BaseModel


class Colours:
class Colors:
HEADER = "\033[95m"
OKBLUE = "\033[94m"
OKGREEN = "\033[92m"
Expand Down
8 changes: 8 additions & 0 deletions src/openai/resources/chat/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/openai/types/chat/completion_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions src/openai/types/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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",
[
Expand Down Expand Up @@ -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",
[
Expand Down
17 changes: 16 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)