@@ -80,8 +80,7 @@ exports.generateWithVertex = onRequest(async (request, response) => {
80
80
generation_config : generationConfig ,
81
81
} ) ;
82
82
83
- // Create the chat; append user input to Remote Config-defined prompt.
84
- const chat = generativeModel . startChat ( ) ;
83
+ // Combine prompt from Remote Config with optional user input.
85
84
const chatInput = textPrompt + " " + userInput ;
86
85
87
86
if ( ! chatInput ) {
@@ -95,23 +94,23 @@ exports.generateWithVertex = onRequest(async (request, response) => {
95
94
return ;
96
95
}
97
96
98
- console . log ( "\nRunning with model " , textModel , ", prompt: " , textPrompt ,
97
+ logger . log ( "\nRunning with model " , textModel , ", prompt: " , textPrompt ,
99
98
", generationConfig: " , generationConfig , ", safetySettings: " ,
100
99
safetySettings , " in " , location , "\n" ) ;
101
100
102
- const result = await chat . sendMessageStream ( chatInput ) ;
101
+ const result = await generativeModel . generateContentStream ( chatInput ) ;
103
102
response . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
104
103
105
104
for await ( const item of result . stream ) {
106
105
const chunk = item . candidates [ 0 ] . content . parts [ 0 ] . text ;
107
- console . log ( "Received chunk:" , chunk ) ;
106
+ logger . log ( "Received chunk:" , chunk ) ;
108
107
response . write ( chunk ) ;
109
108
}
110
109
111
110
response . end ( ) ;
112
111
113
112
} catch ( error ) {
114
- console . error ( error ) ;
113
+ logger . error ( error ) ;
115
114
response . status ( 500 ) . send ( 'Internal server error' ) ;
116
115
}
117
116
} ) ;
0 commit comments