From 12e730885bd3948543dca902293f461c1bc4fb60 Mon Sep 17 00:00:00 2001 From: omrishiv <327609+omrishiv@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:14:35 -0700 Subject: [PATCH 1/4] encode bedrock model id Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com> --- litellm/llms/bedrock/chat/converse_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/llms/bedrock/chat/converse_handler.py b/litellm/llms/bedrock/chat/converse_handler.py index b70c15b3e1f..d45ab40c4bd 100644 --- a/litellm/llms/bedrock/chat/converse_handler.py +++ b/litellm/llms/bedrock/chat/converse_handler.py @@ -274,7 +274,7 @@ class BedrockConverseLLM(BaseAWSLLM): if modelId is not None: modelId = self.encode_model_id(model_id=modelId) else: - modelId = model + modelId = self.encode_model_id(model_id=model) if stream is True and "ai21" in modelId: fake_stream = True From 338722beba2b1ad2ec31af677910904f177455b2 Mon Sep 17 00:00:00 2001 From: omrishiv <327609+omrishiv@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:28:55 -0700 Subject: [PATCH 2/4] add test Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com> --- .../llms/chat/test_converse_handler.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/litellm/llms/chat/test_converse_handler.py diff --git a/tests/litellm/llms/chat/test_converse_handler.py b/tests/litellm/llms/chat/test_converse_handler.py new file mode 100644 index 00000000000..0b19ca11471 --- /dev/null +++ b/tests/litellm/llms/chat/test_converse_handler.py @@ -0,0 +1,19 @@ +import os +import sys + +from litellm.llms.bedrock.chat import BedrockConverseLLM + +sys.path.insert( + 0, os.path.abspath("../../../../..") +) # Adds the parent directory to the system path +import litellm + +def test_encode_model_id_with_inference_profile(): + """ + Tests to make sure model name is being escaped correctly when used with an inference profile + :return: + """ + test = "bedrock/converse/arn:aws:bedrock:us-east-1:12345678910:application-inference-profile/ujdtmcirjhevpi" + expected = "bedrock/converse/arn%3Aaws%3Abedrock%3Aus-east-1%3A12345678910%3Aapplication-inference-profile%2Fujdtmcirjhevpi" + got = BedrockConverseLLM.encode_model_id(test) + assert expected == got From d25693b96cecddc4c3ebdc38eb4e61337b1345cc Mon Sep 17 00:00:00 2001 From: omrishiv <327609+omrishiv@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:34:52 -0700 Subject: [PATCH 3/4] update test Signed-off-by: omrishiv <327609+omrishiv@users.noreply.github.com> --- tests/litellm/llms/chat/test_converse_handler.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/litellm/llms/chat/test_converse_handler.py b/tests/litellm/llms/chat/test_converse_handler.py index 0b19ca11471..9d8371c04da 100644 --- a/tests/litellm/llms/chat/test_converse_handler.py +++ b/tests/litellm/llms/chat/test_converse_handler.py @@ -8,12 +8,13 @@ sys.path.insert( ) # Adds the parent directory to the system path import litellm + def test_encode_model_id_with_inference_profile(): """ - Tests to make sure model name is being escaped correctly when used with an inference profile - :return: + Test instance profile is properly encoded when used as a model """ - test = "bedrock/converse/arn:aws:bedrock:us-east-1:12345678910:application-inference-profile/ujdtmcirjhevpi" - expected = "bedrock/converse/arn%3Aaws%3Abedrock%3Aus-east-1%3A12345678910%3Aapplication-inference-profile%2Fujdtmcirjhevpi" - got = BedrockConverseLLM.encode_model_id(test) - assert expected == got + test_model = "arn:aws:bedrock:us-east-1:12345678910:application-inference-profile/ujdtmcirjhevpi" + expected_model = "arn%3Aaws%3Abedrock%3Aus-east-1%3A12345678910%3Aapplication-inference-profile%2Fujdtmcirjhevpi" + bedrock_converse_llm = BedrockConverseLLM() + returned_model = bedrock_converse_llm.encode_model_id(test_model) + assert expected_model == returned_model From cf8084b5f91a513801d7a96260fc2217a0d7ad52 Mon Sep 17 00:00:00 2001 From: omrishiv <327609+omrishiv@users.noreply.github.com> Date: Tue, 11 Mar 2025 08:57:05 -0700 Subject: [PATCH 4/4] fix encoding in tests --- tests/llm_translation/test_bedrock_completion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/llm_translation/test_bedrock_completion.py b/tests/llm_translation/test_bedrock_completion.py index e2948789fcb..602992aee84 100644 --- a/tests/llm_translation/test_bedrock_completion.py +++ b/tests/llm_translation/test_bedrock_completion.py @@ -983,7 +983,7 @@ async def test_bedrock_custom_api_base(): print(f"mock_client_post.call_args.kwargs: {mock_client_post.call_args.kwargs}") assert ( mock_client_post.call_args.kwargs["url"] - == "https://gateway.ai.cloudflare.com/v1/fa4cdcab1f32b95ca3b53fd36043d691/test/aws-bedrock/bedrock-runtime/us-east-1/model/anthropic.claude-3-sonnet-20240229-v1:0/converse" + == "https://gateway.ai.cloudflare.com/v1/fa4cdcab1f32b95ca3b53fd36043d691/test/aws-bedrock/bedrock-runtime/us-east-1/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse" ) assert "test" in mock_client_post.call_args.kwargs["headers"] assert mock_client_post.call_args.kwargs["headers"]["test"] == "hello world" @@ -2382,7 +2382,7 @@ def test_bedrock_cross_region_inference(monkeypatch): assert ( mock_post.call_args.kwargs["url"] - == "https://bedrock-runtime.us-west-2.amazonaws.com/model/us.meta.llama3-3-70b-instruct-v1:0/converse" + == "https://bedrock-runtime.us-west-2.amazonaws.com/model/us.meta.llama3-3-70b-instruct-v1%3A0/converse" )