Skip to content

Commit 817d4f0

Browse files
committed
Fix bedrock example.
1 parent 95fa2bc commit 817d4f0

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

packages/sdk/ai/examples/bedrock/src/index.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const context = {
2929

3030
console.log('*** SDK successfully initialized');
3131

32+
interface MyModelConfig {
33+
modelId: string;
34+
prompt: { role: ConversationRole; content: string }[];
35+
}
36+
3237
function mapPromptToConversation(prompt: { role: ConversationRole; content: string }[]): Message[] {
3338
return prompt.map((item) => ({
3439
role: item.role,
@@ -47,23 +52,31 @@ async function main() {
4752
configValue = await aiClient.modelConfig(aiConfigKey, context, false, {
4853
myVariable: 'My User Defined Variable',
4954
});
50-
tracker = configValue.tracker;
55+
if (configValue === false) {
56+
console.log('got default value for config');
57+
process.exit(1);
58+
} else {
59+
tracker = configValue.tracker;
60+
}
5161
} catch (error) {
5262
console.log(`*** SDK failed to initialize: ${error}`);
5363
process.exit(1);
5464
}
5565

56-
const completion = await tracker.trackBedrockConverse(
57-
await awsClient.send(
58-
new ConverseCommand({
59-
modelId: configValue.config.config.modelId,
60-
messages: mapPromptToConversation(configValue.config.prompt),
61-
}),
62-
),
63-
);
66+
if (tracker) {
67+
const modelConfig = configValue.config as MyModelConfig;
68+
const completion = await tracker.trackBedrockConverse(
69+
await awsClient.send(
70+
new ConverseCommand({
71+
modelId: modelConfig.modelId,
72+
messages: mapPromptToConversation(modelConfig.prompt),
73+
}),
74+
),
75+
);
6476

65-
console.log('AI Response:', completion.output.message.content[0].text);
66-
console.log('Success.');
77+
console.log('AI Response:', completion.output.message.content[0].text);
78+
console.log('Success.');
79+
}
6780
}
6881

6982
main();

packages/sdk/ai/examples/bedrock/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"module": "CommonJS",
1818
"moduleResolution": "Node"
1919
},
20-
"include": ["src", "test"],
20+
"include": ["src"],
2121
"exclude": ["dist", "node_modules"]
2222
}

packages/sdk/ai/tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"compilerOptions": {
3-
// Uses "." so it can load package.json.
4-
"rootDir": ".",
3+
"rootDir": "src",
54
"outDir": "dist",
65
"target": "es2017",
76
"lib": ["es6"],
87
"module": "commonjs",
98
"strict": true,
109
"noImplicitOverride": true,
11-
// Needed for CommonJS modules: markdown-it, fs-extra
10+
// Needed for CommonJS modules.
1211
"allowSyntheticDefaultImports": true,
1312
"sourceMap": true,
1413
"declaration": true,

0 commit comments

Comments
 (0)