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

fix(botocore): bedrock cross-region inference model name does not throw [backport 2.13] #10965

Open
wants to merge 2 commits into
base: 2.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ddtrace/contrib/internal/botocore/services/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ def handle_bedrock_response(
def patched_bedrock_api_call(original_func, instance, args, kwargs, function_vars):
params = function_vars.get("params")
pin = function_vars.get("pin")
model_provider, model_name = params.get("modelId").split(".")
model_meta = params.get("modelId").split(".")
if len(model_meta) == 2:
model_provider, model_name = model_meta
else:
_, model_provider, model_name = model_meta # cross-region inference
integration = function_vars.get("integration")
submit_to_llmobs = integration.llmobs_enabled and "embed" not in model_name
with core.context_with_data(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
botocore: fixes bedrock model and model provider interpretation from ``modelId`` when using cross-region inference.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interactions:
- !!binary |
YXR0ZW1wdD0x
method: POST
uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/invoke
uri: https://bedrock-runtime.us-east-1.amazonaws.com/model/us.anthropic.claude-3-sonnet-20240229-v1%3A0/invoke
response:
body:
string: '{"id":"msg_01E6sPP1ksqicYCaBrkvzna8","type":"message","role":"assistant","content":[{"type":"text","text":"Hobbits
Expand Down
1 change: 1 addition & 0 deletions tests/contrib/botocore/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def test_anthropic_invoke(bedrock_client, request_vcr):
@pytest.mark.snapshot
def test_anthropic_message_invoke(bedrock_client, request_vcr):
body, model = json.dumps(_REQUEST_BODIES["anthropic_message"]), _MODELS["anthropic_message"]
model = "us." + model
with request_vcr.use_cassette("anthropic_message_invoke.yaml"):
response = bedrock_client.invoke_model(body=body, modelId=model)
json.loads(response.get("body").read())
Expand Down
4 changes: 4 additions & 0 deletions tests/contrib/botocore/test_bedrock_llmobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def _test_llmobs_invoke(cls, provider, bedrock_client, mock_llmobs_span_writer,
}
with get_request_vcr().use_cassette(cassette_name):
body, model = json.dumps(body), _MODELS[provider]
if provider == "anthropic_message":
# we do this to re-use a cassette which tests
# cross-region inference
model = "us." + model
response = bedrock_client.invoke_model(body=body, modelId=model)
json.loads(response.get("body").read())
span = mock_tracer.pop_traces()[0][0]
Expand Down
Loading