Last active
October 7, 2023 04:53
-
-
Save kenyipp/af303080d312bc23361094b2a7a2251d to your computer and use it in GitHub Desktop.
An example that uses Amazon Bedrock to generate data and transform the response into JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
BedrockRuntimeClient, | |
InvokeModelCommand | |
} from "@aws-sdk/client-bedrock-runtime"; | |
const client = new BedrockRuntimeClient({ region: "us-east-1" }); | |
const textDecoder = new TextDecoder("utf-8"); | |
const command = new InvokeModelCommand({ | |
modelId: "ai21.j2-mid-v1", | |
contentType: "application/json", | |
accept: "*/*", | |
body: JSON.stringify({ | |
prompt: "Hello world", | |
maxTokens: 200, | |
temperature: 0.7, | |
topP: 1, | |
stopSequences: [], | |
countPenalty: { | |
scale: 0 | |
}, | |
presencePenalty: { | |
scale: 0 | |
}, | |
frequencyPenalty: { | |
scale: 0 | |
} | |
}) | |
}); | |
client | |
.send(command) | |
.then((data) => JSON.parse(textDecoder.decode(data.body))) | |
.then((data) => console.log(JSON.stringify(data, null, 4))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment