From 9c8ce4fcf4d4d10dec64c41ec3fe6b4c60e0041e Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Mon, 29 Jul 2024 19:46:01 +0000 Subject: [PATCH] fix(client): correctly apply client level timeout for messages --- src/anthropic/resources/completions.py | 22 ++++++++++++++-------- src/anthropic/resources/messages.py | 22 ++++++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/anthropic/resources/completions.py b/src/anthropic/resources/completions.py index d34a42f2..7369f485 100644 --- a/src/anthropic/resources/completions.py +++ b/src/anthropic/resources/completions.py @@ -11,6 +11,7 @@ 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, @@ -18,6 +19,7 @@ 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 @@ -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. @@ -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. @@ -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. @@ -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( @@ -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. @@ -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. @@ -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. @@ -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( diff --git a/src/anthropic/resources/messages.py b/src/anthropic/resources/messages.py index 8eb28ca1..b91d28de 100644 --- a/src/anthropic/resources/messages.py +++ b/src/anthropic/resources/messages.py @@ -11,6 +11,7 @@ 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, @@ -18,6 +19,7 @@ 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 @@ -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. @@ -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. @@ -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. @@ -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( @@ -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. @@ -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. @@ -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. @@ -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(