AIGNE AWS Bedrock SDK for integrating with AWS foundation models within the AIGNE Framework.
@aigne/bedrock provides a seamless integration between the AIGNE Framework and AWS Bedrock foundation models. This package enables developers to easily leverage various AI models available through AWS Bedrock in their AIGNE applications, providing a consistent interface across the framework while taking advantage of AWS's secure and scalable infrastructure.
- AWS Bedrock Integration: Direct connection to AWS Bedrock services using the official AWS SDK
- Multiple Model Support: Access to Claude, Llama, Titan, and other foundation models through AWS Bedrock
- Chat Completions: Support for chat completions API with all available Bedrock models
- Streaming Responses: Support for streaming responses for more responsive applications
- Type-Safe: Comprehensive TypeScript typings for all APIs and models
- Consistent Interface: Compatible with the AIGNE Framework's model interface
- Error Handling: Robust error handling and retry mechanisms
- Full Configuration: Extensive configuration options for fine-tuning behavior
npm install @aigne/bedrock @aigne/coreyarn add @aigne/bedrock @aigne/corepnpm add @aigne/bedrock @aigne/coreimport { BedrockChatModel } from "@aigne/bedrock";
const model = new BedrockChatModel({
// Provide API key directly or use environment variable AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
accessKeyId: "YOUR_ACCESS_KEY_ID",
secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
model: "us.amazon.nova-premier-v1:0",
modelOptions: {
temperature: 0.7,
},
});
const result = await model.invoke({
messages: [{ role: "user", content: "Hello, who are you?" }],
});
console.log(result);
/* Output:
{
text: "Hello! How can I assist you today?",
model: "gpt-4o",
usage: {
inputTokens: 10,
outputTokens: 9
}
}
*/import { BedrockChatModel } from "@aigne/bedrock";
import { isAgentResponseDelta } from "@aigne/core";
const model = new BedrockChatModel({
// Provide API key directly or use environment variable AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
accessKeyId: "YOUR_ACCESS_KEY_ID",
secretAccessKey: "YOUR_SECRET_ACCESS_KEY",
model: "us.amazon.nova-premier-v1:0",
modelOptions: {
temperature: 0.7,
},
});
const stream = await model.invoke(
{
messages: [{ role: "user", content: "Hello, who are you?" }],
},
{ streaming: true },
);
let fullText = "";
const json = {};
for await (const chunk of stream) {
if (isAgentResponseDelta(chunk)) {
const text = chunk.delta.text?.text;
if (text) fullText += text;
if (chunk.delta.json) Object.assign(json, chunk.delta.json);
}
}
console.log(fullText); // Output: "Hello! How can I assist you today?"
console.log(json); // { model: "gpt-4o", usage: { inputTokens: 10, outputTokens: 9 } }Elastic-2.0