mirror of
https://github.com/cline/cline.git
synced 2025-06-03 03:59:07 +00:00
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import AnthropicBedrock from "@anthropic-ai/bedrock-sdk"
|
|
import { Anthropic } from "@anthropic-ai/sdk"
|
|
import { ApiHandlerOptions } from "../shared/api"
|
|
import { ApiHandler } 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<Anthropic.Messages.Message> {
|
|
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" },
|
|
})
|
|
}
|
|
}
|