Skip to content
32 changes: 32 additions & 0 deletions genai/test/tools-google-maps-coordinates-with-txt.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {describe, it} = require('mocha');

const projectId = process.env.CAIP_PROJECT_ID;
const sample = require('../tools/tools-google-maps-coordinates-with-txt');
const {delay} = require('./util');
const {assert} = require('chai');

describe('tools-google-maps-coordinates-with-txt', () => {
it('should use google maps coordinates', async function () {
this.timeout(180000);
this.retries(4);
await delay(this.test);
const output = await sample.generateContent(projectId);
assert(output.length > 0);
});
});
32 changes: 32 additions & 0 deletions genai/test/tools-google-search-and-urlcontext-with-txt.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {describe, it} = require('mocha');

const projectId = process.env.CAIP_PROJECT_ID;
const sample = require('../tools/tools-google-search-and-urlcontext-with-txt');
const {delay} = require('./util');
const {assert} = require('chai');

describe('tools-google-search-and-urlcontext-with-txt', () => {
it('should create urlcontext and google search', async function () {
this.timeout(180000);
this.retries(4);
await delay(this.test);
const output = await sample.generateContent(projectId);
assert(output.length > 0);
});
});
32 changes: 32 additions & 0 deletions genai/test/tools-urlcontext-with-txt.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {describe, it} = require('mocha');

const projectId = process.env.CAIP_PROJECT_ID;
const sample = require('../tools/tools-urlcontext-with-txt');
const {delay} = require('./util');
const {assert} = require('chai');

describe('tools-urlcontext-with-txt', () => {
it('should create urlcontext with txt', async function () {
this.timeout(180000);
this.retries(4);
await delay(this.test);
const output = await sample.generateContent(projectId);
assert(output.length > 0);
});
});
74 changes: 74 additions & 0 deletions genai/tools/tools-google-maps-coordinates-with-txt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START googlegenaisdk_tools_google_maps_coordinates_with_txt]
const {GoogleGenAI} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';

async function generateContent(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const response = await client.models.generateContent({
model: 'gemini-2.5-flash',
contents: 'Where can I get the best espresso near me?',
config: {
tools: [
{
googleMaps: {},
},
],
toolConfig: {
retrievalConfig: {
latLng: {
latitude: 40.7128,
longitude: -74.006,
},
languageCode: 'en_US',
},
},
},
});

const output = [];

console.log('\n--- Model Output ---');
for (const candidate of response.candidates || []) {
for (const part of candidate.content.parts || []) {
if (part.text) {
console.log(part.text);
output.push(part.text);
}
}
}
// Example response:
// 'Here are some of the top-rated places to get espresso near you: ...'

return output;
}
// [END googlegenaisdk_tools_google_maps_coordinates_with_txt]

module.exports = {
generateContent,
};
109 changes: 109 additions & 0 deletions genai/tools/tools-google-search-and-urlcontext-with-txt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START googlegenaisdk_tools_google_search_and_urlcontext_with_txt]
const {GoogleGenAI} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';

async function generateContent(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
httpOptions: {apiVersion: 'v1beta1'},
});

// TODO(developer): Here put your URLs!
const url = 'https://www.google.com/search?q=events+in+New+York';

const response = await client.models.generateContent({
model: 'gemini-2.5-flash',
contents: `Give me a three-day events schedule based on ${url}. Also let me know what to take care of considering weather and commute.`,
config: {
tools: [{urlContext: {}}, {googleSearch: {}}],
responseModalities: ['TEXT'],
},
});

const output = [];

console.log('\n--- Model Output ---');
for (const candidate of response.candidates || []) {
for (const part of candidate.content.parts || []) {
if (part.text) {
console.log(part.text);
output.push(part.text);
}
}
}

