Skip to content

Commit abbc90d

Browse files
author
Guiners
committed
changing response.candidates loop
1 parent e4a0d21 commit abbc90d

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

genai/tools/tools-google-search-and-urlcontext-with-txt.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ async function generateContent(
4343
},
4444
});
4545

46-
console.log(response.text);
46+
const output = [];
47+
48+
if (
49+
response.candidates &&
50+
response.candidates[0] &&
51+
response.candidates[0].content.parts
52+
) {
53+
for (const part of response.candidates[0].content.parts) {
54+
console.log(part.text);
55+
output.push(part.text);
56+
}
57+
}
58+
4759
// Here is a possible three-day event schedule for New York City, focusing on the dates around October 7-9, 2025, along with weather and commute considerations.
4860
//
4961
// ### Three-Day Event Schedule: New York City (October 7-9, 2025)
@@ -89,9 +101,7 @@ async function generateContent(
89101
// * **Taxis/Ride-sharing:** Uber, Lyft, and Curb (for NYC taxis) are available, but driving in the city is generally discouraged due to traffic and parking difficulties.
90102
// * **Allow Extra Time:** Always factor in an additional 20-30 minutes for travel time, as delays can occur.
91103

92-
console.log(response.candidates[0].urlContextMetadata);
93-
94-
return response.text;
104+
return output;
95105
}
96106
// [END googlegenaisdk_tools_google_search_and_urlcontext_with_txt]
97107

genai/tools/tools-urlcontext-with-txt.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,18 @@ async function generateContent(
4444
},
4545
});
4646

47-
console.log(response.text);
47+
const output = [];
48+
49+
if (
50+
response.candidates &&
51+
response.candidates[0] &&
52+
response.candidates[0].content.parts
53+
) {
54+
for (const part of response.candidates[0].content.parts) {
55+
console.log(part.text);
56+
output.push(part.text);
57+
}
58+
}
4859

4960
// Gemini 2.5 Pro and Gemini 2.5 Flash are both advanced models offered by Google AI, but they are optimized for different use cases.
5061
//
@@ -74,9 +85,7 @@ async function generateContent(
7485
// In essence, while both models are powerful and capable, Gemini 2.5 Pro is designed for maximum performance in complex reasoning tasks, whereas Gemini 2.5 Flash prioritizes cost-effectiveness and speed for broader, high-throughput applications.
7586
// get URLs retrieved for context
7687

77-
console.log(response.candidates[0].urlContextMetadata);
78-
79-
return response.text;
88+
return output;
8089
}
8190
// [END googlegenaisdk_tools_urlcontext_with_txt]
8291

0 commit comments

Comments
 (0)