aider icon indicating copy to clipboard operation
aider copied to clipboard

Claude Sonnet 3.5 V2 not working with AWS Bedrock

Open KoStard opened this issue 2 years ago • 28 comments

Issue

aider --model 'anthropic.claude-3-5-sonnet-20241022-v2:0'
/ask hello


Tokens: 2.0k sent, 0 received. Cost: $0.0060 message, 
$0.0060 session.

and similar commands seem to just wait for the response but doesn't actually show one.

With the older version it works correctly:

aider --model anthropic.claude-3-5-sonnet-20240620-v1:0
> /ask hello                                           

Hello! How can I assist you with the code in your git  
repository today? Is there a specific question you have
about any of the files or functionality?               


Tokens: 2.0k sent, 31 received. Cost: $0.0064 message, 
$0.0064 session.

I updated aider-chat and litellm.

Version and model info

Model: anthropic.claude-3-5-sonnet-20241022-v2:0 with diff edit format, infinite output Git repo: .git with 111 files Repo-map: using 1024 tokens, auto refresh VSCode terminal detected, pretty output has been disabled.

KoStard avatar Oct 22 '24 20:10 KoStard

Thanks for trying aider and filing this issue.

Don't update litellm. Aider pins its versions to work with known, tested versions of the required packages.

https://aider.chat/docs/troubleshooting/imports.html

Try a clean install and see if it works better for you.

paul-gauthier avatar Oct 22 '24 20:10 paul-gauthier

Hi Paul :)

I am using Aider v0.60.0 Older Claude 3.5 models work without problem (bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0 and bedrock/us.anthropic.claude-3-5-sonnet-20240620-v1:0 are OK.)

However, no joy with the new models.

> /model bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0

Warning: bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0 expects these environment variables
- AWS_ACCESS_KEY_ID: Not set
- AWS_SECRET_ACCESS_KEY: Not set
If you just set these environment variables using `setx` you may need to restart your terminal or command prompt for the changes to take
effect.
For more info, see: https://aider.chat/docs/llms/warnings.html
Aider v0.60.0
Model: bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0 with diff edit format
Git repo: .git with 143 files
Repo-map: using 1024 tokens, auto refresh
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> /ask What does this do?



Tokens: 2.5k sent, 0 received. Cost: $0.0074 message, $0.10 session.

I am picking up credentials from AWS CLI as a fall-back rather than specifying environmental variables, so you can ignore the credentials warning.

> /model bedrock/us.anthropic.claude-3-5-sonnet-20241022-v2:0

Warning: bedrock/us.anthropic.claude-3-5-sonnet-20241022-v2:0 expects these environment variables
- AWS_ACCESS_KEY_ID: Not set
- AWS_SECRET_ACCESS_KEY: Not set
If you just set these environment variables using `setx` you may need to restart your terminal or command prompt for the changes to take
effect.
For more info, see: https://aider.chat/docs/llms/warnings.html
Aider v0.60.0
Model: bedrock/us.anthropic.claude-3-5-sonnet-20241022-v2:0 with diff edit format
Git repo: .git with 143 files
Repo-map: using 1024 tokens, auto refresh
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> /ask What does this do?

Unexpected error: litellm.NotFoundError: BedrockException - Bedrock HTTPX: Unknown provider=us,
model=us.anthropic.claude-3-5-sonnet-20241022-v2:0
Traceback (most recent call last):
  File "/Users/********/.local/pipx/venvs/aider-chat/lib/python3.12/site-packages/litellm/main.py", line 2430, in completion
    response = bedrock_chat_completion.completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/********/.local/pipx/venvs/aider-chat/lib/python3.12/site-packages/litellm/llms/bedrock/chat/invoke_handler.py", line 811, in
