Using Opik with AWS Bedrock
Opik integrates with AWS Bedrock to provide a simple way to log traces for all Bedrock LLM calls. This works for all supported models, including if you are using the streaming API.
Creating an account on Comet.com
Comet provides a hosted version of the Opik platform, simply create an account and grab you API Key.
You can also run the Opik platform locally, see the installation guide for more information.
Preparing our environment
First, we will set up our bedrock client. Uncomment the following lines to pass AWS Credentials manually or checkout other ways of passing credentials to Boto3. You will also need to request access to the model in the UI before being able to generate text, here we are gonna use the Llama 3.2 model, you can request access to it in this page for the us-east1 region.
Logging traces
In order to log traces to Opik, we need to wrap our Bedrock calls with the track_bedrock
function:
The prompt and response messages are automatically logged to Opik and can be viewed in the UI.
Logging traces with streaming
Using it with the track
decorator
If you have multiple steps in your LLM pipeline, you can use the track
decorator to log the traces for each step. If Bedrock is called within one of these steps, the LLM call with be associated with that corresponding step:
The trace can now be viewed in the UI: