@@ -29,6 +29,11 @@ const context = {
2929
3030console . log ( '*** SDK successfully initialized' ) ;
3131
32+ interface MyModelConfig {
33+ modelId : string ;
34+ prompt : { role : ConversationRole ; content : string } [ ] ;
35+ }
36+
3237function 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
6982main ( ) ;
0 commit comments