Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bedrock modelId encoding for Inference Profiles #9123

Conversation

omrishiv
Copy link
Contributor

@omrishiv omrishiv commented Mar 11, 2025

Title

Make sure to encode bedrock models if they are used as the modelId

Relevant issues

Fixes #8911

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on (make test-unit)[https://docs.litellm.ai/docs/extras/contributing_code]
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix
✅ Test

Changes

Encodes the model if it is being used as the modelid

Screenshot 2025-03-10 at 8 35 38 PM

Sorry, something went wrong.

Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com>
Copy link

vercel bot commented Mar 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 11, 2025 3:58pm

@omrishiv omrishiv changed the title 8911 fix model encoding Fixes bedrock modelId encoding for Inference Profiles Mar 11, 2025
Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work for litellm.completion and litellm.acompletion ?

Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed

import litellm


def test_encode_model_id_with_inference_profile():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a mock e2e test for completion(), you can mock the http response, test_bedrock_completion.py has some examples

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand, this is addressing an incorrect url encoding. I am happy to update the now failing tests that are asserting the incorrect url. Does that work?

@@ -274,7 +274,7 @@ def completion( # noqa: PLR0915
if modelId is not None:
modelId = self.encode_model_id(model_id=modelId)
else:
modelId = model
modelId = self.encode_model_id(model_id=model)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I pass model = "us.anthropicxxx" would that get encoded too? Is that intended ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use us.amazon.nova-pro-v1:0 it still works

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it get encoded too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im concerned doing this for all models might have an un-intended side effect. What do you think @omrishiv ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like boto3 actually encodes all the requests:

https://bedrock-runtime.us-east-1.amazonaws.com/model/bedrock%2Fus.meta.llama3-3-70b-instruct-v1%3A0/invoke

This will require updating a lot of the asserts on the tests to update the expected URL, is that ok?

@omrishiv
Copy link
Contributor Author

does this work for litellm.completion and litellm.acompletion ?

It does work with both completion and acompletion

Copy link
Contributor

@ishaan-jaff ishaan-jaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can this be added to docs https://docs.litellm.ai/docs/providers/bedrock

@omrishiv
Copy link
Contributor Author

also can this be added to docs https://docs.litellm.ai/docs/providers/bedrock

Do you mean using the instance profile? I'm not sure what needs to be updated? This is just properly conforming the url encoding

@omrishiv
Copy link
Contributor Author

@ishaan-jaff @krrishdholakia , please take a look, as discussed, I think this is ready

@krrishdholakia krrishdholakia changed the base branch from main to litellm_dev_03_12_2025_contributor_prs_p2 March 13, 2025 17:42
@krrishdholakia krrishdholakia merged commit 2c011d9 into BerriAI:litellm_dev_03_12_2025_contributor_prs_p2 Mar 13, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Litellm does not work with AWS Bedrock Application Inference profiles
3 participants