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 …
-
December 18 th, 2023
860 Words
I am a huge fan of Computer Interfaces; especially non-textual ones. Spoken words can be a powerful interface to digital services; Amazon Web Services has various services and products available that work with audio. To identify language in spoken words and extract textual information, you can use Amazon Transcribe and analize audio files.
-
December 10 th, 2023
1117 Words
The weekend was nice; I had some fun using the bunq API and configure webhooks for account activities and explained how to use Amazon EventBridge Pipes to process and transform messages from SQS. Now, it’s time to combine both and get bunq events to Amazon EventBridge!
-
December 10 th, 2023
367 Words
When managing continuous events, Amazon EventBridge is a powerful and fully managed service. With Amazon EventBridge Pipes it’s easy to organize, structure, and transform incoming data messages. Using the AWS Cloud Development Kit, this guide will configure an Amazon SQS Queue and use Amazon EventBridge Pipes for data processing and transformation.
-
December 9 th, 2023
1505 Words
The digital banking service bunq has an API for their banking accounts. With support for webhooks, you can easily track any activity within your account! bunq calls them Callbacks. This guide explains how to use the bunq mobile application and some cURL requests to get a JSON request for every activity in your bunq banking accounts.
-
December 3 rd, 2023
369 Words
AWS Step Functions can easily be used to wrap existing AWS services and persist specific use cases. For example, AWS Step Functions can call the Amazon Bedrock API to generate text responses using the AI21 Labs Jurassic-2 models. You can create a Step Function using the AWS Management Console, or the AWS Cloud Development Kit.
-
November 26 th, 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 31 st, 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.