// 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.
//
// ### Three-Day Event Schedule: New York City (October 7-9, 2025)
//
// **Day 1: Tuesday, October 7, 2025 - Art and Culture**
//
// * **Morning (10:00 AM - 1:00 PM):** Visit "Phillips Visual Language: The Art of Irving Penn" at 432 Park Avenue. This exhibition is scheduled to end on this day, offering a last chance to see it.
// * **Lunch (1:00 PM - 2:00 PM):** Grab a quick lunch near Park Avenue.
// * **Afternoon (2:30 PM - 5:30 PM):** Explore the "Lincoln Center Festival of Firsts" at Lincoln Center. This festival runs until October 23rd, offering various performances or exhibits. Check their specific schedule for the day.
// * **Evening (7:00 PM onwards):** Experience a classic Broadway show. Popular options mentioned for October 2025 include "Six The Musical," "Wicked," "Hadestown," or "MJ - The Musical."
//
// **Day 2: Wednesday, October 8, 2025 - Unique Experiences and SoHo Vibes**
//
// * **Morning (11:00 AM - 1:00 PM):** Head to Brooklyn for the "Secret Room at IKEA Brooklyn" at 1 Beard Street. This unique event is scheduled to end on October 9th.
// * **Lunch (1:00 PM - 2:00 PM):** Enjoy lunch in Brooklyn, perhaps exploring local eateries in the area.
// * **Afternoon (2:30 PM - 5:30 PM):** Immerse yourself in the "The Weeknd & Nespresso Samra Origins Vinyl Cafe" at 579 Broadway in SoHo. This pop-up, curated by The Weeknd, combines coffee and music and runs until October 14th.
// * **Evening (6:00 PM onwards):** Explore the vibrant SoHo neighborhood, known for its shopping and dining. You could also consider a dinner cruise to see the illuminated Manhattan skyline and the Statue of Liberty.
//
// **Day 3: Thursday, October 9, 2025 - Film and Scenic Views**
//
// * **Morning (10:00 AM - 1:00 PM):** Attend a screening at the New York Greek Film Expo, which runs until October 12th in New York City.
// * **Lunch (1:00 PM - 2:00 PM):** Have lunch near the film expo's location.
// * **Afternoon (2:30 PM - 5:30 PM):** Take advantage of the pleasant October weather and enjoy outdoor activities. Consider biking along the rivers or through Central Park to admire the early autumn foliage.
// * **Evening (6:00 PM onwards):** Visit an observation deck like the Empire State Building or Top of the Rock for panoramic city views. Afterwards, enjoy dinner in a neighborhood of your choice.
//
// ### Weather and Commute Considerations:
//
// **Weather in Early October:**
//
// * **Temperatures:** Expect mild to cool temperatures. Average daily temperatures in early October range from 10°C (50°F) to 18°C (64°F), with occasional warmer days reaching the mid-20s°C (mid-70s°F). Evenings can be quite chilly.
// * **Rainfall:** October has a higher chance of rainfall compared to other months, with an average of 33mm and a 32% chance of rain on any given day.
// * **Sunshine:** You can generally expect about 7 hours of sunshine per day.
// * **What to Pack:** Pack layers! Bring a light jacket or sweater for the daytime, and a warmer coat for the evenings. An umbrella or a light raincoat is highly recommended due to the chance of showers. Comfortable walking shoes are a must for exploring the city.
//
// **Commute in New York City:**
//
// * **Public Transportation is Key:** The subway is generally the fastest and most efficient way to get around New York City, especially during the day. Buses are good for East-West travel, but can be slower due to traffic.
// * **Using Apps:** Utilize Google Maps or official MTA apps to plan your routes and check for real-time service updates. The subway runs 24/7, but expect potential delays or changes to routes during nights and weekends due to maintenance.
// * **Rush Hour:** Avoid subway and commuter train travel during peak rush hours (8 AM - 10 AM and 5 PM - 7 PM) if possible, as trains can be extremely crowded.
// * **Subway Etiquette:** When on the subway, stand to the side of the doors to let people exit before boarding, and move to the center of the car to make space. Hold onto a pole or seat, and remove your backpack to free up space.
// * **Transfers:** Subway fare is $2.90 per ride, and you get one free transfer between the subway and bus within a two-hour window.
// * **Walking:** New York City is very walkable. If the weather is pleasant, walking between nearby attractions is an excellent way to see the city.
// * **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.
// * **Allow Extra Time:** Always factor in an additional 20-30 minutes for travel time, as delays can occur.