completion
    raise BedrockError(
litellm.llms.bedrock.common_utils.BedrockError: Bedrock HTTPX: Unknown provider=us, model=us.anthropic.claude-3-5-sonnet-20241022-v2:0

ilyagvoz avatar Oct 23 '24 05:10 ilyagvoz

Worth calling out that I do have access to the underlying model in Bedrock:

{
            "modelArn": "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0",
            "modelId": "anthropic.claude-3-5-sonnet-20241022-v2:0",
            "modelName": "Claude 3.5 Sonnet v2",
            "providerName": "Anthropic",
            "inputModalities": [
                "TEXT",
                "IMAGE"
            ],
            "outputModalities": [
                "TEXT"
            ],
            "responseStreamingSupported": true,
            "customizationsSupported": [],
            "inferenceTypesSupported": [
                "ON_DEMAND"
            ],
            "modelLifecycle": {
                "**status": "ACTIVE"**
            }
        },

ilyagvoz avatar Oct 23 '24 05:10 ilyagvoz

pip uninstall litellm
pip uninstall aider-chat
pip install aider-chat

Same issue

KoStard avatar Oct 23 '24 10:10 KoStard

anyone encountered this issue in Bedrock? litellm.RateLimitError: BedrockException - b'{"message":"Too many requests, please wait before trying again."} image

00010110 avatar Oct 23 '24 10:10 00010110

Encountering the same issue with new the Sonnet model. Aider version is v0.60.0

Screenshot 2024-10-24 at 1 00 49 PM

cagdas1 avatar Oct 24 '24 17:10 cagdas1

I had the same issue, and confirmed the new model is working in AWS playground.

  • Tried to update the model settings, and aider. Tested the latest dev version also
  • Remove / reinstalled litellm and aider-chat.

What was working is unfortunately to upgrade litellm.

pip install -U litellm

xcke avatar Oct 25 '24 12:10 xcke

It would be great if we could relax the version constraints on litellm & openai a bit to enable that- I'm currently cloning the repo and modifying requirements.txt to change versions

lattwood avatar Oct 25 '24 13:10 lattwood

Yeah, I cloned locally, bumped openai & litellm to latest, and it's now working with the latest claude 3.5 on bedrock.

lattwood avatar Oct 25 '24 13:10 lattwood

Thanks for tracking this down. I am not set up on Bedrock, so it's not easy for me to test this myself.

I also don't see any Bedrock/Sonnet issues in the litellm github, so it's not clear that there was something explicitly fixed for this.

I just bumped the litellm version that aider uses to litellm==1.50.4. They have been doing some refactoring, so I was holding off.

CC: @ishaan-jaff

The change is available in the main branch. You can get it by installing the latest version from github:

aider --install-main-branch

# or...

python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git

If you have a chance to try it, let me know if it works better for you.

paul-gauthier avatar Oct 25 '24 13:10 paul-gauthier

I think it was this commit specifically in litellm that's needed- https://github.com/BerriAI/litellm/commit/7939e930ff5b6451a03f1a7ee7c6a92e0704568c

lattwood avatar Oct 25 '24 14:10 lattwood

Also just filed this issue on litellm that will warrant a timely version upgrade-

https://github.com/BerriAI/litellm/issues/6437

they don't enable assistant prefill for claude on bedrock

lattwood avatar Oct 25 '24 14:10 lattwood

If it works with aider via a .aider.model.metadata.json file update, then aider will just pick up an updated json metadata file from litellm without the need for a litellm version bump.

paul-gauthier avatar Oct 25 '24 14:10 paul-gauthier

Litellm keeps moving around where to import AnthropicError. The bump to 1.50.4 moved it to litellm.llms.anthropic.common_utils.AnthropicError.

Has been in these places previously:

litellm.llms.anthropic.common_utils.AnthropicError
litellm.llms.anthropic.chat.AnthropicError
litellm.llms.anthropic.AnthropicError

This is one reason why I am slow to bump litellm, since things shift around often.

But maybe there is a stable place to import it from that I am unaware of?

paul-gauthier avatar Oct 25 '24 14:10 paul-gauthier

They have two definitions 🤦🏻‍♂️ https://github.com/search?q=repo%3ABerriAI%2Flitellm%20AnthropicError&type=code

lattwood avatar Oct 25 '24 14:10 lattwood

Actually, they use the same Exception name for different exceptions 🤦🏻

lattwood avatar Oct 25 '24 14:10 lattwood

aider --install-main-branch worked for me. The new 0.60.1 version still had the issue.

xerebz avatar Oct 25 '24 18:10 xerebz

hey @paul-gauthier acknowledging this. We didn't intend our internal llm exceptions to be publicly used

Can you point me to how these are being used? Our internal llm exceptions -> run through our exception mapping which outputs standard OpenAI-compatible exceptions - https://github.com/BerriAI/litellm/blob/81157aa13593a02e8d34ec1ef47a777f347a5b68/litellm/init.py#L1035

ghost avatar Oct 25 '24 18:10 ghost

Is that the list of exceptions I should be catching? I feel like I was at one point receiving bare AnthropicError exceptions from litellm, so started catching that explicitly. Sounds like I should not be seeing any of those?

paul-gauthier avatar Oct 25 '24 19:10 paul-gauthier

Yea you should never be seeing any of those, if it's unmapped we default to APIConnectionError, which seems to be the openai default as well - https://docs.litellm.ai/docs/exception_mapping

How can we do better here? @paul-gauthier

ghost avatar Oct 25 '24 19:10 ghost