From 9aaca6e9c2c1356e8aa87941f9ac7c22781ea55d Mon Sep 17 00:00:00 2001 From: Drew Brown Date: Fri, 12 Jul 2024 16:36:18 -0600 Subject: [PATCH] fix: Update non-streaming example (#3737) * fix: Update non-streaming example Also remove diuplicate region tag to disambiguate correct sample * fix: Lint error --- generative-ai/snippets/nonStreamingMultipartContent.js | 9 +++------ generative-ai/snippets/streamMultipartContent.js | 2 -- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/generative-ai/snippets/nonStreamingMultipartContent.js b/generative-ai/snippets/nonStreamingMultipartContent.js index 7a373ed0c5..45880611bf 100644 --- a/generative-ai/snippets/nonStreamingMultipartContent.js +++ b/generative-ai/snippets/nonStreamingMultipartContent.js @@ -54,16 +54,13 @@ async function createNonStreamingMultipartContent( console.log(request.contents[0].parts[1].text); console.log('Non-Streaming Response Text:'); - // Create the response stream - const responseStream = - await generativeVisionModel.generateContentStream(request); - // Wait for the response stream to complete - const aggregatedResponse = await responseStream.response; + // Generate a response + const response = await generativeVisionModel.generateContent(request); // Select the text from the response const fullTextResponse = - aggregatedResponse.candidates[0].content.parts[0].text; + response.response.candidates[0].content.parts[0].text; console.log(fullTextResponse); } diff --git a/generative-ai/snippets/streamMultipartContent.js b/generative-ai/snippets/streamMultipartContent.js index 5831775637..7604476c67 100644 --- a/generative-ai/snippets/streamMultipartContent.js +++ b/generative-ai/snippets/streamMultipartContent.js @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// [START generativeaionvertexai_gemini_get_started] // [START aiplatform_gemini_get_started] const {VertexAI} = require('@google-cloud/vertexai'); @@ -64,7 +63,6 @@ async function createStreamMultipartContent( } } // [END aiplatform_gemini_get_started] -// [END generativeaionvertexai_gemini_get_started] createStreamMultipartContent(...process.argv.slice(2)).catch(err => { console.error(err.message);