Skip to content

Commit

Permalink
fix(bedrock): correct auth implementation (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Apr 17, 2024
1 parent 7312e0a commit 2f456f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/anthropic/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
is_list as is_list,
is_given as is_given,
is_tuple as is_tuple,
lru_cache as lru_cache,
is_mapping as is_mapping,
is_tuple_t as is_tuple_t,
parse_date as parse_date,
Expand Down
8 changes: 8 additions & 0 deletions src/anthropic/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,11 @@ def get_async_library() -> str:
return sniffio.current_async_library()
except Exception:
return "false"


def lru_cache(*, maxsize: int | None = 128) -> Callable[[CallableT], CallableT]:
"""A version of functools.lru_cache that retains the type signature
for the wrapped function arguments.
"""
wrapper = functools.lru_cache(maxsize=maxsize)
return cast(Any, wrapper) # type: ignore[no-any-return]
9 changes: 5 additions & 4 deletions src/anthropic/lib/bedrock/_auth.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from functools import lru_cache

import httpx

from ..._utils import lru_cache

if TYPE_CHECKING:
import boto3

Expand Down Expand Up @@ -42,9 +43,9 @@ def get_auth_headers(
from botocore.awsrequest import AWSRequest

session = _get_session(
region_name=region,
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key,
region=region,
aws_access_key=aws_access_key,
aws_secret_key=aws_secret_key,
aws_session_token=aws_session_token,
)

Expand Down

0 comments on commit 2f456f5

Please sign in to comment.