Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/.keep +4 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__init__.py +1 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__pycache__/__init__.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__pycache__/_files.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__pycache__/_stainless_helpers.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__pycache__/foundry.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/__init__.py +1 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/__pycache__/__init__.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/__pycache__/_common.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/__pycache__/_google_auth.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/_common.py +13 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/_google_auth.py +29 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_files.py +42 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_parse/__pycache__/_response.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_parse/__pycache__/_transform.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_parse/_response.py +72 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_parse/_transform.py +171 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_stainless_helpers.py +75 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__init__.py +1 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__pycache__/__init__.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__pycache__/_auth.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__pycache__/_client.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__pycache__/_credentials.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/_auth.py +72 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/_client.py +409 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/_credentials.py +129 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__init__.py +5 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/__init__.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_auth.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_beta.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_beta_messages.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_client.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_mantle.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_stream.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_stream_decoder.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_auth.py +72 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_beta.py +102 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_beta_messages.py +93 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_client.py +458 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_mantle.py +512 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_stream.py +37 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_stream_decoder.py +64 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__init__.py +39 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/__init__.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_auth.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_cache.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_chain.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_constants.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_providers.cpython-312.pyc +0 -0
- hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_types.cpython-312.pyc +0 -0
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/.keep
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
File generated from our OpenAPI spec by Stainless.
|
| 2 |
+
|
| 3 |
+
This directory can be used to store custom files to expand the SDK.
|
| 4 |
+
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from ._files import files_from_dir as files_from_dir, async_files_from_dir as async_files_from_dir
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (274 Bytes). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__pycache__/_files.cpython-312.pyc
ADDED
|
Binary file (2.29 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__pycache__/_stainless_helpers.cpython-312.pyc
ADDED
|
Binary file (3.01 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/__pycache__/foundry.cpython-312.pyc
ADDED
|
Binary file (17.4 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from ._google_auth import google_auth as google_auth
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (251 Bytes). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/__pycache__/_common.cpython-312.pyc
ADDED
|
Binary file (966 Bytes). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/__pycache__/_google_auth.cpython-312.pyc
ADDED
|
Binary file (1.31 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/_common.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ..._exceptions import AnthropicError
|
| 2 |
+
|
| 3 |
+
INSTRUCTIONS = """
|
| 4 |
+
|
| 5 |
+
Anthropic error: missing required dependency `{library}`.
|
| 6 |
+
|
| 7 |
+
$ pip install anthropic[{extra}]
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class MissingDependencyError(AnthropicError):
|
| 12 |
+
def __init__(self, *, library: str, extra: str) -> None:
|
| 13 |
+
super().__init__(INSTRUCTIONS.format(library=library, extra=extra))
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_extras/_google_auth.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING, Any
|
| 4 |
+
from typing_extensions import ClassVar, override
|
| 5 |
+
|
| 6 |
+
from ._common import MissingDependencyError
|
| 7 |
+
from ..._utils import LazyProxy
|
| 8 |
+
|
| 9 |
+
if TYPE_CHECKING:
|
| 10 |
+
import google.auth # type: ignore
|
| 11 |
+
|
| 12 |
+
google_auth = google.auth
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class GoogleAuthProxy(LazyProxy[Any]):
|
| 16 |
+
should_cache: ClassVar[bool] = True
|
| 17 |
+
|
| 18 |
+
@override
|
| 19 |
+
def __load__(self) -> Any:
|
| 20 |
+
try:
|
| 21 |
+
import google.auth # type: ignore
|
| 22 |
+
except ImportError as err:
|
| 23 |
+
raise MissingDependencyError(extra="vertex", library="google-auth") from err
|
| 24 |
+
|
| 25 |
+
return google.auth
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
if not TYPE_CHECKING:
|
| 29 |
+
google_auth = GoogleAuthProxy()
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_files.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
import anyio
|
| 7 |
+
|
| 8 |
+
from .._types import FileTypes
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def files_from_dir(directory: str | os.PathLike[str]) -> list[FileTypes]:
|
| 12 |
+
path = Path(directory)
|
| 13 |
+
|
| 14 |
+
files: list[FileTypes] = []
|
| 15 |
+
_collect_files(path, path.parent, files)
|
| 16 |
+
return files
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _collect_files(directory: Path, relative_to: Path, files: list[FileTypes]) -> None:
|
| 20 |
+
for path in directory.iterdir():
|
| 21 |
+
if path.is_dir():
|
| 22 |
+
_collect_files(path, relative_to, files)
|
| 23 |
+
continue
|
| 24 |
+
|
| 25 |
+
files.append((path.relative_to(relative_to).as_posix(), path.read_bytes()))
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
async def async_files_from_dir(directory: str | os.PathLike[str]) -> list[FileTypes]:
|
| 29 |
+
path = anyio.Path(directory)
|
| 30 |
+
|
| 31 |
+
files: list[FileTypes] = []
|
| 32 |
+
await _async_collect_files(path, path.parent, files)
|
| 33 |
+
return files
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
async def _async_collect_files(directory: anyio.Path, relative_to: anyio.Path, files: list[FileTypes]) -> None:
|
| 37 |
+
async for path in directory.iterdir():
|
| 38 |
+
if await path.is_dir():
|
| 39 |
+
await _async_collect_files(path, relative_to, files)
|
| 40 |
+
continue
|
| 41 |
+
|
| 42 |
+
files.append((path.relative_to(relative_to).as_posix(), await path.read_bytes()))
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_parse/__pycache__/_response.cpython-312.pyc
ADDED
|
Binary file (2.91 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_parse/__pycache__/_transform.cpython-312.pyc
ADDED
|
Binary file (5.57 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_parse/_response.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing_extensions import TypeVar
|
| 4 |
+
|
| 5 |
+
from ..._types import NotGiven
|
| 6 |
+
from ..._models import TypeAdapter, construct_type_unchecked
|
| 7 |
+
from ..._utils._utils import is_given
|
| 8 |
+
from ...types.message import Message
|
| 9 |
+
from ...types.parsed_message import ParsedMessage, ParsedTextBlock, ParsedContentBlock
|
| 10 |
+
from ...types.beta.beta_message import BetaMessage
|
| 11 |
+
from ...types.beta.parsed_beta_message import ParsedBetaMessage, ParsedBetaTextBlock, ParsedBetaContentBlock
|
| 12 |
+
|
| 13 |
+
ResponseFormatT = TypeVar("ResponseFormatT", default=None)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def parse_text(text: str, output_format: ResponseFormatT | NotGiven) -> ResponseFormatT | None:
|
| 17 |
+
if is_given(output_format):
|
| 18 |
+
adapted_type: TypeAdapter[ResponseFormatT] = TypeAdapter(output_format)
|
| 19 |
+
return adapted_type.validate_json(text)
|
| 20 |
+
return None
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def parse_beta_response(
|
| 24 |
+
*,
|
| 25 |
+
output_format: ResponseFormatT | NotGiven,
|
| 26 |
+
response: BetaMessage,
|
| 27 |
+
) -> ParsedBetaMessage[ResponseFormatT]:
|
| 28 |
+
content_list: list[ParsedBetaContentBlock[ResponseFormatT]] = []
|
| 29 |
+
for content in response.content:
|
| 30 |
+
if content.type == "text":
|
| 31 |
+
content_list.append(
|
| 32 |
+
construct_type_unchecked(
|
| 33 |
+
type_=ParsedBetaTextBlock[ResponseFormatT],
|
| 34 |
+
value={**content.to_dict(), "parsed_output": parse_text(content.text, output_format)},
|
| 35 |
+
)
|
| 36 |
+
)
|
| 37 |
+
else:
|
| 38 |
+
content_list.append(content) # type: ignore
|
| 39 |
+
|
| 40 |
+
return construct_type_unchecked(
|
| 41 |
+
type_=ParsedBetaMessage[ResponseFormatT],
|
| 42 |
+
value={
|
| 43 |
+
**response.to_dict(),
|
| 44 |
+
"content": content_list,
|
| 45 |
+
},
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def parse_response(
|
| 50 |
+
*,
|
| 51 |
+
output_format: ResponseFormatT | NotGiven,
|
| 52 |
+
response: Message,
|
| 53 |
+
) -> ParsedMessage[ResponseFormatT]:
|
| 54 |
+
content_list: list[ParsedContentBlock[ResponseFormatT]] = []
|
| 55 |
+
for content in response.content:
|
| 56 |
+
if content.type == "text":
|
| 57 |
+
content_list.append(
|
| 58 |
+
construct_type_unchecked(
|
| 59 |
+
type_=ParsedTextBlock[ResponseFormatT],
|
| 60 |
+
value={**content.to_dict(), "parsed_output": parse_text(content.text, output_format)},
|
| 61 |
+
)
|
| 62 |
+
)
|
| 63 |
+
else:
|
| 64 |
+
content_list.append(content) # type: ignore
|
| 65 |
+
|
| 66 |
+
return construct_type_unchecked(
|
| 67 |
+
type_=ParsedMessage[ResponseFormatT],
|
| 68 |
+
value={
|
| 69 |
+
**response.to_dict(),
|
| 70 |
+
"content": content_list,
|
| 71 |
+
},
|
| 72 |
+
)
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_parse/_transform.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import inspect
|
| 4 |
+
from typing import Any, Literal, Optional, cast
|
| 5 |
+
from typing_extensions import assert_never
|
| 6 |
+
|
| 7 |
+
import pydantic
|
| 8 |
+
|
| 9 |
+
from ..._utils import is_list
|
| 10 |
+
|
| 11 |
+
SupportedTypes = Literal[
|
| 12 |
+
"object",
|
| 13 |
+
"array",
|
| 14 |
+
"string",
|
| 15 |
+
"integer",
|
| 16 |
+
"number",
|
| 17 |
+
"boolean",
|
| 18 |
+
"null",
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
SupportedStringFormats = {
|
| 22 |
+
"date-time",
|
| 23 |
+
"time",
|
| 24 |
+
"date",
|
| 25 |
+
"duration",
|
| 26 |
+
"email",
|
| 27 |
+
"hostname",
|
| 28 |
+
"uri",
|
| 29 |
+
"ipv4",
|
| 30 |
+
"ipv6",
|
| 31 |
+
"uuid",
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def get_transformed_string(
|
| 36 |
+
schema: dict[str, Any],
|
| 37 |
+
) -> dict[str, Any]:
|
| 38 |
+
"""Transforms a JSON schema of type string to ensure it conforms to the API's expectations.
|
| 39 |
+
|
| 40 |
+
Specifically, it ensures that if the schema is of type "string" and does not already
|
| 41 |
+
specify a "format", it sets the format to "text".
|
| 42 |
+
|
| 43 |
+
Args:
|
| 44 |
+
schema: The original JSON schema.
|
| 45 |
+
|
| 46 |
+
Returns:
|
| 47 |
+
The transformed JSON schema.
|
| 48 |
+
"""
|
| 49 |
+
if schema.get("type") == "string" and "format" not in schema:
|
| 50 |
+
schema["format"] = "text"
|
| 51 |
+
return schema
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def transform_schema(
|
| 55 |
+
json_schema: type[pydantic.BaseModel] | dict[str, Any],
|
| 56 |
+
) -> dict[str, Any]:
|
| 57 |
+
"""
|
| 58 |
+
Transforms a JSON schema to ensure it conforms to the API's expectations.
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
json_schema (Dict[str, Any]): The original JSON schema.
|
| 62 |
+
|
| 63 |
+
Returns:
|
| 64 |
+
The transformed JSON schema.
|
| 65 |
+
|
| 66 |
+
Examples:
|
| 67 |
+
>>> transform_schema(
|
| 68 |
+
... {
|
| 69 |
+
... "type": "integer",
|
| 70 |
+
... "minimum": 1,
|
| 71 |
+
... "maximum": 10,
|
| 72 |
+
... "description": "A number",
|
| 73 |
+
... }
|
| 74 |
+
... )
|
| 75 |
+
{'type': 'integer', 'description': 'A number\n\n{minimum: 1, maximum: 10}'}
|
| 76 |
+
"""
|
| 77 |
+
if inspect.isclass(json_schema) and issubclass(json_schema, pydantic.BaseModel): # pyright: ignore[reportUnnecessaryIsInstance]
|
| 78 |
+
json_schema = json_schema.model_json_schema()
|
| 79 |
+
|
| 80 |
+
strict_schema: dict[str, Any] = {}
|
| 81 |
+
json_schema = {**json_schema}
|
| 82 |
+
|
| 83 |
+
ref = json_schema.pop("$ref", None)
|
| 84 |
+
if ref is not None:
|
| 85 |
+
strict_schema["$ref"] = ref
|
| 86 |
+
return strict_schema
|
| 87 |
+
|
| 88 |
+
defs = json_schema.pop("$defs", None)
|
| 89 |
+
if defs is not None:
|
| 90 |
+
strict_defs: dict[str, Any] = {}
|
| 91 |
+
strict_schema["$defs"] = strict_defs
|
| 92 |
+
|
| 93 |
+
for name, schema in defs.items():
|
| 94 |
+
strict_defs[name] = transform_schema(schema)
|
| 95 |
+
|
| 96 |
+
type_: Optional[SupportedTypes] = json_schema.pop("type", None)
|
| 97 |
+
any_of = json_schema.pop("anyOf", None)
|
| 98 |
+
one_of = json_schema.pop("oneOf", None)
|
| 99 |
+
all_of = json_schema.pop("allOf", None)
|
| 100 |
+
|
| 101 |
+
if is_list(any_of):
|
| 102 |
+
strict_schema["anyOf"] = [transform_schema(cast("dict[str, Any]", variant)) for variant in any_of]
|
| 103 |
+
elif is_list(one_of):
|
| 104 |
+
strict_schema["anyOf"] = [transform_schema(cast("dict[str, Any]", variant)) for variant in one_of]
|
| 105 |
+
elif is_list(all_of):
|
| 106 |
+
strict_schema["allOf"] = [transform_schema(cast("dict[str, Any]", variant)) for variant in all_of]
|
| 107 |
+
else:
|
| 108 |
+
if type_ is None:
|
| 109 |
+
raise ValueError("Schema must have a 'type', 'anyOf', 'oneOf', or 'allOf' field.")
|
| 110 |
+
|
| 111 |
+
strict_schema["type"] = type_
|
| 112 |
+
|
| 113 |
+
enum = json_schema.pop("enum", None)
|
| 114 |
+
if is_list(enum):
|
| 115 |
+
strict_schema["enum"] = enum
|
| 116 |
+
|
| 117 |
+
description = json_schema.pop("description", None)
|
| 118 |
+
if description is not None:
|
| 119 |
+
strict_schema["description"] = description
|
| 120 |
+
|
| 121 |
+
title = json_schema.pop("title", None)
|
| 122 |
+
if title is not None:
|
| 123 |
+
strict_schema["title"] = title
|
| 124 |
+
|
| 125 |
+
if type_ == "object":
|
| 126 |
+
strict_schema["properties"] = {
|
| 127 |
+
key: transform_schema(prop_schema) for key, prop_schema in json_schema.pop("properties", {}).items()
|
| 128 |
+
}
|
| 129 |
+
json_schema.pop("additionalProperties", None)
|
| 130 |
+
strict_schema["additionalProperties"] = False
|
| 131 |
+
|
| 132 |
+
required = json_schema.pop("required", None)
|
| 133 |
+
if required is not None:
|
| 134 |
+
strict_schema["required"] = required
|
| 135 |
+
|
| 136 |
+
elif type_ == "string":
|
| 137 |
+
format = json_schema.pop("format", None)
|
| 138 |
+
if format and format in SupportedStringFormats:
|
| 139 |
+
strict_schema["format"] = format
|
| 140 |
+
elif format:
|
| 141 |
+
# add it back so its treated as an extra property and appended to the description
|
| 142 |
+
json_schema["format"] = format
|
| 143 |
+
elif type_ == "array":
|
| 144 |
+
items = json_schema.pop("items", None)
|
| 145 |
+
if items is not None:
|
| 146 |
+
strict_schema["items"] = transform_schema(items)
|
| 147 |
+
|
| 148 |
+
min_items = json_schema.pop("minItems", None)
|
| 149 |
+
if min_items is not None and min_items == 0 or min_items == 1:
|
| 150 |
+
strict_schema["minItems"] = min_items
|
| 151 |
+
elif min_items is not None:
|
| 152 |
+
# add it back so its treated as an extra property and appended to the description
|
| 153 |
+
json_schema["minItems"] = min_items
|
| 154 |
+
|
| 155 |
+
elif type_ == "boolean" or type_ == "integer" or type_ == "number" or type_ == "null" or type_ is None:
|
| 156 |
+
pass
|
| 157 |
+
else:
|
| 158 |
+
assert_never(type_)
|
| 159 |
+
|
| 160 |
+
# if there are any propes leftover then they aren't supported, so we add them to the description
|
| 161 |
+
# so that the model *might* follow them.
|
| 162 |
+
if json_schema:
|
| 163 |
+
description = strict_schema.get("description")
|
| 164 |
+
strict_schema["description"] = (
|
| 165 |
+
(description + "\n\n" if description is not None else "")
|
| 166 |
+
+ "{"
|
| 167 |
+
+ ", ".join(f"{key}: {value}" for key, value in json_schema.items())
|
| 168 |
+
+ "}"
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
return strict_schema
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/_stainless_helpers.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tracking for SDK helper usage via the x-stainless-helper header."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Any, Dict, cast
|
| 6 |
+
|
| 7 |
+
_HELPER_ATTR = "_stainless_helper"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def tag_helper(obj: Any, name: str) -> None:
|
| 11 |
+
"""Mark an object as created by a named SDK helper."""
|
| 12 |
+
try:
|
| 13 |
+
object.__setattr__(obj, _HELPER_ATTR, name)
|
| 14 |
+
except (AttributeError, TypeError):
|
| 15 |
+
pass
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def get_helper_tag(obj: object) -> str | None:
|
| 19 |
+
"""Get the helper name from an object, if any."""
|
| 20 |
+
return getattr(obj, _HELPER_ATTR, None) # type: ignore[return-value]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def collect_helpers(
|
| 24 |
+
tools: Any = None,
|
| 25 |
+
messages: Any = None,
|
| 26 |
+
) -> list[str]:
|
| 27 |
+
"""Collect deduplicated helper names from tools and messages."""
|
| 28 |
+
helpers: set[str] = set()
|
| 29 |
+
|
| 30 |
+
if tools:
|
| 31 |
+
for tool in tools:
|
| 32 |
+
tag = get_helper_tag(tool)
|
| 33 |
+
if tag is not None:
|
| 34 |
+
helpers.add(tag)
|
| 35 |
+
|
| 36 |
+
if messages:
|
| 37 |
+
for message in messages:
|
| 38 |
+
tag = get_helper_tag(message)
|
| 39 |
+
if tag is not None:
|
| 40 |
+
helpers.add(tag)
|
| 41 |
+
|
| 42 |
+
# Check content blocks within messages
|
| 43 |
+
if isinstance(message, dict):
|
| 44 |
+
blocks: Any = cast(Dict[str, Any], message).get("content")
|
| 45 |
+
else:
|
| 46 |
+
blocks = getattr(message, "content", None)
|
| 47 |
+
if isinstance(blocks, list):
|
| 48 |
+
for block in cast(list[object], blocks):
|
| 49 |
+
tag = get_helper_tag(block)
|
| 50 |
+
if tag is not None:
|
| 51 |
+
helpers.add(tag)
|
| 52 |
+
|
| 53 |
+
return list(helpers)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def stainless_helper_header(
|
| 57 |
+
tools: Any = None,
|
| 58 |
+
messages: Any = None,
|
| 59 |
+
) -> dict[str, str]:
|
| 60 |
+
"""Build x-stainless-helper header dict from tools and messages.
|
| 61 |
+
|
| 62 |
+
Returns an empty dict if no helpers are found.
|
| 63 |
+
"""
|
| 64 |
+
helpers = collect_helpers(tools, messages)
|
| 65 |
+
if not helpers:
|
| 66 |
+
return {}
|
| 67 |
+
return {"x-stainless-helper": ", ".join(helpers)}
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def stainless_helper_header_from_file(file: object) -> dict[str, str]:
|
| 71 |
+
"""Build x-stainless-helper header dict from a file object."""
|
| 72 |
+
tag = get_helper_tag(file)
|
| 73 |
+
if tag is None:
|
| 74 |
+
return {}
|
| 75 |
+
return {"x-stainless-helper": tag}
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from ._client import AnthropicAWS as AnthropicAWS, AsyncAnthropicAWS as AsyncAnthropicAWS
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (274 Bytes). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__pycache__/_auth.cpython-312.pyc
ADDED
|
Binary file (2.63 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__pycache__/_client.cpython-312.pyc
ADDED
|
Binary file (11.9 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/__pycache__/_credentials.cpython-312.pyc
ADDED
|
Binary file (4.13 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/_auth.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING
|
| 4 |
+
|
| 5 |
+
import httpx
|
| 6 |
+
|
| 7 |
+
from ..._utils import lru_cache
|
| 8 |
+
|
| 9 |
+
if TYPE_CHECKING:
|
| 10 |
+
import boto3
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@lru_cache(maxsize=512)
|
| 14 |
+
def _get_session(
|
| 15 |
+
*,
|
| 16 |
+
aws_access_key: str | None,
|
| 17 |
+
aws_secret_key: str | None,
|
| 18 |
+
aws_session_token: str | None,
|
| 19 |
+
region: str | None,
|
| 20 |
+
profile: str | None,
|
| 21 |
+
) -> boto3.Session:
|
| 22 |
+
import boto3
|
| 23 |
+
|
| 24 |
+
return boto3.Session(
|
| 25 |
+
profile_name=profile,
|
| 26 |
+
region_name=region,
|
| 27 |
+
aws_access_key_id=aws_access_key,
|
| 28 |
+
aws_secret_access_key=aws_secret_key,
|
| 29 |
+
aws_session_token=aws_session_token,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def get_auth_headers(
|
| 34 |
+
*,
|
| 35 |
+
method: str,
|
| 36 |
+
url: str,
|
| 37 |
+
headers: httpx.Headers,
|
| 38 |
+
aws_access_key: str | None,
|
| 39 |
+
aws_secret_key: str | None,
|
| 40 |
+
aws_session_token: str | None,
|
| 41 |
+
region: str | None,
|
| 42 |
+
profile: str | None,
|
| 43 |
+
data: str | None,
|
| 44 |
+
service_name: str,
|
| 45 |
+
) -> dict[str, str]:
|
| 46 |
+
from botocore.auth import SigV4Auth
|
| 47 |
+
from botocore.awsrequest import AWSRequest
|
| 48 |
+
|
| 49 |
+
session = _get_session(
|
| 50 |
+
profile=profile,
|
| 51 |
+
region=region,
|
| 52 |
+
aws_access_key=aws_access_key,
|
| 53 |
+
aws_secret_key=aws_secret_key,
|
| 54 |
+
aws_session_token=aws_session_token,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# The connection header may be stripped by a proxy somewhere, so the receiver
|
| 58 |
+
# of this message may not see this header, so we remove it from the set of headers
|
| 59 |
+
# that are signed.
|
| 60 |
+
new_headers = {k: v for k, v in dict(headers).items() if k.lower() != "connection"}
|
| 61 |
+
|
| 62 |
+
request = AWSRequest(method=method.upper(), url=url, headers=new_headers, data=data)
|
| 63 |
+
credentials = session.get_credentials()
|
| 64 |
+
if not credentials:
|
| 65 |
+
raise RuntimeError("Could not resolve AWS credentials from session")
|
| 66 |
+
|
| 67 |
+
signer = SigV4Auth(credentials, service_name, session.region_name)
|
| 68 |
+
signer.add_auth(request)
|
| 69 |
+
|
| 70 |
+
prepped = request.prepare()
|
| 71 |
+
|
| 72 |
+
return {key: value for key, value in dict(prepped.headers).items() if value is not None}
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/_client.py
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import Any, Mapping
|
| 4 |
+
from typing_extensions import Self, override
|
| 5 |
+
|
| 6 |
+
import httpx
|
| 7 |
+
|
| 8 |
+
from ..._types import NOT_GIVEN, Omit, Headers, Timeout, NotGiven
|
| 9 |
+
from ..._client import Anthropic, AsyncAnthropic
|
| 10 |
+
from ._credentials import (
|
| 11 |
+
resolve_region,
|
| 12 |
+
resolve_api_key,
|
| 13 |
+
resolve_base_url,
|
| 14 |
+
resolve_auth_mode,
|
| 15 |
+
resolve_workspace_id,
|
| 16 |
+
validate_credentials,
|
| 17 |
+
)
|
| 18 |
+
from ..._exceptions import AnthropicError
|
| 19 |
+
from ..._base_client import DEFAULT_MAX_RETRIES
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class AnthropicAWS(Anthropic):
|
| 23 |
+
aws_access_key: str | None
|
| 24 |
+
aws_secret_key: str | None
|
| 25 |
+
aws_region: str | None
|
| 26 |
+
aws_profile: str | None
|
| 27 |
+
aws_session_token: str | None
|
| 28 |
+
workspace_id: str | None
|
| 29 |
+
_use_sigv4: bool
|
| 30 |
+
_skip_auth: bool
|
| 31 |
+
|
| 32 |
+
def __init__(
|
| 33 |
+
self,
|
| 34 |
+
*,
|
| 35 |
+
api_key: str | None = None,
|
| 36 |
+
aws_access_key: str | None = None,
|
| 37 |
+
aws_secret_key: str | None = None,
|
| 38 |
+
aws_region: str | None = None,
|
| 39 |
+
aws_profile: str | None = None,
|
| 40 |
+
aws_session_token: str | None = None,
|
| 41 |
+
workspace_id: str | None = None,
|
| 42 |
+
skip_auth: bool = False,
|
| 43 |
+
base_url: str | httpx.URL | None = None,
|
| 44 |
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
| 45 |
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
| 46 |
+
default_headers: Mapping[str, str] | None = None,
|
| 47 |
+
default_query: Mapping[str, object] | None = None,
|
| 48 |
+
http_client: httpx.Client | None = None,
|
| 49 |
+
_strict_response_validation: bool = False,
|
| 50 |
+
# Passed through to parent but not used for AWS auth
|
| 51 |
+
auth_token: str | None = None,
|
| 52 |
+
webhook_key: str | None = None,
|
| 53 |
+
) -> None:
|
| 54 |
+
self._skip_auth = skip_auth
|
| 55 |
+
|
| 56 |
+
validate_credentials(aws_access_key=aws_access_key, aws_secret_key=aws_secret_key)
|
| 57 |
+
|
| 58 |
+
if skip_auth:
|
| 59 |
+
self._use_sigv4 = False
|
| 60 |
+
resolved_api_key = None
|
| 61 |
+
else:
|
| 62 |
+
self._use_sigv4 = resolve_auth_mode(
|
| 63 |
+
api_key=api_key,
|
| 64 |
+
aws_access_key=aws_access_key,
|
| 65 |
+
aws_secret_key=aws_secret_key,
|
| 66 |
+
aws_profile=aws_profile,
|
| 67 |
+
)
|
| 68 |
+
resolved_api_key = resolve_api_key(api_key=api_key, use_sigv4=self._use_sigv4)
|
| 69 |
+
|
| 70 |
+
resolved_region = resolve_region(aws_region)
|
| 71 |
+
|
| 72 |
+
if self._use_sigv4 and resolved_region is None:
|
| 73 |
+
raise AnthropicError(
|
| 74 |
+
"No AWS region was provided. Set the `aws_region` argument or the `AWS_REGION`/`AWS_DEFAULT_REGION` environment variable."
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
self.aws_access_key = aws_access_key
|
| 78 |
+
self.aws_secret_key = aws_secret_key
|
| 79 |
+
self.aws_region = resolved_region
|
| 80 |
+
self.aws_profile = aws_profile
|
| 81 |
+
self.aws_session_token = aws_session_token
|
| 82 |
+
|
| 83 |
+
if skip_auth:
|
| 84 |
+
self.workspace_id = workspace_id
|
| 85 |
+
else:
|
| 86 |
+
resolved_workspace_id = resolve_workspace_id(workspace_id)
|
| 87 |
+
if resolved_workspace_id is None:
|
| 88 |
+
raise AnthropicError(
|
| 89 |
+
"No workspace ID found. Set the `workspace_id` argument or the `ANTHROPIC_AWS_WORKSPACE_ID` environment variable."
|
| 90 |
+
)
|
| 91 |
+
self.workspace_id = resolved_workspace_id
|
| 92 |
+
|
| 93 |
+
if not skip_auth:
|
| 94 |
+
resolved_base_url = resolve_base_url(
|
| 95 |
+
str(base_url) if base_url is not None else None,
|
| 96 |
+
region=resolved_region,
|
| 97 |
+
)
|
| 98 |
+
if resolved_base_url is None:
|
| 99 |
+
raise AnthropicError(
|
| 100 |
+
"No AWS region was provided and no base_url was given. "
|
| 101 |
+
"Set the `aws_region` argument, the `AWS_REGION`/`AWS_DEFAULT_REGION` environment variable, "
|
| 102 |
+
"or provide a `base_url` directly."
|
| 103 |
+
)
|
| 104 |
+
base_url = resolved_base_url
|
| 105 |
+
|
| 106 |
+
super().__init__(
|
| 107 |
+
api_key=resolved_api_key,
|
| 108 |
+
auth_token=auth_token,
|
| 109 |
+
webhook_key=webhook_key,
|
| 110 |
+
base_url=base_url, # type: ignore[arg-type]
|
| 111 |
+
timeout=timeout,
|
| 112 |
+
max_retries=max_retries,
|
| 113 |
+
default_headers=default_headers,
|
| 114 |
+
default_query=default_query,
|
| 115 |
+
http_client=http_client,
|
| 116 |
+
_strict_response_validation=_strict_response_validation,
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
@property
|
| 120 |
+
@override
|
| 121 |
+
def default_headers(self) -> dict[str, str | Omit]:
|
| 122 |
+
headers = {**super().default_headers}
|
| 123 |
+
if self.workspace_id is not None:
|
| 124 |
+
headers["anthropic-workspace-id"] = self.workspace_id
|
| 125 |
+
return headers
|
| 126 |
+
|
| 127 |
+
@property
|
| 128 |
+
@override
|
| 129 |
+
def _api_key_auth(self) -> dict[str, str]:
|
| 130 |
+
if self._use_sigv4 or self._skip_auth:
|
| 131 |
+
return {}
|
| 132 |
+
return super()._api_key_auth
|
| 133 |
+
|
| 134 |
+
@override
|
| 135 |
+
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
|
| 136 |
+
if self._use_sigv4 or self._skip_auth:
|
| 137 |
+
return
|
| 138 |
+
super()._validate_headers(headers, custom_headers)
|
| 139 |
+
|
| 140 |
+
@override
|
| 141 |
+
def _prepare_request(self, request: httpx.Request) -> None:
|
| 142 |
+
if not self._use_sigv4:
|
| 143 |
+
return
|
| 144 |
+
|
| 145 |
+
from ._auth import get_auth_headers
|
| 146 |
+
|
| 147 |
+
data = request.read().decode()
|
| 148 |
+
|
| 149 |
+
headers = get_auth_headers(
|
| 150 |
+
method=request.method,
|
| 151 |
+
url=str(request.url),
|
| 152 |
+
headers=request.headers,
|
| 153 |
+
aws_access_key=self.aws_access_key,
|
| 154 |
+
aws_secret_key=self.aws_secret_key,
|
| 155 |
+
aws_session_token=self.aws_session_token,
|
| 156 |
+
region=self.aws_region,
|
| 157 |
+
profile=self.aws_profile,
|
| 158 |
+
data=data,
|
| 159 |
+
service_name="aws-external-anthropic",
|
| 160 |
+
)
|
| 161 |
+
request.headers.update(headers)
|
| 162 |
+
|
| 163 |
+
@override
|
| 164 |
+
def copy( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] — subclass intentionally drops `credentials`
|
| 165 |
+
self,
|
| 166 |
+
*,
|
| 167 |
+
api_key: str | None = None,
|
| 168 |
+
aws_access_key: str | None = None,
|
| 169 |
+
aws_secret_key: str | None = None,
|
| 170 |
+
aws_region: str | None = None,
|
| 171 |
+
aws_profile: str | None = None,
|
| 172 |
+
aws_session_token: str | None = None,
|
| 173 |
+
workspace_id: str | None = None,
|
| 174 |
+
skip_auth: bool | None = None,
|
| 175 |
+
auth_token: str | None = None,
|
| 176 |
+
webhook_key: str | None = None,
|
| 177 |
+
base_url: str | httpx.URL | None = None,
|
| 178 |
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
| 179 |
+
http_client: httpx.Client | None = None,
|
| 180 |
+
max_retries: int | NotGiven = NOT_GIVEN,
|
| 181 |
+
default_headers: Mapping[str, str] | None = None,
|
| 182 |
+
set_default_headers: Mapping[str, str] | None = None,
|
| 183 |
+
default_query: Mapping[str, object] | None = None,
|
| 184 |
+
set_default_query: Mapping[str, object] | None = None,
|
| 185 |
+
_extra_kwargs: Mapping[str, Any] = {},
|
| 186 |
+
) -> Self:
|
| 187 |
+
# If region is changing and no explicit base_url, let __init__ derive it
|
| 188 |
+
resolved_base_url = base_url or (None if aws_region else self.base_url)
|
| 189 |
+
|
| 190 |
+
return super().copy(
|
| 191 |
+
api_key=api_key or self.api_key,
|
| 192 |
+
auth_token=auth_token,
|
| 193 |
+
webhook_key=webhook_key,
|
| 194 |
+
base_url=resolved_base_url,
|
| 195 |
+
timeout=timeout,
|
| 196 |
+
http_client=http_client,
|
| 197 |
+
max_retries=max_retries,
|
| 198 |
+
default_headers=default_headers,
|
| 199 |
+
set_default_headers=set_default_headers,
|
| 200 |
+
default_query=default_query,
|
| 201 |
+
set_default_query=set_default_query,
|
| 202 |
+
_extra_kwargs={
|
| 203 |
+
"aws_access_key": aws_access_key or self.aws_access_key,
|
| 204 |
+
"aws_secret_key": aws_secret_key or self.aws_secret_key,
|
| 205 |
+
"aws_region": aws_region or self.aws_region,
|
| 206 |
+
"aws_profile": aws_profile or self.aws_profile,
|
| 207 |
+
"aws_session_token": aws_session_token or self.aws_session_token,
|
| 208 |
+
"workspace_id": workspace_id or self.workspace_id,
|
| 209 |
+
"skip_auth": skip_auth if skip_auth is not None else self._skip_auth,
|
| 210 |
+
**_extra_kwargs,
|
| 211 |
+
},
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
with_options = copy # type: ignore[assignment]
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
class AsyncAnthropicAWS(AsyncAnthropic):
|
| 218 |
+
aws_access_key: str | None
|
| 219 |
+
aws_secret_key: str | None
|
| 220 |
+
aws_region: str | None
|
| 221 |
+
aws_profile: str | None
|
| 222 |
+
aws_session_token: str | None
|
| 223 |
+
workspace_id: str | None
|
| 224 |
+
_use_sigv4: bool
|
| 225 |
+
_skip_auth: bool
|
| 226 |
+
|
| 227 |
+
def __init__(
|
| 228 |
+
self,
|
| 229 |
+
*,
|
| 230 |
+
api_key: str | None = None,
|
| 231 |
+
aws_access_key: str | None = None,
|
| 232 |
+
aws_secret_key: str | None = None,
|
| 233 |
+
aws_region: str | None = None,
|
| 234 |
+
aws_profile: str | None = None,
|
| 235 |
+
aws_session_token: str | None = None,
|
| 236 |
+
workspace_id: str | None = None,
|
| 237 |
+
skip_auth: bool = False,
|
| 238 |
+
base_url: str | httpx.URL | None = None,
|
| 239 |
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
| 240 |
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
| 241 |
+
default_headers: Mapping[str, str] | None = None,
|
| 242 |
+
default_query: Mapping[str, object] | None = None,
|
| 243 |
+
http_client: httpx.AsyncClient | None = None,
|
| 244 |
+
_strict_response_validation: bool = False,
|
| 245 |
+
# Accepted for compatibility with AsyncAnthropic.copy() but not used
|
| 246 |
+
auth_token: str | None = None,
|
| 247 |
+
webhook_key: str | None = None,
|
| 248 |
+
) -> None:
|
| 249 |
+
self._skip_auth = skip_auth
|
| 250 |
+
|
| 251 |
+
validate_credentials(aws_access_key=aws_access_key, aws_secret_key=aws_secret_key)
|
| 252 |
+
|
| 253 |
+
if skip_auth:
|
| 254 |
+
self._use_sigv4 = False
|
| 255 |
+
resolved_api_key = None
|
| 256 |
+
else:
|
| 257 |
+
self._use_sigv4 = resolve_auth_mode(
|
| 258 |
+
api_key=api_key,
|
| 259 |
+
aws_access_key=aws_access_key,
|
| 260 |
+
aws_secret_key=aws_secret_key,
|
| 261 |
+
aws_profile=aws_profile,
|
| 262 |
+
)
|
| 263 |
+
resolved_api_key = resolve_api_key(api_key=api_key, use_sigv4=self._use_sigv4)
|
| 264 |
+
|
| 265 |
+
resolved_region = resolve_region(aws_region)
|
| 266 |
+
|
| 267 |
+
if self._use_sigv4 and resolved_region is None:
|
| 268 |
+
raise AnthropicError(
|
| 269 |
+
"No AWS region was provided. Set the `aws_region` argument or the `AWS_REGION`/`AWS_DEFAULT_REGION` environment variable."
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
self.aws_access_key = aws_access_key
|
| 273 |
+
self.aws_secret_key = aws_secret_key
|
| 274 |
+
self.aws_region = resolved_region
|
| 275 |
+
self.aws_profile = aws_profile
|
| 276 |
+
self.aws_session_token = aws_session_token
|
| 277 |
+
|
| 278 |
+
if skip_auth:
|
| 279 |
+
self.workspace_id = workspace_id
|
| 280 |
+
else:
|
| 281 |
+
resolved_workspace_id = resolve_workspace_id(workspace_id)
|
| 282 |
+
if resolved_workspace_id is None:
|
| 283 |
+
raise AnthropicError(
|
| 284 |
+
"No workspace ID found. Set the `workspace_id` argument or the `ANTHROPIC_AWS_WORKSPACE_ID` environment variable."
|
| 285 |
+
)
|
| 286 |
+
self.workspace_id = resolved_workspace_id
|
| 287 |
+
|
| 288 |
+
if not skip_auth:
|
| 289 |
+
resolved_base_url = resolve_base_url(
|
| 290 |
+
str(base_url) if base_url is not None else None,
|
| 291 |
+
region=resolved_region,
|
| 292 |
+
)
|
| 293 |
+
if resolved_base_url is None:
|
| 294 |
+
raise AnthropicError(
|
| 295 |
+
"No AWS region was provided and no base_url was given. "
|
| 296 |
+
"Set the `aws_region` argument, the `AWS_REGION`/`AWS_DEFAULT_REGION` environment variable, "
|
| 297 |
+
"or provide a `base_url` directly."
|
| 298 |
+
)
|
| 299 |
+
base_url = resolved_base_url
|
| 300 |
+
|
| 301 |
+
super().__init__(
|
| 302 |
+
api_key=resolved_api_key,
|
| 303 |
+
auth_token=auth_token,
|
| 304 |
+
webhook_key=webhook_key,
|
| 305 |
+
base_url=base_url, # type: ignore[arg-type]
|
| 306 |
+
timeout=timeout,
|
| 307 |
+
max_retries=max_retries,
|
| 308 |
+
default_headers=default_headers,
|
| 309 |
+
default_query=default_query,
|
| 310 |
+
http_client=http_client,
|
| 311 |
+
_strict_response_validation=_strict_response_validation,
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
@property
|
| 315 |
+
@override
|
| 316 |
+
def default_headers(self) -> dict[str, str | Omit]:
|
| 317 |
+
headers = {**super().default_headers}
|
| 318 |
+
if self.workspace_id is not None:
|
| 319 |
+
headers["anthropic-workspace-id"] = self.workspace_id
|
| 320 |
+
return headers
|
| 321 |
+
|
| 322 |
+
@property
|
| 323 |
+
@override
|
| 324 |
+
def _api_key_auth(self) -> dict[str, str]:
|
| 325 |
+
if self._use_sigv4 or self._skip_auth:
|
| 326 |
+
return {}
|
| 327 |
+
return super()._api_key_auth
|
| 328 |
+
|
| 329 |
+
@override
|
| 330 |
+
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
|
| 331 |
+
if self._use_sigv4 or self._skip_auth:
|
| 332 |
+
return
|
| 333 |
+
super()._validate_headers(headers, custom_headers)
|
| 334 |
+
|
| 335 |
+
@override
|
| 336 |
+
async def _prepare_request(self, request: httpx.Request) -> None:
|
| 337 |
+
if not self._use_sigv4:
|
| 338 |
+
return
|
| 339 |
+
|
| 340 |
+
from ._auth import get_auth_headers
|
| 341 |
+
|
| 342 |
+
data = request.read().decode()
|
| 343 |
+
|
| 344 |
+
headers = get_auth_headers(
|
| 345 |
+
method=request.method,
|
| 346 |
+
url=str(request.url),
|
| 347 |
+
headers=request.headers,
|
| 348 |
+
aws_access_key=self.aws_access_key,
|
| 349 |
+
aws_secret_key=self.aws_secret_key,
|
| 350 |
+
aws_session_token=self.aws_session_token,
|
| 351 |
+
region=self.aws_region,
|
| 352 |
+
profile=self.aws_profile,
|
| 353 |
+
data=data,
|
| 354 |
+
service_name="aws-external-anthropic",
|
| 355 |
+
)
|
| 356 |
+
request.headers.update(headers)
|
| 357 |
+
|
| 358 |
+
@override
|
| 359 |
+
def copy( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] — subclass intentionally drops `credentials`
|
| 360 |
+
self,
|
| 361 |
+
*,
|
| 362 |
+
api_key: str | None = None,
|
| 363 |
+
aws_access_key: str | None = None,
|
| 364 |
+
aws_secret_key: str | None = None,
|
| 365 |
+
aws_region: str | None = None,
|
| 366 |
+
aws_profile: str | None = None,
|
| 367 |
+
aws_session_token: str | None = None,
|
| 368 |
+
workspace_id: str | None = None,
|
| 369 |
+
skip_auth: bool | None = None,
|
| 370 |
+
auth_token: str | None = None,
|
| 371 |
+
webhook_key: str | None = None,
|
| 372 |
+
base_url: str | httpx.URL | None = None,
|
| 373 |
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
| 374 |
+
http_client: httpx.AsyncClient | None = None,
|
| 375 |
+
max_retries: int | NotGiven = NOT_GIVEN,
|
| 376 |
+
default_headers: Mapping[str, str] | None = None,
|
| 377 |
+
set_default_headers: Mapping[str, str] | None = None,
|
| 378 |
+
default_query: Mapping[str, object] | None = None,
|
| 379 |
+
set_default_query: Mapping[str, object] | None = None,
|
| 380 |
+
_extra_kwargs: Mapping[str, Any] = {},
|
| 381 |
+
) -> Self:
|
| 382 |
+
# If region is changing and no explicit base_url, let __init__ derive it
|
| 383 |
+
resolved_base_url = base_url or (None if aws_region else self.base_url)
|
| 384 |
+
|
| 385 |
+
return super().copy(
|
| 386 |
+
api_key=api_key or self.api_key,
|
| 387 |
+
auth_token=auth_token,
|
| 388 |
+
webhook_key=webhook_key,
|
| 389 |
+
base_url=resolved_base_url,
|
| 390 |
+
timeout=timeout,
|
| 391 |
+
http_client=http_client,
|
| 392 |
+
max_retries=max_retries,
|
| 393 |
+
default_headers=default_headers,
|
| 394 |
+
set_default_headers=set_default_headers,
|
| 395 |
+
default_query=default_query,
|
| 396 |
+
set_default_query=set_default_query,
|
| 397 |
+
_extra_kwargs={
|
| 398 |
+
"aws_access_key": aws_access_key or self.aws_access_key,
|
| 399 |
+
"aws_secret_key": aws_secret_key or self.aws_secret_key,
|
| 400 |
+
"aws_region": aws_region or self.aws_region,
|
| 401 |
+
"aws_profile": aws_profile or self.aws_profile,
|
| 402 |
+
"aws_session_token": aws_session_token or self.aws_session_token,
|
| 403 |
+
"workspace_id": workspace_id or self.workspace_id,
|
| 404 |
+
"skip_auth": skip_auth if skip_auth is not None else self._skip_auth,
|
| 405 |
+
**_extra_kwargs,
|
| 406 |
+
},
|
| 407 |
+
)
|
| 408 |
+
|
| 409 |
+
with_options = copy # type: ignore[assignment]
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/aws/_credentials.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from typing import Sequence
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def validate_credentials(
|
| 8 |
+
*,
|
| 9 |
+
aws_access_key: str | None,
|
| 10 |
+
aws_secret_key: str | None,
|
| 11 |
+
) -> None:
|
| 12 |
+
"""Raise if only one of aws_access_key/aws_secret_key is provided."""
|
| 13 |
+
if (aws_access_key is not None) != (aws_secret_key is not None):
|
| 14 |
+
provided = "aws_access_key" if aws_access_key is not None else "aws_secret_key"
|
| 15 |
+
missing = "aws_secret_key" if aws_access_key is not None else "aws_access_key"
|
| 16 |
+
raise ValueError(
|
| 17 |
+
f"`{provided}` was provided without `{missing}`. "
|
| 18 |
+
f"Both must be provided together, or neither (to use the default credential chain)."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _read_env(*env_vars: str) -> str | None:
|
| 23 |
+
"""Return the first non-None value from the given env vars, or None."""
|
| 24 |
+
for var in env_vars:
|
| 25 |
+
value = os.environ.get(var)
|
| 26 |
+
if value is not None:
|
| 27 |
+
return value
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def resolve_auth_mode(
|
| 32 |
+
*,
|
| 33 |
+
api_key: str | None,
|
| 34 |
+
aws_access_key: str | None,
|
| 35 |
+
aws_secret_key: str | None,
|
| 36 |
+
aws_profile: str | None,
|
| 37 |
+
api_key_env_vars: Sequence[str] = ("ANTHROPIC_AWS_API_KEY",),
|
| 38 |
+
) -> bool:
|
| 39 |
+
"""Determine whether to use SigV4 auth. Returns True for SigV4, False for API key.
|
| 40 |
+
|
| 41 |
+
Auth precedence:
|
| 42 |
+
1. api_key constructor arg → API key mode
|
| 43 |
+
2. aws_access_key + aws_secret_key constructor args → SigV4
|
| 44 |
+
3. aws_profile constructor arg → SigV4
|
| 45 |
+
4. API key env var(s) → API key mode (checked in order; first match wins)
|
| 46 |
+
5. Default AWS credential chain → SigV4
|
| 47 |
+
"""
|
| 48 |
+
if api_key is not None:
|
| 49 |
+
return False
|
| 50 |
+
|
| 51 |
+
if aws_access_key is not None or aws_secret_key is not None:
|
| 52 |
+
return True
|
| 53 |
+
|
| 54 |
+
if aws_profile is not None:
|
| 55 |
+
return True
|
| 56 |
+
|
| 57 |
+
# No explicit constructor args that signal SigV4 — check env vars
|
| 58 |
+
if _read_env(*api_key_env_vars) is not None:
|
| 59 |
+
return False
|
| 60 |
+
|
| 61 |
+
# Fall back to default AWS credential chain
|
| 62 |
+
return True
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def resolve_api_key(
|
| 66 |
+
*,
|
| 67 |
+
api_key: str | None,
|
| 68 |
+
use_sigv4: bool,
|
| 69 |
+
api_key_env_vars: Sequence[str] = ("ANTHROPIC_AWS_API_KEY",),
|
| 70 |
+
) -> str | None:
|
| 71 |
+
"""Resolve the API key. Returns None if using SigV4."""
|
| 72 |
+
if api_key is not None:
|
| 73 |
+
return api_key
|
| 74 |
+
|
| 75 |
+
if not use_sigv4:
|
| 76 |
+
# Must be from env var
|
| 77 |
+
return _read_env(*api_key_env_vars)
|
| 78 |
+
|
| 79 |
+
return None
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def resolve_region(aws_region: str | None) -> str | None:
|
| 83 |
+
"""Resolve the AWS region from constructor arg or env var.
|
| 84 |
+
|
| 85 |
+
Does not silently default — returns None if no region is available.
|
| 86 |
+
"""
|
| 87 |
+
if aws_region is not None:
|
| 88 |
+
return aws_region
|
| 89 |
+
|
| 90 |
+
return os.environ.get("AWS_REGION") or os.environ.get("AWS_DEFAULT_REGION")
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def resolve_workspace_id(
|
| 94 |
+
workspace_id: str | None,
|
| 95 |
+
*,
|
| 96 |
+
workspace_id_env_vars: Sequence[str] = ("ANTHROPIC_AWS_WORKSPACE_ID",),
|
| 97 |
+
) -> str | None:
|
| 98 |
+
"""Resolve the workspace ID from constructor arg or env var(s).
|
| 99 |
+
|
| 100 |
+
Returns None if no workspace ID is available (caller should raise).
|
| 101 |
+
"""
|
| 102 |
+
if workspace_id is not None:
|
| 103 |
+
return workspace_id
|
| 104 |
+
|
| 105 |
+
return _read_env(*workspace_id_env_vars)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def resolve_base_url(
|
| 109 |
+
base_url: str | None,
|
| 110 |
+
*,
|
| 111 |
+
region: str | None,
|
| 112 |
+
base_url_env_vars: Sequence[str] = ("ANTHROPIC_AWS_BASE_URL",),
|
| 113 |
+
url_template: str = "https://aws-external-anthropic.{region}.api.aws",
|
| 114 |
+
) -> str | None:
|
| 115 |
+
"""Resolve the base URL from constructor arg, env var, or region.
|
| 116 |
+
|
| 117 |
+
Returns None if no base URL is resolvable (caller should raise).
|
| 118 |
+
"""
|
| 119 |
+
if base_url is not None:
|
| 120 |
+
return base_url
|
| 121 |
+
|
| 122 |
+
env_url = _read_env(*base_url_env_vars)
|
| 123 |
+
if env_url is not None:
|
| 124 |
+
return env_url
|
| 125 |
+
|
| 126 |
+
if region is not None:
|
| 127 |
+
return url_template.format(region=region)
|
| 128 |
+
|
| 129 |
+
return None
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ._client import AnthropicBedrock as AnthropicBedrock, AsyncAnthropicBedrock as AsyncAnthropicBedrock
|
| 2 |
+
from ._mantle import (
|
| 3 |
+
AnthropicBedrockMantle as AnthropicBedrockMantle,
|
| 4 |
+
AsyncAnthropicBedrockMantle as AsyncAnthropicBedrockMantle,
|
| 5 |
+
)
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (383 Bytes). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_auth.cpython-312.pyc
ADDED
|
Binary file (2.42 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_beta.cpython-312.pyc
ADDED
|
Binary file (5.02 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_beta_messages.cpython-312.pyc
ADDED
|
Binary file (4.19 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_client.cpython-312.pyc
ADDED
|
Binary file (16.3 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_mantle.cpython-312.pyc
ADDED
|
Binary file (17.2 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_stream.cpython-312.pyc
ADDED
|
Binary file (1.66 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/__pycache__/_stream_decoder.cpython-312.pyc
ADDED
|
Binary file (3.65 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_auth.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING
|
| 4 |
+
|
| 5 |
+
import httpx
|
| 6 |
+
|
| 7 |
+
from ..._utils import lru_cache
|
| 8 |
+
|
| 9 |
+
if TYPE_CHECKING:
|
| 10 |
+
import boto3
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@lru_cache(maxsize=512)
|
| 14 |
+
def _get_session(
|
| 15 |
+
*,
|
| 16 |
+
aws_access_key: str | None,
|
| 17 |
+
aws_secret_key: str | None,
|
| 18 |
+
aws_session_token: str | None,
|
| 19 |
+
region: str | None,
|
| 20 |
+
profile: str | None,
|
| 21 |
+
) -> boto3.Session:
|
| 22 |
+
import boto3
|
| 23 |
+
|
| 24 |
+
return boto3.Session(
|
| 25 |
+
profile_name=profile,
|
| 26 |
+
region_name=region,
|
| 27 |
+
aws_access_key_id=aws_access_key,
|
| 28 |
+
aws_secret_access_key=aws_secret_key,
|
| 29 |
+
aws_session_token=aws_session_token,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def get_auth_headers(
|
| 34 |
+
*,
|
| 35 |
+
method: str,
|
| 36 |
+
url: str,
|
| 37 |
+
headers: httpx.Headers,
|
| 38 |
+
aws_access_key: str | None,
|
| 39 |
+
aws_secret_key: str | None,
|
| 40 |
+
aws_session_token: str | None,
|
| 41 |
+
region: str | None,
|
| 42 |
+
profile: str | None,
|
| 43 |
+
data: str | None,
|
| 44 |
+
) -> dict[str, str]:
|
| 45 |
+
from botocore.auth import SigV4Auth
|
| 46 |
+
from botocore.awsrequest import AWSRequest
|
| 47 |
+
|
| 48 |
+
session = _get_session(
|
| 49 |
+
profile=profile,
|
| 50 |
+
region=region,
|
| 51 |
+
aws_access_key=aws_access_key,
|
| 52 |
+
aws_secret_key=aws_secret_key,
|
| 53 |
+
aws_session_token=aws_session_token,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# The connection header may be stripped by a proxy somewhere, so the receiver
|
| 57 |
+
# of this message may not see this header, so we remove it from the set of headers
|
| 58 |
+
# that are signed.
|
| 59 |
+
headers = headers.copy()
|
| 60 |
+
del headers["connection"]
|
| 61 |
+
|
| 62 |
+
request = AWSRequest(method=method.upper(), url=url, headers=headers, data=data)
|
| 63 |
+
credentials = session.get_credentials()
|
| 64 |
+
if not credentials:
|
| 65 |
+
raise RuntimeError("could not resolve credentials from session")
|
| 66 |
+
|
| 67 |
+
signer = SigV4Auth(credentials, "bedrock", session.region_name)
|
| 68 |
+
signer.add_auth(request)
|
| 69 |
+
|
| 70 |
+
prepped = request.prepare()
|
| 71 |
+
|
| 72 |
+
return {key: value for key, value in dict(prepped.headers).items() if value is not None}
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_beta.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from ..._compat import cached_property
|
| 6 |
+
from ..._resource import SyncAPIResource, AsyncAPIResource
|
| 7 |
+
from ._beta_messages import (
|
| 8 |
+
Messages,
|
| 9 |
+
AsyncMessages,
|
| 10 |
+
MessagesWithRawResponse,
|
| 11 |
+
AsyncMessagesWithRawResponse,
|
| 12 |
+
MessagesWithStreamingResponse,
|
| 13 |
+
AsyncMessagesWithStreamingResponse,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
__all__ = ["Beta", "AsyncBeta"]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class Beta(SyncAPIResource):
|
| 20 |
+
@cached_property
|
| 21 |
+
def messages(self) -> Messages:
|
| 22 |
+
return Messages(self._client)
|
| 23 |
+
|
| 24 |
+
@cached_property
|
| 25 |
+
def with_raw_response(self) -> BetaWithRawResponse:
|
| 26 |
+
"""
|
| 27 |
+
This property can be used as a prefix for any HTTP method call to return the
|
| 28 |
+
the raw response object instead of the parsed content.
|
| 29 |
+
|
| 30 |
+
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
| 31 |
+
"""
|
| 32 |
+
return BetaWithRawResponse(self)
|
| 33 |
+
|
| 34 |
+
@cached_property
|
| 35 |
+
def with_streaming_response(self) -> BetaWithStreamingResponse:
|
| 36 |
+
"""
|
| 37 |
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
| 38 |
+
|
| 39 |
+
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
| 40 |
+
"""
|
| 41 |
+
return BetaWithStreamingResponse(self)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class AsyncBeta(AsyncAPIResource):
|
| 45 |
+
@cached_property
|
| 46 |
+
def messages(self) -> AsyncMessages:
|
| 47 |
+
return AsyncMessages(self._client)
|
| 48 |
+
|
| 49 |
+
@cached_property
|
| 50 |
+
def with_raw_response(self) -> AsyncBetaWithRawResponse:
|
| 51 |
+
"""
|
| 52 |
+
This property can be used as a prefix for any HTTP method call to return the
|
| 53 |
+
the raw response object instead of the parsed content.
|
| 54 |
+
|
| 55 |
+
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
| 56 |
+
"""
|
| 57 |
+
return AsyncBetaWithRawResponse(self)
|
| 58 |
+
|
| 59 |
+
@cached_property
|
| 60 |
+
def with_streaming_response(self) -> AsyncBetaWithStreamingResponse:
|
| 61 |
+
"""
|
| 62 |
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
| 63 |
+
|
| 64 |
+
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
| 65 |
+
"""
|
| 66 |
+
return AsyncBetaWithStreamingResponse(self)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class BetaWithRawResponse:
|
| 70 |
+
def __init__(self, beta: Beta) -> None:
|
| 71 |
+
self._beta = beta
|
| 72 |
+
|
| 73 |
+
@cached_property
|
| 74 |
+
def messages(self) -> MessagesWithRawResponse:
|
| 75 |
+
return MessagesWithRawResponse(self._beta.messages)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class AsyncBetaWithRawResponse:
|
| 79 |
+
def __init__(self, beta: AsyncBeta) -> None:
|
| 80 |
+
self._beta = beta
|
| 81 |
+
|
| 82 |
+
@cached_property
|
| 83 |
+
def messages(self) -> AsyncMessagesWithRawResponse:
|
| 84 |
+
return AsyncMessagesWithRawResponse(self._beta.messages)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class BetaWithStreamingResponse:
|
| 88 |
+
def __init__(self, beta: Beta) -> None:
|
| 89 |
+
self._beta = beta
|
| 90 |
+
|
| 91 |
+
@cached_property
|
| 92 |
+
def messages(self) -> MessagesWithStreamingResponse:
|
| 93 |
+
return MessagesWithStreamingResponse(self._beta.messages)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class AsyncBetaWithStreamingResponse:
|
| 97 |
+
def __init__(self, beta: AsyncBeta) -> None:
|
| 98 |
+
self._beta = beta
|
| 99 |
+
|
| 100 |
+
@cached_property
|
| 101 |
+
def messages(self) -> AsyncMessagesWithStreamingResponse:
|
| 102 |
+
return AsyncMessagesWithStreamingResponse(self._beta.messages)
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_beta_messages.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from ... import _legacy_response
|
| 6 |
+
from ..._compat import cached_property
|
| 7 |
+
from ..._resource import SyncAPIResource, AsyncAPIResource
|
| 8 |
+
from ..._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
|
| 9 |
+
from ...resources.beta import Messages as FirstPartyMessagesAPI, AsyncMessages as FirstPartyAsyncMessagesAPI
|
| 10 |
+
|
| 11 |
+
__all__ = ["Messages", "AsyncMessages"]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class Messages(SyncAPIResource):
|
| 15 |
+
create = FirstPartyMessagesAPI.create
|
| 16 |
+
|
| 17 |
+
@cached_property
|
| 18 |
+
def with_raw_response(self) -> MessagesWithRawResponse:
|
| 19 |
+
"""
|
| 20 |
+
This property can be used as a prefix for any HTTP method call to return the
|
| 21 |
+
the raw response object instead of the parsed content.
|
| 22 |
+
|
| 23 |
+
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
| 24 |
+
"""
|
| 25 |
+
return MessagesWithRawResponse(self)
|
| 26 |
+
|
| 27 |
+
@cached_property
|
| 28 |
+
def with_streaming_response(self) -> MessagesWithStreamingResponse:
|
| 29 |
+
"""
|
| 30 |
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
| 31 |
+
|
| 32 |
+
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
| 33 |
+
"""
|
| 34 |
+
return MessagesWithStreamingResponse(self)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class AsyncMessages(AsyncAPIResource):
|
| 38 |
+
create = FirstPartyAsyncMessagesAPI.create
|
| 39 |
+
|
| 40 |
+
@cached_property
|
| 41 |
+
def with_raw_response(self) -> AsyncMessagesWithRawResponse:
|
| 42 |
+
"""
|
| 43 |
+
This property can be used as a prefix for any HTTP method call to return the
|
| 44 |
+
the raw response object instead of the parsed content.
|
| 45 |
+
|
| 46 |
+
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#accessing-raw-response-data-eg-headers
|
| 47 |
+
"""
|
| 48 |
+
return AsyncMessagesWithRawResponse(self)
|
| 49 |
+
|
| 50 |
+
@cached_property
|
| 51 |
+
def with_streaming_response(self) -> AsyncMessagesWithStreamingResponse:
|
| 52 |
+
"""
|
| 53 |
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
| 54 |
+
|
| 55 |
+
For more information, see https://www.github.com/anthropics/anthropic-sdk-python#with_streaming_response
|
| 56 |
+
"""
|
| 57 |
+
return AsyncMessagesWithStreamingResponse(self)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class MessagesWithRawResponse:
|
| 61 |
+
def __init__(self, messages: Messages) -> None:
|
| 62 |
+
self._messages = messages
|
| 63 |
+
|
| 64 |
+
self.create = _legacy_response.to_raw_response_wrapper(
|
| 65 |
+
messages.create,
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class AsyncMessagesWithRawResponse:
|
| 70 |
+
def __init__(self, messages: AsyncMessages) -> None:
|
| 71 |
+
self._messages = messages
|
| 72 |
+
|
| 73 |
+
self.create = _legacy_response.async_to_raw_response_wrapper(
|
| 74 |
+
messages.create,
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class MessagesWithStreamingResponse:
|
| 79 |
+
def __init__(self, messages: Messages) -> None:
|
| 80 |
+
self._messages = messages
|
| 81 |
+
|
| 82 |
+
self.create = to_streamed_response_wrapper(
|
| 83 |
+
messages.create,
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class AsyncMessagesWithStreamingResponse:
|
| 88 |
+
def __init__(self, messages: AsyncMessages) -> None:
|
| 89 |
+
self._messages = messages
|
| 90 |
+
|
| 91 |
+
self.create = async_to_streamed_response_wrapper(
|
| 92 |
+
messages.create,
|
| 93 |
+
)
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_client.py
ADDED
|
@@ -0,0 +1,458 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import logging
|
| 5 |
+
import urllib.parse
|
| 6 |
+
from typing import Any, Union, Mapping, TypeVar
|
| 7 |
+
from typing_extensions import Self, override
|
| 8 |
+
|
| 9 |
+
import httpx
|
| 10 |
+
|
| 11 |
+
from ... import _exceptions
|
| 12 |
+
from ._beta import Beta, AsyncBeta
|
| 13 |
+
from ..._types import NOT_GIVEN, Timeout, NotGiven
|
| 14 |
+
from ..._utils import is_dict, is_given
|
| 15 |
+
from ..._compat import model_copy
|
| 16 |
+
from ..._version import __version__
|
| 17 |
+
from ..._streaming import Stream, AsyncStream
|
| 18 |
+
from ..._exceptions import AnthropicError, APIStatusError
|
| 19 |
+
from ..._base_client import (
|
| 20 |
+
DEFAULT_MAX_RETRIES,
|
| 21 |
+
BaseClient,
|
| 22 |
+
SyncAPIClient,
|
| 23 |
+
AsyncAPIClient,
|
| 24 |
+
FinalRequestOptions,
|
| 25 |
+
)
|
| 26 |
+
from ._stream_decoder import AWSEventStreamDecoder
|
| 27 |
+
from ...resources.messages import Messages, AsyncMessages
|
| 28 |
+
from ...resources.completions import Completions, AsyncCompletions
|
| 29 |
+
|
| 30 |
+
log: logging.Logger = logging.getLogger(__name__)
|
| 31 |
+
|
| 32 |
+
DEFAULT_VERSION = "bedrock-2023-05-31"
|
| 33 |
+
|
| 34 |
+
_HttpxClientT = TypeVar("_HttpxClientT", bound=Union[httpx.Client, httpx.AsyncClient])
|
| 35 |
+
_DefaultStreamT = TypeVar("_DefaultStreamT", bound=Union[Stream[Any], AsyncStream[Any]])
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def _prepare_options(input_options: FinalRequestOptions) -> FinalRequestOptions:
|
| 39 |
+
options = model_copy(input_options, deep=True)
|
| 40 |
+
|
| 41 |
+
if is_dict(options.json_data):
|
| 42 |
+
options.json_data.setdefault("anthropic_version", DEFAULT_VERSION)
|
| 43 |
+
|
| 44 |
+
if is_given(options.headers):
|
| 45 |
+
betas = options.headers.get("anthropic-beta")
|
| 46 |
+
if betas:
|
| 47 |
+
options.json_data.setdefault("anthropic_beta", betas.split(","))
|
| 48 |
+
|
| 49 |
+
if options.url in {"/v1/complete", "/v1/messages", "/v1/messages?beta=true"} and options.method == "post":
|
| 50 |
+
if not is_dict(options.json_data):
|
| 51 |
+
raise RuntimeError("Expected dictionary json_data for post /completions endpoint")
|
| 52 |
+
|
| 53 |
+
model = options.json_data.pop("model", None)
|
| 54 |
+
model = urllib.parse.quote(str(model), safe=":")
|
| 55 |
+
stream = options.json_data.pop("stream", False)
|
| 56 |
+
if stream:
|
| 57 |
+
options.url = f"/model/{model}/invoke-with-response-stream"
|
| 58 |
+
else:
|
| 59 |
+
options.url = f"/model/{model}/invoke"
|
| 60 |
+
|
| 61 |
+
if options.url.startswith("/v1/messages/batches"):
|
| 62 |
+
raise AnthropicError("The Batch API is not supported in Bedrock yet")
|
| 63 |
+
|
| 64 |
+
if options.url == "/v1/messages/count_tokens":
|
| 65 |
+
raise AnthropicError("Token counting is not supported in Bedrock yet")
|
| 66 |
+
|
| 67 |
+
return options
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _infer_region() -> str:
|
| 71 |
+
"""
|
| 72 |
+
Infer the AWS region from the environment variables or
|
| 73 |
+
from the boto3 session if available.
|
| 74 |
+
"""
|
| 75 |
+
aws_region = os.environ.get("AWS_REGION")
|
| 76 |
+
if aws_region is None:
|
| 77 |
+
try:
|
| 78 |
+
import boto3
|
| 79 |
+
|
| 80 |
+
session = boto3.Session()
|
| 81 |
+
if session.region_name:
|
| 82 |
+
aws_region = session.region_name
|
| 83 |
+
except ImportError:
|
| 84 |
+
pass
|
| 85 |
+
|
| 86 |
+
if aws_region is None:
|
| 87 |
+
log.warning("No AWS region specified, defaulting to us-east-1")
|
| 88 |
+
aws_region = "us-east-1" # fall back to legacy behavior
|
| 89 |
+
|
| 90 |
+
return aws_region
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class BaseBedrockClient(BaseClient[_HttpxClientT, _DefaultStreamT]):
|
| 94 |
+
@override
|
| 95 |
+
def _make_status_error(
|
| 96 |
+
self,
|
| 97 |
+
err_msg: str,
|
| 98 |
+
*,
|
| 99 |
+
body: object,
|
| 100 |
+
response: httpx.Response,
|
| 101 |
+
) -> APIStatusError:
|
| 102 |
+
if response.status_code == 400:
|
| 103 |
+
return _exceptions.BadRequestError(err_msg, response=response, body=body)
|
| 104 |
+
|
| 105 |
+
if response.status_code == 401:
|
| 106 |
+
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
|
| 107 |
+
|
| 108 |
+
if response.status_code == 403:
|
| 109 |
+
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
|
| 110 |
+
|
| 111 |
+
if response.status_code == 404:
|
| 112 |
+
return _exceptions.NotFoundError(err_msg, response=response, body=body)
|
| 113 |
+
|
| 114 |
+
if response.status_code == 409:
|
| 115 |
+
return _exceptions.ConflictError(err_msg, response=response, body=body)
|
| 116 |
+
|
| 117 |
+
if response.status_code == 422:
|
| 118 |
+
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
|
| 119 |
+
|
| 120 |
+
if response.status_code == 429:
|
| 121 |
+
return _exceptions.RateLimitError(err_msg, response=response, body=body)
|
| 122 |
+
|
| 123 |
+
if response.status_code == 503:
|
| 124 |
+
return _exceptions.ServiceUnavailableError(err_msg, response=response, body=body)
|
| 125 |
+
|
| 126 |
+
if response.status_code >= 500:
|
| 127 |
+
return _exceptions.InternalServerError(err_msg, response=response, body=body)
|
| 128 |
+
return APIStatusError(err_msg, response=response, body=body)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
class AnthropicBedrock(BaseBedrockClient[httpx.Client, Stream[Any]], SyncAPIClient):
|
| 132 |
+
messages: Messages
|
| 133 |
+
completions: Completions
|
| 134 |
+
beta: Beta
|
| 135 |
+
|
| 136 |
+
def __init__(
|
| 137 |
+
self,
|
| 138 |
+
aws_secret_key: str | None = None,
|
| 139 |
+
aws_access_key: str | None = None,
|
| 140 |
+
aws_region: str | None = None,
|
| 141 |
+
aws_profile: str | None = None,
|
| 142 |
+
aws_session_token: str | None = None,
|
| 143 |
+
api_key: str | None = None,
|
| 144 |
+
base_url: str | httpx.URL | None = None,
|
| 145 |
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
| 146 |
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
| 147 |
+
default_headers: Mapping[str, str] | None = None,
|
| 148 |
+
default_query: Mapping[str, object] | None = None,
|
| 149 |
+
# Configure a custom httpx client. See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
| 150 |
+
http_client: httpx.Client | None = None,
|
| 151 |
+
# Enable or disable schema validation for data returned by the API.
|
| 152 |
+
# When enabled an error APIResponseValidationError is raised
|
| 153 |
+
# if the API responds with invalid data for the expected schema.
|
| 154 |
+
#
|
| 155 |
+
# This parameter may be removed or changed in the future.
|
| 156 |
+
# If you rely on this feature, please open a GitHub issue
|
| 157 |
+
# outlining your use-case to help us decide if it should be
|
| 158 |
+
# part of our public interface in the future.
|
| 159 |
+
_strict_response_validation: bool = False,
|
| 160 |
+
) -> None:
|
| 161 |
+
if api_key is None:
|
| 162 |
+
api_key = os.environ.get("AWS_BEARER_TOKEN_BEDROCK")
|
| 163 |
+
|
| 164 |
+
has_aws_credentials = (
|
| 165 |
+
aws_access_key is not None
|
| 166 |
+
or aws_secret_key is not None
|
| 167 |
+
or aws_session_token is not None
|
| 168 |
+
or aws_profile is not None
|
| 169 |
+
)
|
| 170 |
+
if api_key is not None and has_aws_credentials:
|
| 171 |
+
raise ValueError(
|
| 172 |
+
"Cannot specify both `api_key` and AWS credentials (`aws_access_key`, `aws_secret_key`, `aws_session_token`, `aws_profile`)"
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
self.api_key: str | None = api_key
|
| 176 |
+
|
| 177 |
+
self.aws_secret_key = aws_secret_key
|
| 178 |
+
|
| 179 |
+
self.aws_access_key = aws_access_key
|
| 180 |
+
|
| 181 |
+
self.aws_region = _infer_region() if aws_region is None else aws_region
|
| 182 |
+
self.aws_profile = aws_profile
|
| 183 |
+
|
| 184 |
+
self.aws_session_token = aws_session_token
|
| 185 |
+
|
| 186 |
+
if base_url is None:
|
| 187 |
+
base_url = os.environ.get("ANTHROPIC_BEDROCK_BASE_URL")
|
| 188 |
+
if base_url is None:
|
| 189 |
+
base_url = f"https://bedrock-runtime.{self.aws_region}.amazonaws.com"
|
| 190 |
+
|
| 191 |
+
super().__init__(
|
| 192 |
+
version=__version__,
|
| 193 |
+
base_url=base_url,
|
| 194 |
+
timeout=timeout,
|
| 195 |
+
max_retries=max_retries,
|
| 196 |
+
custom_headers=default_headers,
|
| 197 |
+
custom_query=default_query,
|
| 198 |
+
http_client=http_client,
|
| 199 |
+
_strict_response_validation=_strict_response_validation,
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
self.beta = Beta(self)
|
| 203 |
+
self.messages = Messages(self)
|
| 204 |
+
self.completions = Completions(self)
|
| 205 |
+
|
| 206 |
+
@override
|
| 207 |
+
def _make_sse_decoder(self) -> AWSEventStreamDecoder:
|
| 208 |
+
return AWSEventStreamDecoder()
|
| 209 |
+
|
| 210 |
+
@override
|
| 211 |
+
def _prepare_options(self, options: FinalRequestOptions) -> FinalRequestOptions:
|
| 212 |
+
return _prepare_options(options)
|
| 213 |
+
|
| 214 |
+
@override
|
| 215 |
+
def _prepare_request(self, request: httpx.Request) -> None:
|
| 216 |
+
if self.api_key is not None:
|
| 217 |
+
request.headers["Authorization"] = f"Bearer {self.api_key}"
|
| 218 |
+
return
|
| 219 |
+
|
| 220 |
+
from ._auth import get_auth_headers
|
| 221 |
+
|
| 222 |
+
data = request.read().decode()
|
| 223 |
+
|
| 224 |
+
headers = get_auth_headers(
|
| 225 |
+
method=request.method,
|
| 226 |
+
url=str(request.url),
|
| 227 |
+
headers=request.headers,
|
| 228 |
+
aws_access_key=self.aws_access_key,
|
| 229 |
+
aws_secret_key=self.aws_secret_key,
|
| 230 |
+
aws_session_token=self.aws_session_token,
|
| 231 |
+
region=self.aws_region or "us-east-1",
|
| 232 |
+
profile=self.aws_profile,
|
| 233 |
+
data=data,
|
| 234 |
+
)
|
| 235 |
+
request.headers.update(headers)
|
| 236 |
+
|
| 237 |
+
def copy(
|
| 238 |
+
self,
|
| 239 |
+
*,
|
| 240 |
+
aws_secret_key: str | None = None,
|
| 241 |
+
aws_access_key: str | None = None,
|
| 242 |
+
aws_region: str | None = None,
|
| 243 |
+
aws_session_token: str | None = None,
|
| 244 |
+
api_key: str | None = None,
|
| 245 |
+
base_url: str | httpx.URL | None = None,
|
| 246 |
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
| 247 |
+
http_client: httpx.Client | None = None,
|
| 248 |
+
max_retries: int | NotGiven = NOT_GIVEN,
|
| 249 |
+
default_headers: Mapping[str, str] | None = None,
|
| 250 |
+
set_default_headers: Mapping[str, str] | None = None,
|
| 251 |
+
default_query: Mapping[str, object] | None = None,
|
| 252 |
+
set_default_query: Mapping[str, object] | None = None,
|
| 253 |
+
_extra_kwargs: Mapping[str, Any] = {},
|
| 254 |
+
) -> Self:
|
| 255 |
+
"""
|
| 256 |
+
Create a new client instance re-using the same options given to the current client with optional overriding.
|
| 257 |
+
"""
|
| 258 |
+
if default_headers is not None and set_default_headers is not None:
|
| 259 |
+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
|
| 260 |
+
|
| 261 |
+
if default_query is not None and set_default_query is not None:
|
| 262 |
+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
|
| 263 |
+
|
| 264 |
+
headers = self._custom_headers
|
| 265 |
+
if default_headers is not None:
|
| 266 |
+
headers = {**headers, **default_headers}
|
| 267 |
+
elif set_default_headers is not None:
|
| 268 |
+
headers = set_default_headers
|
| 269 |
+
|
| 270 |
+
params = self._custom_query
|
| 271 |
+
if default_query is not None:
|
| 272 |
+
params = {**params, **default_query}
|
| 273 |
+
elif set_default_query is not None:
|
| 274 |
+
params = set_default_query
|
| 275 |
+
|
| 276 |
+
return self.__class__(
|
| 277 |
+
aws_secret_key=aws_secret_key or self.aws_secret_key,
|
| 278 |
+
aws_access_key=aws_access_key or self.aws_access_key,
|
| 279 |
+
aws_region=aws_region or self.aws_region,
|
| 280 |
+
aws_session_token=aws_session_token or self.aws_session_token,
|
| 281 |
+
api_key=api_key or self.api_key,
|
| 282 |
+
base_url=base_url or self.base_url,
|
| 283 |
+
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
| 284 |
+
http_client=http_client,
|
| 285 |
+
max_retries=max_retries if is_given(max_retries) else self.max_retries,
|
| 286 |
+
default_headers=headers,
|
| 287 |
+
default_query=params,
|
| 288 |
+
**_extra_kwargs,
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
# Alias for `copy` for nicer inline usage, e.g.
|
| 292 |
+
# client.with_options(timeout=10).foo.create(...)
|
| 293 |
+
with_options = copy
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
class AsyncAnthropicBedrock(BaseBedrockClient[httpx.AsyncClient, AsyncStream[Any]], AsyncAPIClient):
|
| 297 |
+
messages: AsyncMessages
|
| 298 |
+
completions: AsyncCompletions
|
| 299 |
+
beta: AsyncBeta
|
| 300 |
+
|
| 301 |
+
def __init__(
|
| 302 |
+
self,
|
| 303 |
+
aws_secret_key: str | None = None,
|
| 304 |
+
aws_access_key: str | None = None,
|
| 305 |
+
aws_region: str | None = None,
|
| 306 |
+
aws_profile: str | None = None,
|
| 307 |
+
aws_session_token: str | None = None,
|
| 308 |
+
api_key: str | None = None,
|
| 309 |
+
base_url: str | httpx.URL | None = None,
|
| 310 |
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
| 311 |
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
| 312 |
+
default_headers: Mapping[str, str] | None = None,
|
| 313 |
+
default_query: Mapping[str, object] | None = None,
|
| 314 |
+
# Configure a custom httpx client. See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
|
| 315 |
+
http_client: httpx.AsyncClient | None = None,
|
| 316 |
+
# Enable or disable schema validation for data returned by the API.
|
| 317 |
+
# When enabled an error APIResponseValidationError is raised
|
| 318 |
+
# if the API responds with invalid data for the expected schema.
|
| 319 |
+
#
|
| 320 |
+
# This parameter may be removed or changed in the future.
|
| 321 |
+
# If you rely on this feature, please open a GitHub issue
|
| 322 |
+
# outlining your use-case to help us decide if it should be
|
| 323 |
+
# part of our public interface in the future.
|
| 324 |
+
_strict_response_validation: bool = False,
|
| 325 |
+
) -> None:
|
| 326 |
+
if api_key is None:
|
| 327 |
+
api_key = os.environ.get("AWS_BEARER_TOKEN_BEDROCK")
|
| 328 |
+
|
| 329 |
+
has_aws_credentials = (
|
| 330 |
+
aws_access_key is not None
|
| 331 |
+
or aws_secret_key is not None
|
| 332 |
+
or aws_session_token is not None
|
| 333 |
+
or aws_profile is not None
|
| 334 |
+
)
|
| 335 |
+
if api_key is not None and has_aws_credentials:
|
| 336 |
+
raise ValueError(
|
| 337 |
+
"Cannot specify both `api_key` and AWS credentials (`aws_access_key`, `aws_secret_key`, `aws_session_token`, `aws_profile`)"
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
self.api_key: str | None = api_key
|
| 341 |
+
|
| 342 |
+
self.aws_secret_key = aws_secret_key
|
| 343 |
+
|
| 344 |
+
self.aws_access_key = aws_access_key
|
| 345 |
+
|
| 346 |
+
self.aws_region = _infer_region() if aws_region is None else aws_region
|
| 347 |
+
self.aws_profile = aws_profile
|
| 348 |
+
|
| 349 |
+
self.aws_session_token = aws_session_token
|
| 350 |
+
|
| 351 |
+
if base_url is None:
|
| 352 |
+
base_url = os.environ.get("ANTHROPIC_BEDROCK_BASE_URL")
|
| 353 |
+
if base_url is None:
|
| 354 |
+
base_url = f"https://bedrock-runtime.{self.aws_region}.amazonaws.com"
|
| 355 |
+
|
| 356 |
+
super().__init__(
|
| 357 |
+
version=__version__,
|
| 358 |
+
base_url=base_url,
|
| 359 |
+
timeout=timeout,
|
| 360 |
+
max_retries=max_retries,
|
| 361 |
+
custom_headers=default_headers,
|
| 362 |
+
custom_query=default_query,
|
| 363 |
+
http_client=http_client,
|
| 364 |
+
_strict_response_validation=_strict_response_validation,
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
self.messages = AsyncMessages(self)
|
| 368 |
+
self.completions = AsyncCompletions(self)
|
| 369 |
+
self.beta = AsyncBeta(self)
|
| 370 |
+
|
| 371 |
+
@override
|
| 372 |
+
def _make_sse_decoder(self) -> AWSEventStreamDecoder:
|
| 373 |
+
return AWSEventStreamDecoder()
|
| 374 |
+
|
| 375 |
+
@override
|
| 376 |
+
async def _prepare_options(self, options: FinalRequestOptions) -> FinalRequestOptions:
|
| 377 |
+
return _prepare_options(options)
|
| 378 |
+
|
| 379 |
+
@override
|
| 380 |
+
async def _prepare_request(self, request: httpx.Request) -> None:
|
| 381 |
+
if self.api_key is not None:
|
| 382 |
+
request.headers["Authorization"] = f"Bearer {self.api_key}"
|
| 383 |
+
return
|
| 384 |
+
|
| 385 |
+
from ._auth import get_auth_headers
|
| 386 |
+
|
| 387 |
+
data = request.read().decode()
|
| 388 |
+
|
| 389 |
+
headers = get_auth_headers(
|
| 390 |
+
method=request.method,
|
| 391 |
+
url=str(request.url),
|
| 392 |
+
headers=request.headers,
|
| 393 |
+
aws_access_key=self.aws_access_key,
|
| 394 |
+
aws_secret_key=self.aws_secret_key,
|
| 395 |
+
aws_session_token=self.aws_session_token,
|
| 396 |
+
region=self.aws_region or "us-east-1",
|
| 397 |
+
profile=self.aws_profile,
|
| 398 |
+
data=data,
|
| 399 |
+
)
|
| 400 |
+
request.headers.update(headers)
|
| 401 |
+
|
| 402 |
+
def copy(
|
| 403 |
+
self,
|
| 404 |
+
*,
|
| 405 |
+
aws_secret_key: str | None = None,
|
| 406 |
+
aws_access_key: str | None = None,
|
| 407 |
+
aws_region: str | None = None,
|
| 408 |
+
aws_session_token: str | None = None,
|
| 409 |
+
api_key: str | None = None,
|
| 410 |
+
base_url: str | httpx.URL | None = None,
|
| 411 |
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
| 412 |
+
http_client: httpx.AsyncClient | None = None,
|
| 413 |
+
max_retries: int | NotGiven = NOT_GIVEN,
|
| 414 |
+
default_headers: Mapping[str, str] | None = None,
|
| 415 |
+
set_default_headers: Mapping[str, str] | None = None,
|
| 416 |
+
default_query: Mapping[str, object] | None = None,
|
| 417 |
+
set_default_query: Mapping[str, object] | None = None,
|
| 418 |
+
_extra_kwargs: Mapping[str, Any] = {},
|
| 419 |
+
) -> Self:
|
| 420 |
+
"""
|
| 421 |
+
Create a new client instance re-using the same options given to the current client with optional overriding.
|
| 422 |
+
"""
|
| 423 |
+
if default_headers is not None and set_default_headers is not None:
|
| 424 |
+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
|
| 425 |
+
|
| 426 |
+
if default_query is not None and set_default_query is not None:
|
| 427 |
+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
|
| 428 |
+
|
| 429 |
+
headers = self._custom_headers
|
| 430 |
+
if default_headers is not None:
|
| 431 |
+
headers = {**headers, **default_headers}
|
| 432 |
+
elif set_default_headers is not None:
|
| 433 |
+
headers = set_default_headers
|
| 434 |
+
|
| 435 |
+
params = self._custom_query
|
| 436 |
+
if default_query is not None:
|
| 437 |
+
params = {**params, **default_query}
|
| 438 |
+
elif set_default_query is not None:
|
| 439 |
+
params = set_default_query
|
| 440 |
+
|
| 441 |
+
return self.__class__(
|
| 442 |
+
aws_secret_key=aws_secret_key or self.aws_secret_key,
|
| 443 |
+
aws_access_key=aws_access_key or self.aws_access_key,
|
| 444 |
+
aws_region=aws_region or self.aws_region,
|
| 445 |
+
aws_session_token=aws_session_token or self.aws_session_token,
|
| 446 |
+
api_key=api_key or self.api_key,
|
| 447 |
+
base_url=base_url or self.base_url,
|
| 448 |
+
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
| 449 |
+
http_client=http_client,
|
| 450 |
+
max_retries=max_retries if is_given(max_retries) else self.max_retries,
|
| 451 |
+
default_headers=headers,
|
| 452 |
+
default_query=params,
|
| 453 |
+
**_extra_kwargs,
|
| 454 |
+
)
|
| 455 |
+
|
| 456 |
+
# Alias for `copy` for nicer inline usage, e.g.
|
| 457 |
+
# client.with_options(timeout=10).foo.create(...)
|
| 458 |
+
with_options = copy
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_mantle.py
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from typing import Any, Union, Mapping, TypeVar
|
| 5 |
+
from typing_extensions import Self, override
|
| 6 |
+
|
| 7 |
+
import httpx
|
| 8 |
+
|
| 9 |
+
from ... import _exceptions
|
| 10 |
+
from ..._qs import Querystring
|
| 11 |
+
from ..._types import NOT_GIVEN, Omit, Timeout, NotGiven
|
| 12 |
+
from ..._utils import is_given
|
| 13 |
+
from ..._compat import cached_property
|
| 14 |
+
from ..._version import __version__
|
| 15 |
+
from ..aws._auth import get_auth_headers
|
| 16 |
+
from ..._resource import SyncAPIResource, AsyncAPIResource
|
| 17 |
+
from ..._streaming import Stream, AsyncStream
|
| 18 |
+
from ..._exceptions import AnthropicError, APIStatusError
|
| 19 |
+
from ..._base_client import (
|
| 20 |
+
DEFAULT_MAX_RETRIES,
|
| 21 |
+
BaseClient,
|
| 22 |
+
SyncAPIClient,
|
| 23 |
+
AsyncAPIClient,
|
| 24 |
+
)
|
| 25 |
+
from ..aws._credentials import (
|
| 26 |
+
resolve_region,
|
| 27 |
+
resolve_api_key,
|
| 28 |
+
resolve_auth_mode,
|
| 29 |
+
validate_credentials,
|
| 30 |
+
)
|
| 31 |
+
from ...resources.messages import Messages, AsyncMessages
|
| 32 |
+
from ...resources.beta.messages import Messages as BetaMessages, AsyncMessages as AsyncBetaMessages
|
| 33 |
+
|
| 34 |
+
DEFAULT_SERVICE_NAME = "bedrock-mantle"
|
| 35 |
+
|
| 36 |
+
_MANTLE_API_KEY_ENV_VARS = ("AWS_BEARER_TOKEN_BEDROCK", "ANTHROPIC_AWS_API_KEY")
|
| 37 |
+
|
| 38 |
+
_HttpxClientT = TypeVar("_HttpxClientT", bound=Union[httpx.Client, httpx.AsyncClient])
|
| 39 |
+
_DefaultStreamT = TypeVar("_DefaultStreamT", bound=Union[Stream[Any], AsyncStream[Any]])
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# --- Beta resources (messages-only) ---
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class MantleBeta(SyncAPIResource):
|
| 46 |
+
@cached_property
|
| 47 |
+
def messages(self) -> BetaMessages:
|
| 48 |
+
return BetaMessages(self._client)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class AsyncMantleBeta(AsyncAPIResource):
|
| 52 |
+
@cached_property
|
| 53 |
+
def messages(self) -> AsyncBetaMessages:
|
| 54 |
+
return AsyncBetaMessages(self._client)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# --- Base ---
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class BaseMantleClient(BaseClient[_HttpxClientT, _DefaultStreamT]):
|
| 61 |
+
@override
|
| 62 |
+
def _make_status_error(
|
| 63 |
+
self,
|
| 64 |
+
err_msg: str,
|
| 65 |
+
*,
|
| 66 |
+
body: object,
|
| 67 |
+
response: httpx.Response,
|
| 68 |
+
) -> APIStatusError:
|
| 69 |
+
if response.status_code == 400:
|
| 70 |
+
return _exceptions.BadRequestError(err_msg, response=response, body=body)
|
| 71 |
+
|
| 72 |
+
if response.status_code == 401:
|
| 73 |
+
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
|
| 74 |
+
|
| 75 |
+
if response.status_code == 403:
|
| 76 |
+
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
|
| 77 |
+
|
| 78 |
+
if response.status_code == 404:
|
| 79 |
+
return _exceptions.NotFoundError(err_msg, response=response, body=body)
|
| 80 |
+
|
| 81 |
+
if response.status_code == 409:
|
| 82 |
+
return _exceptions.ConflictError(err_msg, response=response, body=body)
|
| 83 |
+
|
| 84 |
+
if response.status_code == 413:
|
| 85 |
+
return _exceptions.RequestTooLargeError(err_msg, response=response, body=body)
|
| 86 |
+
|
| 87 |
+
if response.status_code == 422:
|
| 88 |
+
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
|
| 89 |
+
|
| 90 |
+
if response.status_code == 429:
|
| 91 |
+
return _exceptions.RateLimitError(err_msg, response=response, body=body)
|
| 92 |
+
|
| 93 |
+
if response.status_code == 529:
|
| 94 |
+
return _exceptions.OverloadedError(err_msg, response=response, body=body)
|
| 95 |
+
|
| 96 |
+
if response.status_code >= 500:
|
| 97 |
+
return _exceptions.InternalServerError(err_msg, response=response, body=body)
|
| 98 |
+
return APIStatusError(err_msg, response=response, body=body)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# --- Shared init logic ---
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def _resolve_mantle_config(
|
| 105 |
+
*,
|
| 106 |
+
api_key: str | None,
|
| 107 |
+
aws_access_key: str | None,
|
| 108 |
+
aws_secret_key: str | None,
|
| 109 |
+
aws_region: str | None,
|
| 110 |
+
aws_profile: str | None,
|
| 111 |
+
skip_auth: bool,
|
| 112 |
+
base_url: str | httpx.URL | None,
|
| 113 |
+
default_headers: Mapping[str, str] | None,
|
| 114 |
+
) -> tuple[str | None, str | httpx.URL, bool, dict[str, str]]:
|
| 115 |
+
"""Resolve and validate all Mantle client configuration.
|
| 116 |
+
|
| 117 |
+
Returns (resolved_api_key, resolved_base_url, use_sigv4, merged_headers).
|
| 118 |
+
"""
|
| 119 |
+
if skip_auth:
|
| 120 |
+
use_sigv4 = False
|
| 121 |
+
resolved_api_key = None
|
| 122 |
+
else:
|
| 123 |
+
validate_credentials(aws_access_key=aws_access_key, aws_secret_key=aws_secret_key)
|
| 124 |
+
|
| 125 |
+
use_sigv4 = resolve_auth_mode(
|
| 126 |
+
api_key=api_key,
|
| 127 |
+
aws_access_key=aws_access_key,
|
| 128 |
+
aws_secret_key=aws_secret_key,
|
| 129 |
+
aws_profile=aws_profile,
|
| 130 |
+
api_key_env_vars=_MANTLE_API_KEY_ENV_VARS,
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
resolved_api_key = resolve_api_key(
|
| 134 |
+
api_key=api_key,
|
| 135 |
+
use_sigv4=use_sigv4,
|
| 136 |
+
api_key_env_vars=_MANTLE_API_KEY_ENV_VARS,
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
resolved_region = resolve_region(aws_region)
|
| 140 |
+
|
| 141 |
+
if base_url is None:
|
| 142 |
+
base_url = os.environ.get("ANTHROPIC_BEDROCK_MANTLE_BASE_URL")
|
| 143 |
+
if base_url is None:
|
| 144 |
+
if resolved_region is None:
|
| 145 |
+
raise AnthropicError(
|
| 146 |
+
"No AWS region or base URL found. Set `aws_region` in the constructor, "
|
| 147 |
+
"the `AWS_REGION` / `AWS_DEFAULT_REGION` environment variable, or provide "
|
| 148 |
+
"a `base_url` / `ANTHROPIC_BEDROCK_MANTLE_BASE_URL` environment variable."
|
| 149 |
+
)
|
| 150 |
+
base_url = f"https://bedrock-mantle.{resolved_region}.api.aws/anthropic"
|
| 151 |
+
|
| 152 |
+
merged_headers: dict[str, str] = {}
|
| 153 |
+
if default_headers:
|
| 154 |
+
merged_headers.update(default_headers)
|
| 155 |
+
|
| 156 |
+
return resolved_api_key, base_url, use_sigv4, merged_headers
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
# --- Sync client ---
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class AnthropicBedrockMantle(BaseMantleClient[httpx.Client, Stream[Any]], SyncAPIClient):
|
| 163 |
+
messages: Messages
|
| 164 |
+
beta: MantleBeta
|
| 165 |
+
|
| 166 |
+
aws_region: str | None
|
| 167 |
+
aws_access_key: str | None
|
| 168 |
+
aws_secret_key: str | None
|
| 169 |
+
aws_session_token: str | None
|
| 170 |
+
aws_profile: str | None
|
| 171 |
+
skip_auth: bool
|
| 172 |
+
|
| 173 |
+
_use_sigv4: bool
|
| 174 |
+
|
| 175 |
+
def __init__(
|
| 176 |
+
self,
|
| 177 |
+
*,
|
| 178 |
+
aws_access_key: str | None = None,
|
| 179 |
+
aws_secret_key: str | None = None,
|
| 180 |
+
aws_session_token: str | None = None,
|
| 181 |
+
aws_region: str | None = None,
|
| 182 |
+
aws_profile: str | None = None,
|
| 183 |
+
api_key: str | None = None,
|
| 184 |
+
skip_auth: bool = False,
|
| 185 |
+
base_url: str | httpx.URL | None = None,
|
| 186 |
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
| 187 |
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
| 188 |
+
default_headers: Mapping[str, str] | None = None,
|
| 189 |
+
default_query: Mapping[str, object] | None = None,
|
| 190 |
+
http_client: httpx.Client | None = None,
|
| 191 |
+
_strict_response_validation: bool = False,
|
| 192 |
+
) -> None:
|
| 193 |
+
resolved_api_key, resolved_base_url, use_sigv4, merged_headers = _resolve_mantle_config(
|
| 194 |
+
api_key=api_key,
|
| 195 |
+
aws_access_key=aws_access_key,
|
| 196 |
+
aws_secret_key=aws_secret_key,
|
| 197 |
+
aws_region=aws_region,
|
| 198 |
+
aws_profile=aws_profile,
|
| 199 |
+
skip_auth=skip_auth,
|
| 200 |
+
base_url=base_url,
|
| 201 |
+
default_headers=default_headers,
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
resolved_region = resolve_region(aws_region)
|
| 205 |
+
|
| 206 |
+
super().__init__(
|
| 207 |
+
version=__version__,
|
| 208 |
+
base_url=resolved_base_url,
|
| 209 |
+
timeout=timeout,
|
| 210 |
+
max_retries=max_retries,
|
| 211 |
+
custom_headers=merged_headers,
|
| 212 |
+
custom_query=default_query,
|
| 213 |
+
http_client=http_client,
|
| 214 |
+
_strict_response_validation=_strict_response_validation,
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
self.api_key = resolved_api_key
|
| 218 |
+
self.aws_region = resolved_region
|
| 219 |
+
self.aws_access_key = aws_access_key
|
| 220 |
+
self.aws_secret_key = aws_secret_key
|
| 221 |
+
self.aws_session_token = aws_session_token
|
| 222 |
+
self.aws_profile = aws_profile
|
| 223 |
+
self.skip_auth = skip_auth
|
| 224 |
+
self._use_sigv4 = use_sigv4
|
| 225 |
+
|
| 226 |
+
self.messages = Messages(self)
|
| 227 |
+
self.beta = MantleBeta(self)
|
| 228 |
+
|
| 229 |
+
@property
|
| 230 |
+
@override
|
| 231 |
+
def qs(self) -> Querystring:
|
| 232 |
+
return Querystring(array_format="comma")
|
| 233 |
+
|
| 234 |
+
@property
|
| 235 |
+
@override
|
| 236 |
+
def auth_headers(self) -> dict[str, str]:
|
| 237 |
+
if self.skip_auth or self._use_sigv4:
|
| 238 |
+
return {}
|
| 239 |
+
api_key = self.api_key
|
| 240 |
+
if api_key is None:
|
| 241 |
+
return {}
|
| 242 |
+
return {"Authorization": f"Bearer {api_key}"}
|
| 243 |
+
|
| 244 |
+
@property
|
| 245 |
+
@override
|
| 246 |
+
def default_headers(self) -> dict[str, str | Omit]:
|
| 247 |
+
return {
|
| 248 |
+
**super().default_headers,
|
| 249 |
+
"X-Stainless-Async": "false",
|
| 250 |
+
"anthropic-version": "2023-06-01",
|
| 251 |
+
**self._custom_headers,
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
@override
|
| 255 |
+
def _validate_headers(self, headers: Any, custom_headers: Any) -> None:
|
| 256 |
+
pass
|
| 257 |
+
|
| 258 |
+
@override
|
| 259 |
+
def _prepare_request(self, request: httpx.Request) -> None:
|
| 260 |
+
if self.skip_auth or not self._use_sigv4:
|
| 261 |
+
return
|
| 262 |
+
|
| 263 |
+
data = request.read().decode()
|
| 264 |
+
|
| 265 |
+
headers = get_auth_headers(
|
| 266 |
+
method=request.method,
|
| 267 |
+
url=str(request.url),
|
| 268 |
+
headers=request.headers,
|
| 269 |
+
aws_access_key=self.aws_access_key,
|
| 270 |
+
aws_secret_key=self.aws_secret_key,
|
| 271 |
+
aws_session_token=self.aws_session_token,
|
| 272 |
+
region=self.aws_region,
|
| 273 |
+
profile=self.aws_profile,
|
| 274 |
+
data=data,
|
| 275 |
+
service_name=DEFAULT_SERVICE_NAME,
|
| 276 |
+
)
|
| 277 |
+
request.headers.update(headers)
|
| 278 |
+
|
| 279 |
+
def copy(
|
| 280 |
+
self,
|
| 281 |
+
*,
|
| 282 |
+
api_key: str | None = None,
|
| 283 |
+
aws_access_key: str | None = None,
|
| 284 |
+
aws_secret_key: str | None = None,
|
| 285 |
+
aws_session_token: str | None = None,
|
| 286 |
+
aws_region: str | None = None,
|
| 287 |
+
aws_profile: str | None = None,
|
| 288 |
+
skip_auth: bool | None = None,
|
| 289 |
+
base_url: str | httpx.URL | None = None,
|
| 290 |
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
| 291 |
+
http_client: httpx.Client | None = None,
|
| 292 |
+
max_retries: int | NotGiven = NOT_GIVEN,
|
| 293 |
+
default_headers: Mapping[str, str] | None = None,
|
| 294 |
+
set_default_headers: Mapping[str, str] | None = None,
|
| 295 |
+
default_query: Mapping[str, object] | None = None,
|
| 296 |
+
set_default_query: Mapping[str, object] | None = None,
|
| 297 |
+
_extra_kwargs: Mapping[str, Any] = {},
|
| 298 |
+
) -> Self:
|
| 299 |
+
if default_headers is not None and set_default_headers is not None:
|
| 300 |
+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
|
| 301 |
+
|
| 302 |
+
if default_query is not None and set_default_query is not None:
|
| 303 |
+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
|
| 304 |
+
|
| 305 |
+
headers = self._custom_headers
|
| 306 |
+
if default_headers is not None:
|
| 307 |
+
headers = {**headers, **default_headers}
|
| 308 |
+
elif set_default_headers is not None:
|
| 309 |
+
headers = set_default_headers
|
| 310 |
+
|
| 311 |
+
params = self._custom_query
|
| 312 |
+
if default_query is not None:
|
| 313 |
+
params = {**params, **default_query}
|
| 314 |
+
elif set_default_query is not None:
|
| 315 |
+
params = set_default_query
|
| 316 |
+
|
| 317 |
+
return self.__class__(
|
| 318 |
+
api_key=api_key or self.api_key,
|
| 319 |
+
aws_access_key=aws_access_key or self.aws_access_key,
|
| 320 |
+
aws_secret_key=aws_secret_key or self.aws_secret_key,
|
| 321 |
+
aws_session_token=aws_session_token or self.aws_session_token,
|
| 322 |
+
aws_region=aws_region or self.aws_region,
|
| 323 |
+
aws_profile=aws_profile or self.aws_profile,
|
| 324 |
+
skip_auth=skip_auth if skip_auth is not None else self.skip_auth,
|
| 325 |
+
base_url=base_url or self.base_url,
|
| 326 |
+
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
| 327 |
+
http_client=http_client,
|
| 328 |
+
max_retries=max_retries if is_given(max_retries) else self.max_retries,
|
| 329 |
+
default_headers=headers,
|
| 330 |
+
default_query=params,
|
| 331 |
+
**_extra_kwargs,
|
| 332 |
+
)
|
| 333 |
+
|
| 334 |
+
with_options = copy
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
# --- Async client ---
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
class AsyncAnthropicBedrockMantle(BaseMantleClient[httpx.AsyncClient, AsyncStream[Any]], AsyncAPIClient):
|
| 341 |
+
messages: AsyncMessages
|
| 342 |
+
beta: AsyncMantleBeta
|
| 343 |
+
|
| 344 |
+
aws_region: str | None
|
| 345 |
+
aws_access_key: str | None
|
| 346 |
+
aws_secret_key: str | None
|
| 347 |
+
aws_session_token: str | None
|
| 348 |
+
aws_profile: str | None
|
| 349 |
+
skip_auth: bool
|
| 350 |
+
|
| 351 |
+
_use_sigv4: bool
|
| 352 |
+
|
| 353 |
+
def __init__(
|
| 354 |
+
self,
|
| 355 |
+
*,
|
| 356 |
+
aws_access_key: str | None = None,
|
| 357 |
+
aws_secret_key: str | None = None,
|
| 358 |
+
aws_session_token: str | None = None,
|
| 359 |
+
aws_region: str | None = None,
|
| 360 |
+
aws_profile: str | None = None,
|
| 361 |
+
api_key: str | None = None,
|
| 362 |
+
skip_auth: bool = False,
|
| 363 |
+
base_url: str | httpx.URL | None = None,
|
| 364 |
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
| 365 |
+
max_retries: int = DEFAULT_MAX_RETRIES,
|
| 366 |
+
default_headers: Mapping[str, str] | None = None,
|
| 367 |
+
default_query: Mapping[str, object] | None = None,
|
| 368 |
+
http_client: httpx.AsyncClient | None = None,
|
| 369 |
+
_strict_response_validation: bool = False,
|
| 370 |
+
) -> None:
|
| 371 |
+
resolved_api_key, resolved_base_url, use_sigv4, merged_headers = _resolve_mantle_config(
|
| 372 |
+
api_key=api_key,
|
| 373 |
+
aws_access_key=aws_access_key,
|
| 374 |
+
aws_secret_key=aws_secret_key,
|
| 375 |
+
aws_region=aws_region,
|
| 376 |
+
aws_profile=aws_profile,
|
| 377 |
+
skip_auth=skip_auth,
|
| 378 |
+
base_url=base_url,
|
| 379 |
+
default_headers=default_headers,
|
| 380 |
+
)
|
| 381 |
+
|
| 382 |
+
resolved_region = resolve_region(aws_region)
|
| 383 |
+
|
| 384 |
+
super().__init__(
|
| 385 |
+
version=__version__,
|
| 386 |
+
base_url=resolved_base_url,
|
| 387 |
+
timeout=timeout,
|
| 388 |
+
max_retries=max_retries,
|
| 389 |
+
custom_headers=merged_headers,
|
| 390 |
+
custom_query=default_query,
|
| 391 |
+
http_client=http_client,
|
| 392 |
+
_strict_response_validation=_strict_response_validation,
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
self.api_key = resolved_api_key
|
| 396 |
+
self.aws_region = resolved_region
|
| 397 |
+
self.aws_access_key = aws_access_key
|
| 398 |
+
self.aws_secret_key = aws_secret_key
|
| 399 |
+
self.aws_session_token = aws_session_token
|
| 400 |
+
self.aws_profile = aws_profile
|
| 401 |
+
self.skip_auth = skip_auth
|
| 402 |
+
self._use_sigv4 = use_sigv4
|
| 403 |
+
|
| 404 |
+
self.messages = AsyncMessages(self)
|
| 405 |
+
self.beta = AsyncMantleBeta(self)
|
| 406 |
+
|
| 407 |
+
@property
|
| 408 |
+
@override
|
| 409 |
+
def qs(self) -> Querystring:
|
| 410 |
+
return Querystring(array_format="comma")
|
| 411 |
+
|
| 412 |
+
@property
|
| 413 |
+
@override
|
| 414 |
+
def auth_headers(self) -> dict[str, str]:
|
| 415 |
+
if self.skip_auth or self._use_sigv4:
|
| 416 |
+
return {}
|
| 417 |
+
api_key = self.api_key
|
| 418 |
+
if api_key is None:
|
| 419 |
+
return {}
|
| 420 |
+
return {"Authorization": f"Bearer {api_key}"}
|
| 421 |
+
|
| 422 |
+
@property
|
| 423 |
+
@override
|
| 424 |
+
def default_headers(self) -> dict[str, str | Omit]:
|
| 425 |
+
return {
|
| 426 |
+
**super().default_headers,
|
| 427 |
+
"X-Stainless-Async": "async:asyncio",
|
| 428 |
+
"anthropic-version": "2023-06-01",
|
| 429 |
+
**self._custom_headers,
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
@override
|
| 433 |
+
def _validate_headers(self, headers: Any, custom_headers: Any) -> None:
|
| 434 |
+
pass
|
| 435 |
+
|
| 436 |
+
@override
|
| 437 |
+
async def _prepare_request(self, request: httpx.Request) -> None:
|
| 438 |
+
if self.skip_auth or not self._use_sigv4:
|
| 439 |
+
return
|
| 440 |
+
|
| 441 |
+
data = request.read().decode()
|
| 442 |
+
|
| 443 |
+
headers = get_auth_headers(
|
| 444 |
+
method=request.method,
|
| 445 |
+
url=str(request.url),
|
| 446 |
+
headers=request.headers,
|
| 447 |
+
aws_access_key=self.aws_access_key,
|
| 448 |
+
aws_secret_key=self.aws_secret_key,
|
| 449 |
+
aws_session_token=self.aws_session_token,
|
| 450 |
+
region=self.aws_region,
|
| 451 |
+
profile=self.aws_profile,
|
| 452 |
+
data=data,
|
| 453 |
+
service_name=DEFAULT_SERVICE_NAME,
|
| 454 |
+
)
|
| 455 |
+
request.headers.update(headers)
|
| 456 |
+
|
| 457 |
+
def copy(
|
| 458 |
+
self,
|
| 459 |
+
*,
|
| 460 |
+
api_key: str | None = None,
|
| 461 |
+
aws_access_key: str | None = None,
|
| 462 |
+
aws_secret_key: str | None = None,
|
| 463 |
+
aws_session_token: str | None = None,
|
| 464 |
+
aws_region: str | None = None,
|
| 465 |
+
aws_profile: str | None = None,
|
| 466 |
+
skip_auth: bool | None = None,
|
| 467 |
+
base_url: str | httpx.URL | None = None,
|
| 468 |
+
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
|
| 469 |
+
http_client: httpx.AsyncClient | None = None,
|
| 470 |
+
max_retries: int | NotGiven = NOT_GIVEN,
|
| 471 |
+
default_headers: Mapping[str, str] | None = None,
|
| 472 |
+
set_default_headers: Mapping[str, str] | None = None,
|
| 473 |
+
default_query: Mapping[str, object] | None = None,
|
| 474 |
+
set_default_query: Mapping[str, object] | None = None,
|
| 475 |
+
_extra_kwargs: Mapping[str, Any] = {},
|
| 476 |
+
) -> Self:
|
| 477 |
+
if default_headers is not None and set_default_headers is not None:
|
| 478 |
+
raise ValueError("The `default_headers` and `set_default_headers` arguments are mutually exclusive")
|
| 479 |
+
|
| 480 |
+
if default_query is not None and set_default_query is not None:
|
| 481 |
+
raise ValueError("The `default_query` and `set_default_query` arguments are mutually exclusive")
|
| 482 |
+
|
| 483 |
+
headers = self._custom_headers
|
| 484 |
+
if default_headers is not None:
|
| 485 |
+
headers = {**headers, **default_headers}
|
| 486 |
+
elif set_default_headers is not None:
|
| 487 |
+
headers = set_default_headers
|
| 488 |
+
|
| 489 |
+
params = self._custom_query
|
| 490 |
+
if default_query is not None:
|
| 491 |
+
params = {**params, **default_query}
|
| 492 |
+
elif set_default_query is not None:
|
| 493 |
+
params = set_default_query
|
| 494 |
+
|
| 495 |
+
return self.__class__(
|
| 496 |
+
api_key=api_key or self.api_key,
|
| 497 |
+
aws_access_key=aws_access_key or self.aws_access_key,
|
| 498 |
+
aws_secret_key=aws_secret_key or self.aws_secret_key,
|
| 499 |
+
aws_session_token=aws_session_token or self.aws_session_token,
|
| 500 |
+
aws_region=aws_region or self.aws_region,
|
| 501 |
+
aws_profile=aws_profile or self.aws_profile,
|
| 502 |
+
skip_auth=skip_auth if skip_auth is not None else self.skip_auth,
|
| 503 |
+
base_url=base_url or self.base_url,
|
| 504 |
+
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
|
| 505 |
+
http_client=http_client,
|
| 506 |
+
max_retries=max_retries if is_given(max_retries) else self.max_retries,
|
| 507 |
+
default_headers=headers,
|
| 508 |
+
default_query=params,
|
| 509 |
+
**_extra_kwargs,
|
| 510 |
+
)
|
| 511 |
+
|
| 512 |
+
with_options = copy
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_stream.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TypeVar
|
| 4 |
+
|
| 5 |
+
import httpx
|
| 6 |
+
|
| 7 |
+
from ..._client import Anthropic, AsyncAnthropic
|
| 8 |
+
from ..._streaming import Stream, AsyncStream
|
| 9 |
+
from ._stream_decoder import AWSEventStreamDecoder
|
| 10 |
+
|
| 11 |
+
_T = TypeVar("_T")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class BedrockStream(Stream[_T]):
|
| 15 |
+
def __init__(
|
| 16 |
+
self,
|
| 17 |
+
*,
|
| 18 |
+
cast_to: type[_T],
|
| 19 |
+
response: httpx.Response,
|
| 20 |
+
client: Anthropic,
|
| 21 |
+
) -> None:
|
| 22 |
+
super().__init__(cast_to=cast_to, response=response, client=client)
|
| 23 |
+
|
| 24 |
+
self._decoder = AWSEventStreamDecoder()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class AsyncBedrockStream(AsyncStream[_T]):
|
| 28 |
+
def __init__(
|
| 29 |
+
self,
|
| 30 |
+
*,
|
| 31 |
+
cast_to: type[_T],
|
| 32 |
+
response: httpx.Response,
|
| 33 |
+
client: AsyncAnthropic,
|
| 34 |
+
) -> None:
|
| 35 |
+
super().__init__(cast_to=cast_to, response=response, client=client)
|
| 36 |
+
|
| 37 |
+
self._decoder = AWSEventStreamDecoder()
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/bedrock/_stream_decoder.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import TYPE_CHECKING, Iterator, AsyncIterator
|
| 4 |
+
|
| 5 |
+
from ..._utils import lru_cache
|
| 6 |
+
from ..._streaming import ServerSentEvent
|
| 7 |
+
|
| 8 |
+
if TYPE_CHECKING:
|
| 9 |
+
from botocore.model import Shape
|
| 10 |
+
from botocore.eventstream import EventStreamMessage
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@lru_cache(maxsize=None)
|
| 14 |
+
def get_response_stream_shape() -> Shape:
|
| 15 |
+
from botocore.model import ServiceModel
|
| 16 |
+
from botocore.loaders import Loader
|
| 17 |
+
|
| 18 |
+
loader = Loader()
|
| 19 |
+
bedrock_service_dict = loader.load_service_model("bedrock-runtime", "service-2")
|
| 20 |
+
bedrock_service_model = ServiceModel(bedrock_service_dict)
|
| 21 |
+
return bedrock_service_model.shape_for("ResponseStream")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class AWSEventStreamDecoder:
|
| 25 |
+
def __init__(self) -> None:
|
| 26 |
+
from botocore.parsers import EventStreamJSONParser
|
| 27 |
+
|
| 28 |
+
self.parser = EventStreamJSONParser()
|
| 29 |
+
|
| 30 |
+
def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
|
| 31 |
+
"""Given an iterator that yields lines, iterate over it & yield every event encountered"""
|
| 32 |
+
from botocore.eventstream import EventStreamBuffer
|
| 33 |
+
|
| 34 |
+
event_stream_buffer = EventStreamBuffer()
|
| 35 |
+
for chunk in iterator:
|
| 36 |
+
event_stream_buffer.add_data(chunk)
|
| 37 |
+
for event in event_stream_buffer:
|
| 38 |
+
message = self._parse_message_from_event(event)
|
| 39 |
+
if message:
|
| 40 |
+
yield ServerSentEvent(data=message, event="completion")
|
| 41 |
+
|
| 42 |
+
async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]:
|
| 43 |
+
"""Given an async iterator that yields lines, iterate over it & yield every event encountered"""
|
| 44 |
+
from botocore.eventstream import EventStreamBuffer
|
| 45 |
+
|
| 46 |
+
event_stream_buffer = EventStreamBuffer()
|
| 47 |
+
async for chunk in iterator:
|
| 48 |
+
event_stream_buffer.add_data(chunk)
|
| 49 |
+
for event in event_stream_buffer:
|
| 50 |
+
message = self._parse_message_from_event(event)
|
| 51 |
+
if message:
|
| 52 |
+
yield ServerSentEvent(data=message, event="completion")
|
| 53 |
+
|
| 54 |
+
def _parse_message_from_event(self, event: EventStreamMessage) -> str | None:
|
| 55 |
+
response_dict = event.to_response_dict()
|
| 56 |
+
parsed_response = self.parser.parse(response_dict, get_response_stream_shape())
|
| 57 |
+
if response_dict["status_code"] != 200:
|
| 58 |
+
raise ValueError(f"Bad response code, expected 200: {response_dict}")
|
| 59 |
+
|
| 60 |
+
chunk = parsed_response.get("chunk")
|
| 61 |
+
if not chunk:
|
| 62 |
+
return None
|
| 63 |
+
|
| 64 |
+
return chunk.get("bytes").decode() # type: ignore[no-any-return]
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__init__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ._auth import AccessTokenAuth as AccessTokenAuth
|
| 2 |
+
from ._cache import TokenCache as TokenCache
|
| 3 |
+
from ._chain import default_credentials as default_credentials
|
| 4 |
+
from ._types import (
|
| 5 |
+
AccessToken as AccessToken,
|
| 6 |
+
CredentialResult as CredentialResult,
|
| 7 |
+
AccessTokenProvider as AccessTokenProvider,
|
| 8 |
+
IdentityTokenProvider as IdentityTokenProvider,
|
| 9 |
+
)
|
| 10 |
+
from ._workload import (
|
| 11 |
+
WorkloadIdentityError as WorkloadIdentityError,
|
| 12 |
+
WorkloadIdentityCredentials as WorkloadIdentityCredentials,
|
| 13 |
+
exchange_federation_assertion as exchange_federation_assertion,
|
| 14 |
+
)
|
| 15 |
+
from ._providers import (
|
| 16 |
+
EnvToken as EnvToken,
|
| 17 |
+
StaticToken as StaticToken,
|
| 18 |
+
InMemoryConfig as InMemoryConfig,
|
| 19 |
+
CredentialsFile as CredentialsFile,
|
| 20 |
+
IdentityTokenFile as IdentityTokenFile,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
__all__ = [
|
| 24 |
+
"AccessToken",
|
| 25 |
+
"AccessTokenProvider",
|
| 26 |
+
"CredentialResult",
|
| 27 |
+
"IdentityTokenProvider",
|
| 28 |
+
"StaticToken",
|
| 29 |
+
"EnvToken",
|
| 30 |
+
"CredentialsFile",
|
| 31 |
+
"InMemoryConfig",
|
| 32 |
+
"IdentityTokenFile",
|
| 33 |
+
"WorkloadIdentityCredentials",
|
| 34 |
+
"WorkloadIdentityError",
|
| 35 |
+
"exchange_federation_assertion",
|
| 36 |
+
"TokenCache",
|
| 37 |
+
"AccessTokenAuth",
|
| 38 |
+
"default_credentials",
|
| 39 |
+
]
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (878 Bytes). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_auth.cpython-312.pyc
ADDED
|
Binary file (6.36 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_cache.cpython-312.pyc
ADDED
|
Binary file (7.81 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_chain.cpython-312.pyc
ADDED
|
Binary file (6.14 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_constants.cpython-312.pyc
ADDED
|
Binary file (11.6 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_providers.cpython-312.pyc
ADDED
|
Binary file (37.7 kB). View file
|
|
|
hientran/sythetic_crawl_data/crawl/lib64/python3.12/site-packages/anthropic/lib/credentials/__pycache__/_types.cpython-312.pyc
ADDED
|
Binary file (3.31 kB). View file
|
|
|