return output;
}
// [END googlegenaisdk_tools_google_search_and_urlcontext_with_txt]

module.exports = {
generateContent,
};
93 changes: 93 additions & 0 deletions genai/tools/tools-urlcontext-with-txt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START googlegenaisdk_tools_urlcontext_with_txt]
const {GoogleGenAI} = require('@google/genai');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';

async function generateContent(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
httpOptions: {apiVersion: 'v1beta1'},
});

// TODO(developer): Here put your URLs!
const url1 = 'https://cloud.google.com/vertex-ai/docs/generative-ai/start';
const url2 = 'https://cloud.google.com/docs/overview';

const response = await client.models.generateContent({
model: 'gemini-2.5-flash',
contents: `Compare the content, purpose, and audiences of ${url1} and ${url2}.`,
config: {
tools: [{urlContext: {}}],
responseModalities: ['TEXT'],
},
});

const output = [];

console.log('\n--- Model Output ---');
for (const candidate of response.candidates || []) {
for (const part of candidate.content.parts || []) {
if (part.text) {
console.log(part.text);
output.push(part.text);
}
}
}

// 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.
//
// Here's a comparison:
//
// **Gemini 2.5 Pro**
// * **Description**: This is Google's most advanced model, described as a "state-of-the-art thinking model". It excels at reasoning over complex problems in areas like code, mathematics, and STEM, and can analyze large datasets, codebases, and documents using a long context window.
// * **Input Data Types**: It supports audio, images, video, text, and PDF inputs.
// * **Output Data Types**: It produces text outputs.
// * **Token Limits**: It has an input token limit of 1,048,576 and an output token limit of 65,536.
// * **Supported Capabilities**: Gemini 2.5 Pro supports Batch API, Caching, Code execution, Function calling, Search grounding, Structured outputs, Thinking, and URL context.
// * **Knowledge Cutoff**: January 2025.
//
// **Gemini 2.5 Flash**
// * **Description**: Positioned as "fast and intelligent," Gemini 2.5 Flash is highlighted as Google's best model in terms of price-performance, offering well-rounded capabilities. It is ideal for large-scale processing, low-latency, high-volume tasks that require thinking, and agentic use cases.
// * **Input Data Types**: It supports text, images, video, and audio inputs.
// * **Output Data Types**: It produces text outputs.
// * **Token Limits**: Similar to Pro, it has an input token limit of 1,048,576 and an output token limit of 65,536.
// * **Supported Capabilities**: Gemini 2.5 Flash supports Batch API, Caching, Code execution, Function calling, Search grounding, Structured outputs, Thinking, and URL con//
// **Key Differences and Similarities:**
//
// * **Primary Focus**: Gemini 2.5 Pro is geared towards advanced reasoning and in-depth analysis of complex problems and large documents. Gemini 2.5 Flash, on the other hand, is optimized for efficiency, scale, and high-volume, low-latency applications, making it a strong choice for price-performance sensitive scenarios.
// * **Input Modalities**: Both models handle various input types including text, images, video, and audio. Gemini 2.5 Pro explicitly lists PDF as an input type, while Gemini 2.5 Flash lists text, images, video, audio.
// * **Technical Specifications (for primary stable versions)**: Both models share the same substantial input and output token limits (1,048,576 input and 65,536 output). They also support a very similar set of core capabilities, including code execution, function calling, and URL context. Neither model supports audio generation, image generation, or Live API in their standard stable versions.
// * **Knowledge Cutoff**: Both models have a knowledge cutoff of January 2025.
//
// 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.
// get URLs retrieved for context

return output;
}
// [END googlegenaisdk_tools_urlcontext_with_txt]

module.exports = {
generateContent,
};
Loading