Skip to content

Commit

Permalink
fix(client): correctly apply client level timeout for messages (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Jul 29, 2024
1 parent 44bb26c commit 7770906
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
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 @@ -12,13 +12,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 ..lib.streaming import MessageStreamManager, AsyncMessageStreamManager
Expand Down Expand Up @@ -62,7 +64,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 @@ -325,7 +327,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 @@ -588,7 +590,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 @@ -851,8 +853,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 @@ -966,7 +970,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 @@ -1229,7 +1233,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 @@ -1492,7 +1496,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 @@ -1755,8 +1759,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

0 comments on commit 7770906

Please sign in to comment.