-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda-bedrock-suggest.js
More file actions
34 lines (28 loc) · 1.12 KB
/
lambda-bedrock-suggest.js
File metadata and controls
34 lines (28 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { BedrockRuntimeClient, InvokeModelCommand } = require("@aws-sdk/client-bedrock-runtime");
exports.handler = async (event) => {
try {
const { title, goal } = JSON.parse(event.body);
const client = new BedrockRuntimeClient({ region: process.env.AWS_REGION || "us-east-1" });
const prompt = `Write a compelling 2-3 sentence crowdfunding campaign description for: "${title}". Goal: ${goal} APT. Be concise, inspiring, and action-oriented.`;
const command = new InvokeModelCommand({
modelId: "anthropic.claude-3-haiku-20240307-v1:0",
body: JSON.stringify({
anthropic_version: "bedrock-2023-05-31",
max_tokens: 200,
messages: [{ role: "user", content: prompt }]
})
});
const response = await client.send(command);
const result = JSON.parse(new TextDecoder().decode(response.body));
return {
statusCode: 200,
body: JSON.stringify({ description: result.content[0].text })
};
} catch (error) {
console.error("Error:", error);
return {
statusCode: 500,
body: JSON.stringify({ error: error.message })
};
}
};