mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(bedrock): route async_invoke embeddings whether the region comes before or after it
This commit is contained in:
parent
4470033ccd
commit
3a5fdc0c3c
2 changed files with 15 additions and 7 deletions
|
|
@ -430,8 +430,10 @@ class BedrockEmbedding(BaseAWSLLM):
|
|||
api_key: str | None = None,
|
||||
) -> EmbeddingResponse:
|
||||
model_id_param: Final = _OPTIONAL_STR.validate_python(optional_params.pop("model_id", None)) or None
|
||||
path_region: Final = split_bedrock_region_path(model)[0] if model_id_param is None else None
|
||||
model_path: Final = _without_region_path(model)
|
||||
has_async_invoke: Final = "async_invoke/" in model
|
||||
model_without_async_route: Final = model.replace("async_invoke/", "", 1)
|
||||
path_region: Final = split_bedrock_region_path(model_without_async_route)[0] if model_id_param is None else None
|
||||
bedrock_model: Final = _without_region_path(model_without_async_route)
|
||||
credentials, aws_region_name = self._load_credentials(
|
||||
optional_params,
|
||||
bearer_token=bedrock_bearer_token(api_key),
|
||||
|
|
@ -439,15 +441,13 @@ class BedrockEmbedding(BaseAWSLLM):
|
|||
)
|
||||
|
||||
### TRANSFORMATION ###
|
||||
unencoded_model_id: Final = model_id_param or model_path
|
||||
unencoded_model_id: Final = model_id_param or bedrock_model
|
||||
modelId: Final = urllib.parse.quote(unencoded_model_id, safe="")
|
||||
aws_region_name = self._get_aws_region_name(
|
||||
optional_params={"aws_region_name": aws_region_name},
|
||||
model=model_path,
|
||||
model=bedrock_model,
|
||||
model_id=unencoded_model_id,
|
||||
)
|
||||
has_async_invoke: Final = "async_invoke/" in model_path
|
||||
bedrock_model: Final = model_path.replace("async_invoke/", "", 1)
|
||||
response_model: Final = _response_model(model, path_region, aws_region_name, bedrock_model)
|
||||
provider: Final = self.get_bedrock_embedding_provider(bedrock_model)
|
||||
if provider is None:
|
||||
|
|
|
|||
|
|
@ -331,8 +331,16 @@ def test_bedrock_embedding_explicit_region_outside_the_known_list_returns_the_ve
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
[
|
||||
"bedrock/us-gov-west-1/async_invoke/amazon.nova-2-multimodal-embeddings-v1:0",
|
||||
"bedrock/async_invoke/us-gov-west-1/amazon.nova-2-multimodal-embeddings-v1:0",
|
||||
],
|
||||
)
|
||||
def test_bedrock_async_invoke_embedding_with_a_region_path_posts_the_bare_id_to_that_region(
|
||||
respx_mock: respx.MockRouter,
|
||||
model: str,
|
||||
) -> None:
|
||||
route = respx_mock.post(f"{GOVCLOUD_WEST_RUNTIME}/async-invoke").mock(
|
||||
return_value=httpx.Response(
|
||||
|
|
@ -341,7 +349,7 @@ def test_bedrock_async_invoke_embedding_with_a_region_path_posts_the_bare_id_to_
|
|||
)
|
||||
|
||||
litellm.embedding(
|
||||
model="bedrock/us-gov-west-1/async_invoke/amazon.nova-2-multimodal-embeddings-v1:0",
|
||||
model=model,
|
||||
input=[test_input],
|
||||
api_key="test-bearer-token",
|
||||
output_s3_uri="s3://test-bucket/async-invoke-output/",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue