@@ -33,27 +33,19 @@ async function createNonStreamingChat(
33
33
34
34
const chat = generativeModel . startChat ( { } ) ;
35
35
36
- const chatInput1 = 'Hello' ;
37
- console . log ( `User: ${ chatInput1 } ` ) ;
36
+ const result1 = await chat . sendMessage ( 'Hello' ) ;
37
+ const response1 = await result1 . response ;
38
+ console . log ( 'Chat response 1: ' , JSON . stringify ( response1 ) ) ;
38
39
39
- const result1 = await chat . sendMessage ( chatInput1 ) ;
40
- const response1 = result1 . response ;
41
- const text1 = response1 . candidates [ 0 ] . content . parts [ 0 ] . text ;
42
- console . log ( 'Chat bot: ' , text1 ) ;
43
-
44
- const chatInput2 = 'Can you tell me a scientific fun fact?' ;
45
- console . log ( `User: ${ chatInput2 } ` ) ;
46
- const result2 = await chat . sendMessage ( chatInput2 ) ;
40
+ const result2 = await chat . sendMessage (
41
+ 'Can you tell me a scientific fun fact?'
42
+ ) ;
47
43
const response2 = await result2 . response ;
48
- const text2 = response2 . candidates [ 0 ] . content . parts [ 0 ] . text ;
49
- console . log ( 'Chat bot: ' , text2 ) ;
44
+ console . log ( 'Chat response 2: ' , JSON . stringify ( response2 ) ) ;
50
45
51
- const chatInput3 = 'How can I learn more about that?' ;
52
- console . log ( `User: ${ chatInput3 } ` ) ;
53
- const result3 = await chat . sendMessage ( chatInput3 ) ;
46
+ const result3 = await chat . sendMessage ( 'How can I learn more about that?' ) ;
54
47
const response3 = await result3 . response ;
55
- const text3 = response3 . candidates [ 0 ] . content . parts [ 0 ] . text ;
56
- console . log ( 'Chat bot: ' , text3 ) ;
48
+ console . log ( 'Chat response 3: ' , JSON . stringify ( response3 ) ) ;
57
49
}
58
50
// [END aiplatform_gemini_multiturn_chat_nonstreaming]
59
51
0 commit comments