@@ -80,8 +80,7 @@ exports.generateWithVertex = onRequest(async (request, response) => {
8080 generation_config : generationConfig ,
8181 } ) ;
8282
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.
8584 const chatInput = textPrompt + " " + userInput ;
8685
8786 if ( ! chatInput ) {
@@ -95,23 +94,23 @@ exports.generateWithVertex = onRequest(async (request, response) => {
9594 return ;
9695 }
9796
98- console . log ( "\nRunning with model " , textModel , ", prompt: " , textPrompt ,
97+ logger . log ( "\nRunning with model " , textModel , ", prompt: " , textPrompt ,
9998 ", generationConfig: " , generationConfig , ", safetySettings: " ,
10099 safetySettings , " in " , location , "\n" ) ;
101100
102- const result = await chat . sendMessageStream ( chatInput ) ;
101+ const result = await generativeModel . generateContentStream ( chatInput ) ;
103102 response . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
104103
105104 for await ( const item of result . stream ) {
106105 const chunk = item . candidates [ 0 ] . content . parts [ 0 ] . text ;
107- console . log ( "Received chunk:" , chunk ) ;
106+ logger . log ( "Received chunk:" , chunk ) ;
108107 response . write ( chunk ) ;
109108 }
110109
111110 response . end ( ) ;
112111
113112 } catch ( error ) {
114- console . error ( error ) ;
113+ logger . error ( error ) ;
115114 response . status ( 500 ) . send ( 'Internal server error' ) ;
116115 }
117116} ) ;
0 commit comments