Skip to content

Commit

Permalink
chore(internal): options updates (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Nov 23, 2023
1 parent daf0d26 commit d2cf227
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/anthropic/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ def _request(
self._prepare_request(request)

try:
response = self._client.send(request, auth=self.custom_auth, stream=stream)
response = self._client.send(request, auth=self.custom_auth, stream=stream or options.stream or False)
log.debug(
'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
)
Expand Down Expand Up @@ -1304,7 +1304,7 @@ async def _request(
await self._prepare_request(request)

try:
response = await self._client.send(request, auth=self.custom_auth, stream=stream)
response = await self._client.send(request, auth=self.custom_auth, stream=stream or options.stream or False)
log.debug(
'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
)
Expand Down Expand Up @@ -1541,6 +1541,7 @@ def make_request_options(
idempotency_key: str | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
post_parser: PostParser | NotGiven = NOT_GIVEN,
stream: bool | None = None,
) -> RequestOptions:
"""Create a dict of type RequestOptions without keys of NotGiven values."""
options: RequestOptions = {}
Expand All @@ -1562,6 +1563,9 @@ def make_request_options(
if idempotency_key is not None:
options["idempotency_key"] = idempotency_key

if stream is not None:
options["stream"] = stream

if is_given(post_parser):
# internal
options["post_parser"] = post_parser # type: ignore
Expand Down
2 changes: 2 additions & 0 deletions src/anthropic/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ class FinalRequestOptionsInput(TypedDict, total=False):
params: Query
headers: Headers
max_retries: int
stream: bool | None
timeout: float | Timeout | None
files: HttpxRequestFiles | None
idempotency_key: str
Expand All @@ -420,6 +421,7 @@ class FinalRequestOptions(pydantic.BaseModel):
timeout: Union[float, Timeout, None, NotGiven] = NotGiven()
files: Union[HttpxRequestFiles, None] = None
idempotency_key: Union[str, None] = None
stream: Union[bool, None] = None
post_parser: Union[Callable[[Any], Any], NotGiven] = NotGiven()

# It should be noted that we cannot use `json` here as that would override
Expand Down
1 change: 1 addition & 0 deletions src/anthropic/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ async def aclose(self) -> None:
class RequestOptions(TypedDict, total=False):
headers: Headers
max_retries: int
stream: bool
timeout: float | Timeout | None
params: Query
extra_json: AnyMapping
Expand Down

0 comments on commit d2cf227

Please sign in to comment.