import AnthropicBedrock from "@anthropic-ai/bedrock-sdk" import { Anthropic } from "@anthropic-ai/sdk" import { ApiHandlerOptions } from "../shared/api" import { ApiHandler, withoutImageData } from "." // https://docs.anthropic.com/en/api/claude-on-amazon-bedrock export class AwsBedrockHandler implements ApiHandler { private options: ApiHandlerOptions private client: AnthropicBedrock constructor(options: ApiHandlerOptions) { this.options = options this.client = new AnthropicBedrock({ // Authenticate by either providing the keys below or use the default AWS credential providers, such as // using ~/.aws/credentials or the "AWS_SECRET_ACCESS_KEY" and "AWS_ACCESS_KEY_ID" environment variables. awsAccessKey: this.options.awsAccessKey, awsSecretKey: this.options.awsSecretKey, // awsRegion changes the aws region to which the request is made. By default, we read AWS_REGION, // and if that's not present, we default to us-east-1. Note that we do not read ~/.aws/config for the region. awsRegion: this.options.awsRegion, }) } async createMessage( systemPrompt: string, messages: Anthropic.Messages.MessageParam[], tools: Anthropic.Messages.Tool[] ): Promise { return await this.client.messages.create({ model: "anthropic.claude-3-5-sonnet-20240620-v1:0", max_tokens: 4096, system: systemPrompt, messages, tools, tool_choice: { type: "auto" }, }) } createUserReadableRequest( userContent: Array< | Anthropic.TextBlockParam | Anthropic.ImageBlockParam | Anthropic.ToolUseBlockParam | Anthropic.ToolResultBlockParam > ): any { return { model: "anthropic.claude-3-5-sonnet-20240620-v1:0", max_tokens: 4096, system: "(see SYSTEM_PROMPT in src/ClaudeDev.ts)", messages: [{ conversation_history: "..." }, { role: "user", content: withoutImageData(userContent) }], tools: "(see tools in src/ClaudeDev.ts)", tool_choice: { type: "auto" }, } } }