pip install traceAI-bedrock pip install boto3
import os os.environ["AWS_ACCESS_KEY_ID"] = "your-aws-access-key-id" os.environ["AWS_SECRET_ACCESS_KEY"] = "your-aws-secret-access-key" os.environ["FI_API_KEY"] = "your-futureagi-api-key" os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"
from fi_instrumentation import register from fi_instrumentation.fi_types import ProjectType trace_provider = register( project_type=ProjectType.OBSERVE, project_name="bedrock_project", )
from traceai_bedrock import BedrockInstrumentor BedrockInstrumentor().instrument(tracer_provider=trace_provider)
import boto3 client = boto3.client( service_name="bedrock", region_name="your-region", aws_access_key_id=os.environ["AWS_ACCESS_KEY_ID"], aws_secret_access_key=os.environ["AWS_SECRET_ACCESS_KEY"], )
def converse_with_claude(): system_prompt = [{"text": "You are an expert at creating music playlists"}] messages = [ { "role": "user", "content": [{"text": "Hello, how are you?"}, {"text": "What's your name?"}], } ] inference_config = {"maxTokens": 1024, "temperature": 0.0} try: response = client.converse( modelId="model_id", system=system_prompt, messages=messages, inferenceConfig=inference_config, ) out = response["output"]["message"] messages.append(out) print(out) except Exception as e: print(f"Error: {str(e)}") if __name__ == "__main__": converse_with_claude()
Was this page helpful?