-
Notifications
You must be signed in to change notification settings - Fork 839
fix(bedrock): Add prompt caching support for Converse API #3390
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
ff8e343
83bdb0b
4fa3792
c8abf60
7d65ff8
6cf3366
a3c94e3
277499e
979db5d
1965083
750a59e
d4c2ca6
419ae0f
440295c
a5563d5
771b5d5
ea2b0da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||||||
| from opentelemetry.instrumentation.bedrock import PromptCaching | ||||||||||||||||||||||||||||||
| from opentelemetry.instrumentation.bedrock.prompt_caching import CacheSpanAttrs | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def call(brt): | ||||||||||||||||||||||||||||||
| return brt.converse( | ||||||||||||||||||||||||||||||
| modelId="anthropic.claude-3-haiku-20240307-v1:0", | ||||||||||||||||||||||||||||||
| messages=[ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "role": "user", | ||||||||||||||||||||||||||||||
| "content": [ | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "text": "What is the capital of the USA?", | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| inferenceConfig={"maxTokens": 50, "temperature": 0.1}, | ||||||||||||||||||||||||||||||
| additionalModelRequestFields={"cacheControl": {"type": "ephemeral"}}, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def get_metric(resource_metrics, name): | ||||||||||||||||||||||||||||||
| for rm in resource_metrics: | ||||||||||||||||||||||||||||||
| for sm in rm.scope_metrics: | ||||||||||||||||||||||||||||||
| for metric in sm.metrics: | ||||||||||||||||||||||||||||||
| if metric.name == name: | ||||||||||||||||||||||||||||||
| return metric | ||||||||||||||||||||||||||||||
| raise Exception(f"No metric found with name {name}") | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| def get_metric(resource_metrics, name): | |
| for rm in resource_metrics: | |
| for sm in rm.scope_metrics: | |
| for metric in sm.metrics: | |
| if metric.name == name: | |
| return metric | |
| raise Exception(f"No metric found with name {name}") | |
| def get_metric(resource_metrics, name): | |
| for rm in resource_metrics: | |
| for sm in rm.scope_metrics: | |
| for metric in sm.metrics: | |
| if metric.name == name: | |
| return metric | |
| raise AssertionError(f"No metric found with name {name}") |
🧰 Tools
🪛 Ruff (0.14.2)
30-30: Create your own exception
(TRY002)
30-30: Avoid specifying long messages outside the exception class
(TRY003)
🤖 Prompt for AI Agents
In
packages/opentelemetry-instrumentation-bedrock/tests/metrics/test_bedrock_converse_prompt_caching_metrics.py
around lines 24 to 30, the helper raises a generic Exception when a metric is
not found; change it to raise an AssertionError (or use assert False) with the
same message so test failures surface as assertion failures. Update the raise
statement accordingly and keep the message f"No metric found with name {name}"
intact.
Uh oh!
There was an error while loading. Please reload this page.