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

fix(client): correctly apply client level timeout for messages #615

Merged
merged 1 commit into from
Jul 29, 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
22 changes: 14 additions & 8 deletions src/anthropic/resources/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
from ..types import completion_create_params
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._utils import (
is_given,
required_args,
maybe_transform,
async_maybe_transform,
)
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .._constants import DEFAULT_TIMEOUT
from .._streaming import Stream, AsyncStream
from .._base_client import make_request_options
from ..types.completion import Completion
Expand Down Expand Up @@ -53,7 +55,7 @@ def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Completion:
"""[Legacy] Create a Text Completion.

Expand Down Expand Up @@ -157,7 +159,7 @@ def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Stream[Completion]:
"""[Legacy] Create a Text Completion.

Expand Down Expand Up @@ -261,7 +263,7 @@ def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Completion | Stream[Completion]:
"""[Legacy] Create a Text Completion.

Expand Down Expand Up @@ -365,8 +367,10 @@ def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Completion | Stream[Completion]:
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = 600
return self._post(
"/v1/complete",
body=maybe_transform(
Expand Down Expand Up @@ -419,7 +423,7 @@ async def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Completion:
"""[Legacy] Create a Text Completion.

Expand Down Expand Up @@ -523,7 +527,7 @@ async def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> AsyncStream[Completion]:
"""[Legacy] Create a Text Completion.

Expand Down Expand Up @@ -627,7 +631,7 @@ async def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Completion | AsyncStream[Completion]:
"""[Legacy] Create a Text Completion.

Expand Down Expand Up @@ -731,8 +735,10 @@ async def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Completion | AsyncStream[Completion]:
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = 600
return await self._post(
"/v1/complete",
body=await async_maybe_transform(
Expand Down
22 changes: 14 additions & 8 deletions src/anthropic/resources/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
from ..types import message_create_params
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from .._utils import (
is_given,
required_args,
maybe_transform,
async_maybe_transform,
)
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .._constants import DEFAULT_TIMEOUT
from .._streaming import Stream, AsyncStream
from .._base_client import make_request_options
from ..types.message import Message
Expand Down Expand Up @@ -60,7 +62,7 @@ def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Message:
"""
Create a Message.
Expand Down Expand Up @@ -323,7 +325,7 @@ def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Stream[RawMessageStreamEvent]:
"""
Create a Message.
Expand Down Expand Up @@ -586,7 +588,7 @@ def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Message | Stream[RawMessageStreamEvent]:
"""
Create a Message.
Expand Down Expand Up @@ -849,8 +851,10 @@ def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Message | Stream[RawMessageStreamEvent]:
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = 600
return self._post(
"/v1/messages",
body=maybe_transform(
Expand Down Expand Up @@ -909,7 +913,7 @@ async def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Message:
"""
Create a Message.
Expand Down Expand Up @@ -1172,7 +1176,7 @@ async def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> AsyncStream[RawMessageStreamEvent]:
"""
Create a Message.
Expand Down Expand Up @@ -1435,7 +1439,7 @@ async def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Message | AsyncStream[RawMessageStreamEvent]:
"""
Create a Message.
Expand Down Expand Up @@ -1698,8 +1702,10 @@ async def create(
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = 600,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Message | AsyncStream[RawMessageStreamEvent]:
if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT:
timeout = 600
return await self._post(
"/v1/messages",
body=await async_maybe_transform(
Expand Down