diff --git a/letta/llm_api/anthropic.py b/letta/llm_api/anthropic.py index 7013cbe6..09f6cd86 100644 --- a/letta/llm_api/anthropic.py +++ b/letta/llm_api/anthropic.py @@ -519,6 +519,7 @@ def _prepare_anthropic_request( prefix_fill: bool = True, # if true, put COT inside the tool calls instead of inside the content put_inner_thoughts_in_kwargs: bool = False, + bedrock: bool = False ) -> dict: """Prepare the request data for Anthropic API format.""" @@ -606,10 +607,11 @@ def _prepare_anthropic_request( # NOTE: cannot prefill with tools for opus: # Your API request included an `assistant` message in the final position, which would pre-fill the `assistant` response. When using tools with "claude-3-opus-20240229" if prefix_fill and not put_inner_thoughts_in_kwargs and "opus" not in data["model"]: - data["messages"].append( - # Start the thinking process for the assistant - {"role": "assistant", "content": f"<{inner_thoughts_xml_tag}>"}, - ) + if not bedrock: # not support for bedrock + data["messages"].append( + # Start the thinking process for the assistant + {"role": "assistant", "content": f"<{inner_thoughts_xml_tag}>"}, + ) # Validate max_tokens assert "max_tokens" in data, data @@ -651,13 +653,16 @@ def anthropic_bedrock_chat_completions_request( inner_thoughts_xml_tag: Optional[str] = "thinking", ) -> ChatCompletionResponse: """Make a chat completion request to Anthropic via AWS Bedrock.""" - data = _prepare_anthropic_request(data, inner_thoughts_xml_tag) + data = _prepare_anthropic_request(data, inner_thoughts_xml_tag, bedrock=True) # Get the client client = get_bedrock_client() # Make the request try: + # bedrock does not support certain args + data["tool_choice"] = {"type": "any"} + response = client.messages.create(**data) return convert_anthropic_response_to_chatcompletion(response=response, inner_thoughts_xml_tag=inner_thoughts_xml_tag) except PermissionDeniedError: diff --git a/letta/llm_api/aws_bedrock.py b/letta/llm_api/aws_bedrock.py index b3077e41..31da4619 100644 --- a/letta/llm_api/aws_bedrock.py +++ b/letta/llm_api/aws_bedrock.py @@ -10,7 +10,7 @@ def has_valid_aws_credentials() -> bool: """ Check if AWS credentials are properly configured. """ - valid_aws_credentials = os.getenv("AWS_ACCESS_KEY_ID") and os.getenv("AWS_SECRET_ACCESS_KEY") and os.getenv("AWS_REGION") + valid_aws_credentials = os.getenv("AWS_ACCESS_KEY") and os.getenv("AWS_SECRET_ACCESS_KEY") and os.getenv("AWS_REGION") return valid_aws_credentials diff --git a/letta/schemas/providers.py b/letta/schemas/providers.py index e569db04..bc11909d 100644 --- a/letta/schemas/providers.py +++ b/letta/schemas/providers.py @@ -1014,4 +1014,6 @@ class AnthropicBedrockProvider(Provider): return bedrock_get_model_context_window(model_name) def get_handle(self, model_name: str) -> str: - return f"anthropic/{model_name}" + print(model_name) + model = model_name.split(".")[-1] + return f"bedrock/{model}" diff --git a/poetry.lock b/poetry.lock index 09180909..fc13e59e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "aiohappyeyeballs" @@ -405,6 +405,44 @@ files = [ {file = "blinker-1.9.0.tar.gz", hash = "sha256:b4ce2265a7abece45e7cc896e98dbebe6cead56bcf805a3d23136d145f5445bf"}, ] +[[package]] +name = "boto3" +version = "1.36.24" +description = "The AWS SDK for Python" +optional = true +python-versions = ">=3.8" +files = [ + {file = "boto3-1.36.24-py3-none-any.whl", hash = "sha256:c9055fe6a33f79c43053c06db432092cfcf88f4b4181950f5ca8f2f0cb6abb87"}, + {file = "boto3-1.36.24.tar.gz", hash = "sha256:777ec08a6fe0ad77fa0607b431542c51d2d2e4145fecd512bee9f383ee4184f2"}, +] + +[package.dependencies] +botocore = ">=1.36.24,<1.37.0" +jmespath = ">=0.7.1,<2.0.0" +s3transfer = ">=0.11.0,<0.12.0" + +[package.extras] +crt = ["botocore[crt] (>=1.21.0,<2.0a0)"] + +[[package]] +name = "botocore" +version = "1.36.24" +description = "Low-level, data-driven core of boto 3." +optional = true +python-versions = ">=3.8" +files = [ + {file = "botocore-1.36.24-py3-none-any.whl", hash = "sha256:b8b2ad60e6545aaef3a40163793c39555fcfd67fb081a38695018026c4f4db25"}, + {file = "botocore-1.36.24.tar.gz", hash = "sha256:7d35ba92ccbed7aa7e1563b12bb339bde612d5f845c89bfdd79a6db8c26b9f2e"}, +] + +[package.dependencies] +jmespath = ">=0.7.1,<2.0.0" +python-dateutil = ">=2.1,<3.0.0" +urllib3 = {version = ">=1.25.4,<2.2.0 || >2.2.0,<3", markers = "python_version >= \"3.10\""} + +[package.extras] +crt = ["awscrt (==0.23.8)"] + [[package]] name = "brotli" version = "1.1.0" @@ -2004,13 +2042,13 @@ files = [ [[package]] name = "huggingface-hub" -version = "0.28.1" +version = "0.29.0" description = "Client library to download and publish models, datasets and other repos on the huggingface.co hub" optional = true python-versions = ">=3.8.0" files = [ - {file = "huggingface_hub-0.28.1-py3-none-any.whl", hash = "sha256:aa6b9a3ffdae939b72c464dbb0d7f99f56e649b55c3d52406f49e0a5a620c0a7"}, - {file = "huggingface_hub-0.28.1.tar.gz", hash = "sha256:893471090c98e3b6efbdfdacafe4052b20b84d59866fb6f54c33d9af18c303ae"}, + {file = "huggingface_hub-0.29.0-py3-none-any.whl", hash = "sha256:c02daa0b6bafbdacb1320fdfd1dc7151d0940825c88c4ef89837fdb1f6ea0afe"}, + {file = "huggingface_hub-0.29.0.tar.gz", hash = "sha256:64034c852be270cac16c5743fe1f659b14515a9de6342d6f42cbb2ede191fc80"}, ] [package.dependencies] @@ -2353,6 +2391,17 @@ files = [ {file = "jiter-0.8.2.tar.gz", hash = "sha256:cd73d3e740666d0e639f678adb176fad25c1bcbdae88d8d7b857e1783bb4212d"}, ] +[[package]] +name = "jmespath" +version = "1.0.1" +description = "JSON Matching Expressions" +optional = true +python-versions = ">=3.7" +files = [ + {file = "jmespath-1.0.1-py3-none-any.whl", hash = "sha256:02e2e4cc71b5bcab88332eebf907519190dd9e6e82107fa7f83b1003a6252980"}, + {file = "jmespath-1.0.1.tar.gz", hash = "sha256:90261b206d6defd58fdd5e85f478bf633a2901798906be2ad389150c5c60edbe"}, +] + [[package]] name = "joblib" version = "1.4.2" @@ -2523,21 +2572,21 @@ xai = ["langchain-xai"] [[package]] name = "langchain-community" -version = "0.3.17" +version = "0.3.18" description = "Community contributed LangChain integrations." optional = true python-versions = "<4.0,>=3.9" files = [ - {file = "langchain_community-0.3.17-py3-none-any.whl", hash = "sha256:13bbd87d681b0df67bafa294321613b13ac524f173c92f11048d40c74e585f0b"}, - {file = "langchain_community-0.3.17.tar.gz", hash = "sha256:d8547a3d4f8307950be88ca638cd6ab1abe2440d0012e401a172ba4a39aa8044"}, + {file = "langchain_community-0.3.18-py3-none-any.whl", hash = "sha256:0d4a70144a1750045c4f726f9a43379ed2484178f76e4b8295bcef3a7fdf41d5"}, + {file = "langchain_community-0.3.18.tar.gz", hash = "sha256:fa2889a8f0b2d22b5c306fd1b070c0970e1f11b604bf55fad2f4a1d0bf68a077"}, ] [package.dependencies] aiohttp = ">=3.8.3,<4.0.0" dataclasses-json = ">=0.5.7,<0.7" httpx-sse = ">=0.4.0,<1.0.0" -langchain = ">=0.3.18,<1.0.0" -langchain-core = ">=0.3.34,<1.0.0" +langchain = ">=0.3.19,<1.0.0" +langchain-core = ">=0.3.37,<1.0.0" langsmith = ">=0.1.125,<0.4" numpy = [ {version = ">=1.26.4,<2", markers = "python_version < \"3.12\""}, @@ -2551,13 +2600,13 @@ tenacity = ">=8.1.0,<8.4.0 || >8.4.0,<10" [[package]] name = "langchain-core" -version = "0.3.36" +version = "0.3.37" description = "Building applications with LLMs through composability" optional = false python-versions = "<4.0,>=3.9" files = [ - {file = "langchain_core-0.3.36-py3-none-any.whl", hash = "sha256:8410311862c7c674e4f3f120cfd8d1f3d003d6e7d8cb8f934746e222f7e865d9"}, - {file = "langchain_core-0.3.36.tar.gz", hash = "sha256:dffdce8a554905f53f33c1d6a40633a45a8d47c17c5792753891dd73941cd57a"}, + {file = "langchain_core-0.3.37-py3-none-any.whl", hash = "sha256:8202fd6506ce139a3a1b1c4c3006216b1c7fffa40bdd1779f7d2c67f75eb5f79"}, + {file = "langchain_core-0.3.37.tar.gz", hash = "sha256:cda8786e616caa2f68f7cc9e811b9b50e3b63fb2094333318b348e5961a7ea01"}, ] [package.dependencies] @@ -2646,13 +2695,13 @@ pytest = ["pytest (>=7.0.0)", "rich (>=13.9.4,<14.0.0)"] [[package]] name = "letta-client" -version = "0.1.33" +version = "0.1.39" description = "" optional = false python-versions = "<4.0,>=3.8" files = [ - {file = "letta_client-0.1.33-py3-none-any.whl", hash = "sha256:7f10413164ae4b22f6b09fb75149c6313fae81e7dbd6fc705ff6b8078cbe8ae5"}, - {file = "letta_client-0.1.33.tar.gz", hash = "sha256:eada44fbd2a84bcb801025888badd0fc785e34915d85e892ee462c23bd26c9f5"}, + {file = "letta_client-0.1.39-py3-none-any.whl", hash = "sha256:0644643031f45ca6306e9690f9c75c8077e1d66a9b0247cbf45e018e13313312"}, + {file = "letta_client-0.1.39.tar.gz", hash = "sha256:d4ac3aef4c6b33a6281df3751a2b9279c91448ebd75f55f0304c605317aa938a"}, ] [package.dependencies] @@ -2664,13 +2713,13 @@ typing_extensions = ">=4.0.0" [[package]] name = "llama-cloud" -version = "0.1.12" +version = "0.1.13" description = "" optional = false python-versions = "<4,>=3.8" files = [ - {file = "llama_cloud-0.1.12-py3-none-any.whl", hash = "sha256:de1b4f89afc3cf3adf86ca9a6eb2b8de3f131b20fd25a5647b5a162e6bf2ed1b"}, - {file = "llama_cloud-0.1.12.tar.gz", hash = "sha256:d51d26cc4c542398a3490813bc791f7504a40298225e62ed918951bf57266e2a"}, + {file = "llama_cloud-0.1.13-py3-none-any.whl", hash = "sha256:c36d9e9288cb7298faae68797f9789615b7c72409af8f3315e3098a479c09e17"}, + {file = "llama_cloud-0.1.13.tar.gz", hash = "sha256:cb6522fbd0f5e4c1cd2825e70bb943d0d8916816e232a5ce3be3a7272f329a8c"}, ] [package.dependencies] @@ -4287,6 +4336,7 @@ files = [ {file = "psycopg2-2.9.10-cp311-cp311-win_amd64.whl", hash = "sha256:0435034157049f6846e95103bd8f5a668788dd913a7c30162ca9503fdf542cb4"}, {file = "psycopg2-2.9.10-cp312-cp312-win32.whl", hash = "sha256:65a63d7ab0e067e2cdb3cf266de39663203d38d6a8ed97f5ca0cb315c73fe067"}, {file = "psycopg2-2.9.10-cp312-cp312-win_amd64.whl", hash = "sha256:4a579d6243da40a7b3182e0430493dbd55950c493d8c68f4eec0b302f6bbf20e"}, + {file = "psycopg2-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:91fd603a2155da8d0cfcdbf8ab24a2d54bca72795b90d2a3ed2b6da8d979dee2"}, {file = "psycopg2-2.9.10-cp39-cp39-win32.whl", hash = "sha256:9d5b3b94b79a844a986d029eee38998232451119ad653aea42bb9220a8c5066b"}, {file = "psycopg2-2.9.10-cp39-cp39-win_amd64.whl", hash = "sha256:88138c8dedcbfa96408023ea2b0c369eda40fe5d75002c0964c78f46f11fa442"}, {file = "psycopg2-2.9.10.tar.gz", hash = "sha256:12ec0b40b0273f95296233e8750441339298e6a572f7039da5b260e3c8b60e11"}, @@ -4346,6 +4396,7 @@ files = [ {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:bb89f0a835bcfc1d42ccd5f41f04870c1b936d8507c6df12b7737febc40f0909"}, {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:f0c2d907a1e102526dd2986df638343388b94c33860ff3bbe1384130828714b1"}, {file = "psycopg2_binary-2.9.10-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:f8157bed2f51db683f31306aa497311b560f2265998122abe1dce6428bd86567"}, + {file = "psycopg2_binary-2.9.10-cp313-cp313-win_amd64.whl", hash = "sha256:27422aa5f11fbcd9b18da48373eb67081243662f9b46e6fd07c3eb46e4535142"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-macosx_12_0_x86_64.whl", hash = "sha256:eb09aa7f9cecb45027683bb55aebaaf45a0df8bf6de68801a6afdc7947bb09d4"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b73d6d7f0ccdad7bc43e6d34273f70d587ef62f824d7261c4ae9b8b1b6af90e8"}, {file = "psycopg2_binary-2.9.10-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ce5ab4bf46a211a8e924d307c1b1fcda82368586a19d0a24f8ae166f5c784864"}, @@ -5485,6 +5536,23 @@ files = [ [package.dependencies] pyasn1 = ">=0.1.3" +[[package]] +name = "s3transfer" +version = "0.11.2" +description = "An Amazon S3 Transfer Manager" +optional = true +python-versions = ">=3.8" +files = [ + {file = "s3transfer-0.11.2-py3-none-any.whl", hash = "sha256:be6ecb39fadd986ef1701097771f87e4d2f821f27f6071c872143884d2950fbc"}, + {file = "s3transfer-0.11.2.tar.gz", hash = "sha256:3b39185cb72f5acc77db1a58b6e25b977f28d20496b6e58d6813d75f464d632f"}, +] + +[package.dependencies] +botocore = ">=1.36.0,<2.0a.0" + +[package.extras] +crt = ["botocore[crt] (>=1.36.0,<2.0a.0)"] + [[package]] name = "scramp" version = "1.4.5" @@ -6784,7 +6852,7 @@ cffi = ["cffi (>=1.11)"] [extras] all = ["autoflake", "black", "datasets", "docker", "fastapi", "isort", "langchain", "langchain-community", "locust", "pexpect", "pg8000", "pgvector", "pre-commit", "psycopg2", "psycopg2-binary", "pyright", "pytest-asyncio", "pytest-order", "uvicorn", "wikipedia"] -bedrock = [] +bedrock = ["boto3"] cloud-tool-sandbox = ["e2b-code-interpreter"] dev = ["autoflake", "black", "datasets", "isort", "locust", "pexpect", "pre-commit", "pyright", "pytest-asyncio", "pytest-order"] external-tools = ["docker", "langchain", "langchain-community", "wikipedia"] @@ -6797,4 +6865,4 @@ tests = ["wikipedia"] [metadata] lock-version = "2.0" python-versions = "<3.14,>=3.10" -content-hash = "7f256d27a3441c2d32a8597f8ec807364f85d15b160b67dfa5959693c1ddbf8b" +content-hash = "55cce79796d9e1265865b8bfc9a5b4aaa959705401054553b8bf39fe2f5c27f9" diff --git a/pyproject.toml b/pyproject.toml index 836b3b16..8673cfa0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,6 +86,7 @@ google-genai = {version = "^1.1.0", optional = true} faker = "^36.1.0" colorama = "^0.4.6" marshmallow-sqlalchemy = "^1.4.1" +boto3 = {version = "^1.36.24", optional = true} [tool.poetry.extras]