Skip to content

release: 1.45.0 #1702

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

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.44.1"
".": "1.45.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 68
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-85a85e0c08de456441431c0ae4e9c078cc8f9748c29430b9a9058340db6389ee.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-501122aa32adaa2abb3d4487880ab9cdf2141addce2e6c3d1bd9bb6b44c318a8.yml
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 1.45.0 (2024-09-12)

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

### Features

* **api:** add o1 models ([#1708](https://github.com/openai/openai-python/issues/1708)) ([06bd42e](https://github.com/openai/openai-python/commit/06bd42e77121a6abd4826a79ce1848812d956576))
* **errors:** include completion in LengthFinishReasonError ([#1701](https://github.com/openai/openai-python/issues/1701)) ([b0e3256](https://github.com/openai/openai-python/commit/b0e32562aff9aceafec994d3b047f7c2a9f11524))


### Bug Fixes

* **types:** correctly mark stream discriminator as optional ([#1706](https://github.com/openai/openai-python/issues/1706)) ([80f02f9](https://github.com/openai/openai-python/commit/80f02f9e5f83fac9cd2f4172b733a92ad01399b2))

## 1.44.1 (2024-09-09)

Full Changelog: [v1.44.0...v1.44.1](https://github.com/openai/openai-python/compare/v1.44.0...v1.44.1)
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.44.1"
version = "1.45.0"
description = "The official Python library for the openai API"
dynamic = ["readme"]
license = "Apache-2.0"
Expand Down
23 changes: 18 additions & 5 deletions src/openai/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

from __future__ import annotations

from typing import Any, Optional, cast
from typing import TYPE_CHECKING, Any, Optional, cast
from typing_extensions import Literal

import httpx

from ._utils import is_dict
from ._models import construct_type

if TYPE_CHECKING:
from .types.chat import ChatCompletion

__all__ = [
"BadRequestError",
"AuthenticationError",
Expand Down Expand Up @@ -130,10 +133,20 @@ class InternalServerError(APIStatusError):


class LengthFinishReasonError(OpenAIError):
def __init__(self) -> None:
super().__init__(
f"Could not parse response content as the length limit was reached",
)
completion: ChatCompletion
"""The completion that caused this error.

Note: this will *not* be a complete `ChatCompletion` object when streaming as `usage`
will not be included.
"""

def __init__(self, *, completion: ChatCompletion) -> None:
msg = "Could not parse response content as the length limit was reached"
if completion.usage:
msg += f" - {completion.usage}"

super().__init__(msg)
self.completion = completion


class ContentFilterFinishReasonError(OpenAIError):
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.44.1" # x-release-please-version
__version__ = "1.45.0" # x-release-please-version
2 changes: 1 addition & 1 deletion src/openai/lib/_parsing/_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def parse_chat_completion(
choices: list[ParsedChoice[ResponseFormatT]] = []
for choice in chat_completion.choices:
if choice.finish_reason == "length":
raise LengthFinishReasonError()
raise LengthFinishReasonError(completion=chat_completion)

if choice.finish_reason == "content_filter":
raise ContentFilterFinishReasonError()
Expand Down
4 changes: 3 additions & 1 deletion src/openai/lib/streaming/chat/_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ def _accumulate_chunk(self, chunk: ChatCompletionChunk) -> ParsedChatCompletionS

if has_parseable_input(response_format=self._response_format, input_tools=self._input_tools):
if choice.finish_reason == "length":
raise LengthFinishReasonError()
# at the time of writing, `.usage` will always be `None` but
# we include it here in case that is changed in the future
raise LengthFinishReasonError(completion=completion_snapshot)

if choice.finish_reason == "content_filter":
raise ContentFilterFinishReasonError()
Expand Down
24 changes: 12 additions & 12 deletions src/openai/resources/beta/assistants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def create(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down Expand Up @@ -250,11 +250,11 @@ def update(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down Expand Up @@ -486,11 +486,11 @@ async def create(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down Expand Up @@ -636,11 +636,11 @@ async def update(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down
8 changes: 8 additions & 0 deletions src/openai/resources/beta/chat/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def parse(
functions: Iterable[completion_create_params.Function] | NotGiven = NOT_GIVEN,
logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN,
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -121,6 +122,7 @@ class MathResponse(BaseModel):
functions=functions,
logit_bias=logit_bias,
logprobs=logprobs,
max_completion_tokens=max_completion_tokens,
max_tokens=max_tokens,
n=n,
parallel_tool_calls=parallel_tool_calls,
Expand Down Expand Up @@ -157,6 +159,7 @@ def stream(
functions: Iterable[completion_create_params.Function] | NotGiven = NOT_GIVEN,
logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN,
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -216,6 +219,7 @@ def stream(
functions=functions,
logit_bias=logit_bias,
logprobs=logprobs,
max_completion_tokens=max_completion_tokens,
max_tokens=max_tokens,
n=n,
parallel_tool_calls=parallel_tool_calls,
Expand Down Expand Up @@ -254,6 +258,7 @@ async def parse(
functions: Iterable[completion_create_params.Function] | NotGiven = NOT_GIVEN,
logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN,
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -333,6 +338,7 @@ class MathResponse(BaseModel):
functions=functions,
logit_bias=logit_bias,
logprobs=logprobs,
max_completion_tokens=max_completion_tokens,
max_tokens=max_tokens,
n=n,
parallel_tool_calls=parallel_tool_calls,
Expand Down Expand Up @@ -369,6 +375,7 @@ def stream(
functions: Iterable[completion_create_params.Function] | NotGiven = NOT_GIVEN,
logit_bias: Optional[Dict[str, int]] | NotGiven = NOT_GIVEN,
logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
max_completion_tokens: Optional[int] | NotGiven = NOT_GIVEN,
max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
n: Optional[int] | NotGiven = NOT_GIVEN,
parallel_tool_calls: bool | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -429,6 +436,7 @@ def stream(
functions=functions,
logit_bias=logit_bias,
logprobs=logprobs,
max_completion_tokens=max_completion_tokens,
max_tokens=max_tokens,
n=n,
parallel_tool_calls=parallel_tool_calls,
Expand Down
36 changes: 18 additions & 18 deletions src/openai/resources/beta/threads/runs/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ def create(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down Expand Up @@ -311,11 +311,11 @@ def create(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down Expand Up @@ -451,11 +451,11 @@ def create(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down Expand Up @@ -1529,11 +1529,11 @@ async def create(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down Expand Up @@ -1673,11 +1673,11 @@ async def create(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down Expand Up @@ -1813,11 +1813,11 @@ async def create(
and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
Outputs which guarantees the model will match your supplied JSON schema. Learn
more in the
Outputs which ensures the model will match your supplied JSON schema. Learn more
in the
[Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the
Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
message the model generates is valid JSON.

**Important:** when using JSON mode, you **must** also instruct the model to
Expand Down
Loading