After using Amazon Bedrock Generative AI with the AWS CLI, you may also want to use the AWS JavaScript SDK to invoke an available Amazon Bedrock Model.
Like the first example about CLI usage of Amazon Bedrock, this is how you can generate a Haiku about software engineering with the JavaScript v3 SDK:
import {
BedrockRuntimeClient,
InvokeModelCommand,
InvokeModelCommandInput
} from "@aws-sdk/client-bedrock-runtime";
const client = new BedrockRuntimeClient({
region: "us-east-1",
});
const sendPrompt = async (prompt: string) => {
const input: InvokeModelCommandInput = {
body: JSON.stringify({
prompt,
"maxTokens": 300,
"temperature": 0.5,
"topP": 0.9
}),
contentType: 'application/json',
modelId: "ai21.j2-mid-v1",
};
const command = new InvokeModelCommand(input);
const response = await client.send(command);
return JSON.parse(Buffer.from(response.body).toString()).completions
}
Promise.resolve(
sendPrompt("Please generate a funny Haiku about software engineering.")
).then(
console.log
)
Next, just invoke the script:
$ > ./scripts/invoke-model.ts
[
{
data: {
text: '\n' +
'Software engineering haiku\n' +
'Debugging code all night\n' +
'Coffee helps, but not much',
tokens: [Array]
},
finishReason: { reason: 'endoftext' }
}
]
Enjoy! 🎉 Soon, Bedrock Agents will enable you to chain and orchestrate individual prompts and automate complex tasks …
-
November 26th, 2023
290 Words
The current en vogue alternative for Twitter is the invite-only services Bluesky. Based on the open specifications of the foundational concept, the AT Protocol, and the available API client on GitHub, it is not that complex to retrieve details of one of your posts; for example the number of likes.
-
October 31st, 2023
535 Words
The previous post described how to create an Amazon EventBridge Event Bus with Amazon CloudWatch Log forwarding using the AWS CDK. Publishing events works fine with the AWS Management Console or the AWS CLI, but you can also use Service Integrations for Amazon API Gateway; this works for HTTP and Rest API Gateways.
-
October 31st, 2023
583 Words
Amazon EventBridge is a powerful service to build event-driven applications at scale across AWS. To get started with EventBridge, you just need to create an Event Bus; for example, using the AWS Cloud Development Kit. Next, forwarding all events to an Amazon CloudWatch Log group enables basic insights into all processed events.
-
October 30th, 2023
325 Words
Based on invoking Amazon Bedrock with AWS Lambda and Amazon API Gateway, you can adapt the AWS Cloud Development Kit example code to use AWS AppSync and GraphQL for accessing Amazon Bedrock.
-
October 30th, 2023
351 Words
After using Amazon Bedrock Generative AI with the AWS CLI and AWS JavaScript SDK, this guide will explain how to create an Amazon API Gateway and use the AWS Cloud Development Kit and AWS Lambda to invoke Amazon Bedrock.
-
October 28th, 2023
377 Words
With AWS re:Invent 2023 just around the corner, the frequency of AWS press releases increases. Generative AI is a hot topic everywhere, tools like Midjourney and ChatGPT lower the bar for non-technical people, and I wonder how and when AWS will introduce a more solution-like Genrative AI service.
-
October 25th, 2023
305 Words
When using the AWS Software Development Kit, pagination in API responses is a common and sometimes annoying to deal with. Thanks to a shared interfaced in @aws-sdk
clients, can you can establish a common pattern to interact with AWS paginated API actions using the JavaScript SDK v3. Retrieving all AWS Accounts in your AWS Organization is a neat example use case for this.