-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathcli_text_playground.js
More file actions
78 lines (68 loc) · 1.82 KB
/
cli_text_playground.js
File metadata and controls
78 lines (68 loc) · 1.82 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { fileURLToPath } from "node:url";
import {
Scenario,
ScenarioAction,
ScenarioInput,
ScenarioOutput,
} from "@aws-doc-sdk-examples/lib/scenario/index.js";
import { FoundationModels } from "../config/foundation_models.js";
/**
* @typedef {Object} ModelConfig
* @property {Function} module
* @property {Function} invoker
* @property {string} modelId
* @property {string} modelName
*/
const greeting = new ScenarioOutput(
"greeting",
"Welcome to the Amazon Bedrock Runtime client demo!",
{ header: true },
);
const selectModel = new ScenarioInput("model", "First, select a model:", {
type: "select",
choices: Object.values(FoundationModels).map((model) => ({
name: model.modelName,
value: model,
})),
});
const enterPrompt = new ScenarioInput("prompt", "Now, enter your prompt:", {
type: "input",
});
const printDetails = new ScenarioOutput(
"print details",
/**
* @param {{ model: ModelConfig, prompt: string }} c
*/
(c) => console.log(`Invoking ${c.model.modelName} with '${c.prompt}'...`),
);
const invokeModel = new ScenarioAction(
"invoke model",
/**
* @param {{ model: ModelConfig, prompt: string, response: string }} c
*/
async (c) => {
const modelModule = await c.model.module();
const invoker = c.model.invoker(modelModule);
c.response = await invoker(c.prompt, c.model.modelId);
},
);
const printResponse = new ScenarioOutput(
"print response",
/**
* @param {{ response: string }} c
*/
(c) => c.response,
);
const scenario = new Scenario("Amazon Bedrock Runtime Demo", [
greeting,
selectModel,
enterPrompt,
printDetails,
invokeModel,
printResponse,
]);
if (process.argv[1] === fileURLToPath(import.meta.url)) {
scenario.run();
}