diff --git a/genai/live/hello_gemini_are_you_there.wav b/genai/live/hello_gemini_are_you_there.wav new file mode 100644 index 0000000000..ef60adee2a Binary files /dev/null and b/genai/live/hello_gemini_are_you_there.wav differ diff --git a/genai/live/live-code-exec-with-txt.js b/genai/live/live-code-exec-with-txt.js new file mode 100644 index 0000000000..da269ccbed --- /dev/null +++ b/genai/live/live-code-exec-with-txt.js @@ -0,0 +1,101 @@ +// 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. + +// [START googlegenaisdk_live_code_exec_with_txt] + +'use strict'; + +const {GoogleGenAI, Modality} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateLiveCodeExec( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const modelId = 'gemini-2.0-flash-live-preview-04-09'; + const config = { + responseModalities: [Modality.TEXT], + tools: [ + { + codeExecution: {}, + }, + ], + }; + + const responseQueue = []; + + async function waitMessage() { + while (responseQueue.length === 0) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + return responseQueue.shift(); + } + + async function handleTurn() { + const turns = []; + let done = false; + while (!done) { + const message = await waitMessage(); + turns.push(message); + if (message.serverContent && message.serverContent.turnComplete) { + done = true; + } + } + return turns; + } + + const session = await client.live.connect({ + model: modelId, + config: config, + callbacks: { + onmessage: msg => responseQueue.push(msg), + onerror: e => console.error('Error:', e.message), + }, + }); + + const textInput = 'Compute the largest prime palindrome under 10'; + console.log('> ', textInput, '\n'); + + await session.sendClientContent({ + turns: [{role: 'user', parts: [{text: textInput}]}], + }); + + const turns = await handleTurn(); + for (const turn of turns) { + if (turn.text) { + console.log('Received text:', turn.text); + } + } + + // Example output: + // > Compute the largest prime palindrome under 10 + // The largest prime palindrome under 10 is 7. + + session.close(); + return turns; +} + +// [END googlegenaisdk_live_code_exec_with_txt] + +module.exports = { + generateLiveCodeExec, +}; diff --git a/genai/live/live-conversation-audio-with-audio.js b/genai/live/live-conversation-audio-with-audio.js new file mode 100644 index 0000000000..147514ce54 --- /dev/null +++ b/genai/live/live-conversation-audio-with-audio.js @@ -0,0 +1,170 @@ +// 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. + +// [START googlegenaisdk_live_conversation_audio_with_audio] + +'use strict'; + +const fs = require('fs'); +const path = require('path'); +const {GoogleGenAI, Modality} = require('@google/genai'); + +const MODEL = 'gemini-2.0-flash-live-preview-04-09'; +const INPUT_RATE = 16000; +const OUTPUT_RATE = 24000; +const SAMPLE_WIDTH = 2; // 16-bit + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +function readWavefile(filepath) { + const buffer = fs.readFileSync(filepath); + const audioBytes = buffer.subarray(44); + const base64Data = audioBytes.toString('base64'); + const mimeType = `audio/pcm;rate=${INPUT_RATE}`; + return {base64Data, mimeType}; +} + +// Utility: write bytes -> .wav file +function writeWavefile(filepath, audioFrames, rate = OUTPUT_RATE) { + const rawAudioBytes = Buffer.concat(audioFrames); + const header = Buffer.alloc(44); + header.write('RIFF', 0); + header.writeUInt32LE(36 + rawAudioBytes.length, 4); + header.write('WAVE', 8); + header.write('fmt ', 12); + header.writeUInt32LE(16, 16); + header.writeUInt16LE(1, 20); + header.writeUInt16LE(1, 22); + header.writeUInt32LE(rate, 24); + header.writeUInt32LE(rate * SAMPLE_WIDTH, 28); + header.writeUInt16LE(SAMPLE_WIDTH, 32); + header.writeUInt16LE(16, 34); + header.write('data', 36); + header.writeUInt32LE(rawAudioBytes.length, 40); + + fs.writeFileSync(filepath, Buffer.concat([header, rawAudioBytes])); + console.log(`Model response saved to ${filepath}`); +} + +async function generateLiveConversation( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + console.log('Starting audio conversation sample...'); + console.log(`Project: ${projectId}, Location: ${location}`); + + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const responseQueue = []; + + async function waitMessage(timeoutMs = 60 * 1000) { + const startTime = Date.now(); + + while (responseQueue.length === 0) { + if (Date.now() - startTime > timeoutMs) { + console.warn('No messages received within timeout. Exiting...'); + return null; // timeout occurred + } + await new Promise(resolve => setTimeout(resolve, 100)); + } + + return responseQueue.shift(); + } + + async function handleTurn() { + const audioFrames = []; + let done = false; + + while (!done) { + const message = await waitMessage(); + const serverContent = message.serverContent; + + if (serverContent && serverContent.inputTranscription) { + console.log('Input transcription', serverContent.inputTranscription); + } + if (serverContent && serverContent.outputTranscription) { + console.log('Output transcription', serverContent.outputTranscription); + } + if ( + serverContent && + serverContent.modelTurn && + serverContent.modelTurn.parts + ) { + for (const part of serverContent.modelTurn.parts) { + if (part && part.inlineData && part.inlineData.data) { + const audioData = Buffer.from(part.inlineData.data, 'base64'); + audioFrames.push(audioData); + } + } + } + if (serverContent && serverContent.turnComplete) { + done = true; + } + } + + return audioFrames; + } + + const session = await client.live.connect({ + model: MODEL, + config: { + responseModalities: [Modality.AUDIO], + inputAudioTranscription: {}, + outputAudioTranscription: {}, + }, + callbacks: { + onmessage: msg => responseQueue.push(msg), + onerror: e => console.error(e.message), + onclose: () => console.log('Closed'), + }, + }); + + const wavFilePath = path.join(__dirname, 'hello_gemini_are_you_there.wav'); + console.log('Reading file:', wavFilePath); + + const {base64Data, mimeType} = readWavefile(wavFilePath); + const audioBytes = Buffer.from(base64Data, 'base64'); + + await session.sendRealtimeInput({ + media: { + data: audioBytes.toString('base64'), + mimeType: mimeType, + }, + }); + + console.log('Audio sent, waiting for response...'); + + const audioFrames = await handleTurn(); + if (audioFrames.length > 0) { + writeWavefile( + path.join(__dirname, 'example_model_response.wav'), + audioFrames, + OUTPUT_RATE + ); + } + + await session.close(); + return audioFrames; +} + +// [END googlegenaisdk_live_conversation_audio_with_audio] + +module.exports = { + generateLiveConversation, +}; diff --git a/genai/live/live-func-call-with-txt.js b/genai/live/live-func-call-with-txt.js new file mode 100644 index 0000000000..25277b8133 --- /dev/null +++ b/genai/live/live-func-call-with-txt.js @@ -0,0 +1,125 @@ +// 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. + +// [START googlegenaisdk_live_func_call_with_txt] + +'use strict'; + +const {GoogleGenAI, Modality} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateLiveFunctionCall( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const modelId = 'gemini-2.0-flash-live-preview-04-09'; + + const config = { + responseModalities: [Modality.TEXT], + tools: [ + { + functionDeclarations: [ + {name: 'turn_on_the_lights'}, + {name: 'turn_off_the_lights'}, + ], + }, + ], + }; + + const responseQueue = []; + + async function waitMessage() { + while (responseQueue.length === 0) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + return responseQueue.shift(); + } + + async function handleTurn() { + const turns = []; + let done = false; + while (!done) { + const message = await waitMessage(); + turns.push(message); + + if (message.toolCall) { + for (const fc of message.toolCall.functionCalls) { + console.log(`Model requested function call: ${fc.name}`); + + await session.sendToolResponse({ + functionResponses: [ + { + id: fc.id, + name: fc.name, + response: {result: 'ok'}, + }, + ], + }); + console.log(`Sent tool response for ${fc.name}:`, {result: 'ok'}); + } + } + + if (message.serverContent && message.serverContent.turnComplete) { + done = true; + } + } + return turns; + } + + const session = await client.live.connect({ + model: modelId, + config: config, + callbacks: { + onmessage: msg => responseQueue.push(msg), + onerror: e => console.error('Error:', e.message), + }, + }); + + const textInput = 'Turn on the lights please'; + console.log('> ', textInput, '\n'); + + await session.sendClientContent({ + turns: [{role: 'user', parts: [{text: textInput}]}], + }); + + const turns = await handleTurn(); + + for (const turn of turns) { + if (turn.text) { + console.log('Received text:', turn.text); + } + } + + // Example output: + //>> Turn on the lights please + // Model requested function call: turn_on_the_lights + // Sent tool response for turn_on_the_lights: { result: 'ok' } + + session.close(); + return turns; +} + +// [END googlegenaisdk_live_func_call_with_txt] + +module.exports = { + generateLiveFunctionCall, +}; diff --git a/genai/live/live-ground-googsearch-with-txt.js b/genai/live/live-ground-googsearch-with-txt.js new file mode 100644 index 0000000000..c81b5fe618 --- /dev/null +++ b/genai/live/live-ground-googsearch-with-txt.js @@ -0,0 +1,100 @@ +// 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_live_ground_googsearch_with_txt] +const {GoogleGenAI, Modality} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateLiveGoogleSearch( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const modelId = 'gemini-2.0-flash-live-preview-04-09'; + + const config = { + responseModalities: [Modality.TEXT], + tools: [{googleSearch: {}}], + }; + + const responseQueue = []; + + async function waitMessage() { + while (responseQueue.length === 0) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + return responseQueue.shift(); + } + + async function handleTurn() { + const turns = []; + let done = false; + while (!done) { + const message = await waitMessage(); + turns.push(message); + if (message.serverContent && message.serverContent.turnComplete) { + done = true; + } + } + return turns; + } + + const session = await client.live.connect({ + model: modelId, + config: config, + callbacks: { + onmessage: msg => responseQueue.push(msg), + onerror: e => console.error('Error:', e.message), + }, + }); + + const textInput = + 'When did the last Brazil vs. Argentina soccer match happen?'; + console.log('> ', textInput, '\n'); + + await session.sendClientContent({ + turns: [{role: 'user', parts: [{text: textInput}]}], + }); + + const turns = await handleTurn(); + for (const turn of turns) { + if (turn.text) { + console.log('Received text:', turn.text); + } + } + + // Example output: + // > When did the last Brazil vs. Argentina soccer match happen? + // Received text: The last + // Received text: Brazil vs. Argentina soccer match was on March 25, 202 + // Received text: 5.Argentina won 4-1 in the 2026 FIFA World Cup + // Received text: qualifier. + + session.close(); + return turns; +} + +// [END googlegenaisdk_live_ground_googsearch_with_txt] + +module.exports = { + generateLiveGoogleSearch, +}; diff --git a/genai/live/live-ground-ragengine-with-txt.js b/genai/live/live-ground-ragengine-with-txt.js index 04c83f34fc..2e407cbfe9 100644 --- a/genai/live/live-ground-ragengine-with-txt.js +++ b/genai/live/live-ground-ragengine-with-txt.js @@ -22,20 +22,19 @@ const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; // (DEVELOPER) put here your memory corpus -const MEMORY_CORPUS = - 'projects/cloud-ai-devrel-softserve/locations/us-central1/ragCorpora/2305843009213693952'; +const RAG_CORPUS_ID = ''; async function generateLiveRagTextResponse( - memoryCorpus = MEMORY_CORPUS, projectId = GOOGLE_CLOUD_PROJECT, - location = GOOGLE_CLOUD_LOCATION + location = GOOGLE_CLOUD_LOCATION, + rag_corpus_id = RAG_CORPUS_ID ) { const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - + const memoryCorpus = `projects/${projectId}/locations/${location}/ragCorpora/${rag_corpus_id}`; const modelId = 'gemini-2.0-flash-live-preview-04-09'; // RAG store config diff --git a/genai/live/live-with-txt.js b/genai/live/live-with-txt.js new file mode 100644 index 0000000000..8eaeacf7f1 --- /dev/null +++ b/genai/live/live-with-txt.js @@ -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. + +// [START googlegenaisdk_live_with_txt] + +'use strict'; + +const {GoogleGenAI, Modality} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateLiveConversation( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const modelId = 'gemini-2.0-flash-live-preview-04-09'; + const config = {responseModalities: [Modality.TEXT]}; + + const responseQueue = []; + + async function waitMessage() { + while (responseQueue.length === 0) { + await new Promise(resolve => setTimeout(resolve, 100)); + } + return responseQueue.shift(); + } + + async function handleTurn() { + const turns = []; + let done = false; + while (!done) { + const message = await waitMessage(); + turns.push(message); + if (message.serverContent && message.serverContent.turnComplete) { + done = true; + } + } + return turns; + } + + const session = await client.live.connect({ + model: modelId, + config: config, + callbacks: { + onmessage: msg => responseQueue.push(msg), + onerror: e => console.error('Error:', e.message), + }, + }); + + const textInput = 'Hello? Gemini, are you there?'; + console.log('> ', textInput, '\n'); + + await session.sendClientContent({ + turns: [{role: 'user', parts: [{text: textInput}]}], + }); + + const turns = await handleTurn(); + for (const turn of turns) { + if (turn.text) { + console.log('Received text:', turn.text); + } + } + // Example output: + //> Hello? Gemini, are you there? + // Received text: Yes + // Received text: I'm here. How can I help you today? + session.close(); + return turns; +} + +// [END googlegenaisdk_live_with_txt] + +module.exports = { + generateLiveConversation, +}; diff --git a/genai/test/live-code-exec-with-txt.test.js b/genai/test/live-code-exec-with-txt.test.js new file mode 100644 index 0000000000..361a7cd824 --- /dev/null +++ b/genai/test/live-code-exec-with-txt.test.js @@ -0,0 +1,30 @@ +// 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 {assert} = require('chai'); +const {describe, it} = require('mocha'); + +const projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../live/live-code-exec-with-txt'); + +describe('live-code-exec-with-txt', () => { + it('should generate code execution in a live session from a text prompt', async function () { + this.timeout(180000); + const output = await sample.generateLiveCodeExec(projectId); + console.log('Generated output:', output); + assert(output.length > 0); + }); +}); diff --git a/genai/test/live-conversation-audio-with-audio.test.js b/genai/test/live-conversation-audio-with-audio.test.js new file mode 100644 index 0000000000..a31aac6d42 --- /dev/null +++ b/genai/test/live-conversation-audio-with-audio.test.js @@ -0,0 +1,89 @@ +// 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 {assert} = require('chai'); +const {describe, it} = require('mocha'); +const sinon = require('sinon'); + +const projectId = process.env.CAIP_PROJECT_ID; +const {delay} = require('./util'); +const proxyquire = require('proxyquire'); + +describe('live-conversation-audio-with-audio', () => { + it('should generate content in a live session conversation from a text prompt', async function () { + const mockClient = { + live: { + connect: async (opts = {}) => { + setImmediate(() => + opts.callbacks.onmessage({ + serverContent: { + inputTranscription: 'Hello Gemini', + outputTranscription: 'Hi Mocked Gemini there!', + modelTurn: { + parts: [ + { + inlineData: { + data: Buffer.from('fake audio data').toString('base64'), + }, + }, + ], + }, + turnComplete: false, + }, + }) + ); + + setImmediate(() => + opts.callbacks.onmessage({ + serverContent: { + modelTurn: {parts: []}, + turnComplete: true, + }, + }) + ); + + return { + sendRealtimeInput: async () => {}, + close: async () => {}, + }; + }, + }, + }; + + const sample = proxyquire('../live/live-conversation-audio-with-audio', { + '@google/genai': { + GoogleGenAI: function () { + return mockClient; + }, + Modality: {AUDIO: 'AUDIO'}, + }, + fs: { + readFileSync: sinon.stub().returns(Buffer.alloc(100, 0)), + writeFileSync: sinon.stub().returns(), + }, + path: { + join: (...args) => args.join('/'), + }, + }); + + this.timeout(180000); + this.retries(4); + await delay(this.test); + const output = await sample.generateLiveConversation(projectId); + console.log('Generated output:', output); + assert(output.length > 0); + }); +}); diff --git a/genai/test/live-func-call-with-txt.test.js b/genai/test/live-func-call-with-txt.test.js new file mode 100644 index 0000000000..f63f2b8782 --- /dev/null +++ b/genai/test/live-func-call-with-txt.test.js @@ -0,0 +1,30 @@ +// 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 {assert} = require('chai'); +const {describe, it} = require('mocha'); + +const projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../live/live-func-call-with-txt'); + +describe('live-func-call-with-txt', () => { + it('should generate function call in a live session from a text prompt', async function () { + this.timeout(180000); + const output = await sample.generateLiveFunctionCall(projectId); + console.log('Generated output:', output); + assert(output.length > 0); + }); +}); diff --git a/genai/test/live-ground-googsearch-with-txt.test.js b/genai/test/live-ground-googsearch-with-txt.test.js new file mode 100644 index 0000000000..6c1be019d3 --- /dev/null +++ b/genai/test/live-ground-googsearch-with-txt.test.js @@ -0,0 +1,30 @@ +// 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 {assert} = require('chai'); +const {describe, it} = require('mocha'); + +const projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../live/live-ground-googsearch-with-txt.js'); + +describe('live-ground-googsearch-with-txt', () => { + it('should generate Google Search in a live session from a text prompt', async function () { + this.timeout(180000); + const output = await sample.generateLiveGoogleSearch(projectId); + console.log('Generated output:', output); + assert(output.length > 0); + }); +}); diff --git a/genai/test/live-with-txt.test.js b/genai/test/live-with-txt.test.js new file mode 100644 index 0000000000..a32139c3e0 --- /dev/null +++ b/genai/test/live-with-txt.test.js @@ -0,0 +1,30 @@ +// 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 {assert} = require('chai'); +const {describe, it} = require('mocha'); + +const projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../live/live-with-txt'); + +describe('live-with-txt', () => { + it('should generate content in a live session from a text prompt', async function () { + this.timeout(180000); + const output = await sample.generateLiveConversation(projectId); + console.log('Generated output:', output); + assert(output.length > 0); + }); +}); diff --git a/genai/tools/tools-vais-with-txt.js b/genai/tools/tools-vais-with-txt.js index 67f8d3f12f..58c31d021f 100644 --- a/genai/tools/tools-vais-with-txt.js +++ b/genai/tools/tools-vais-with-txt.js @@ -20,8 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; // (Developer) put your path Data Store -const DATASTORE = - 'projects/cloud-ai-devrel-softserve/locations/global/collections/default_collection/dataStores/example-adk-website-datastore_1755611010401'; +const DATASTORE = `projects/${GOOGLE_CLOUD_PROJECT}/locations/${GOOGLE_CLOUD_LOCATION}/collections/default_collection/dataStores/data-store-id `; async function generateContent( datastore = DATASTORE,