diff --git a/genai/count-tokens/counttoken-with-txt.js b/genai/count-tokens/counttoken-with-txt.js new file mode 100644 index 0000000000..eb82c348bf --- /dev/null +++ b/genai/count-tokens/counttoken-with-txt.js @@ -0,0 +1,46 @@ +// 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_counttoken_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 countTokens( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await ai.models.countTokens({ + model: 'gemini-2.0-flash', + contents: 'What is the highest mountain in Africa?', + }); + + console.log(response); + + return response.totalTokens; +} +// [END googlegenaisdk_counttoken_with_txt] + +module.exports = { + countTokens, +}; diff --git a/genai/package.json b/genai/package.json new file mode 100644 index 0000000000..1786d292d9 --- /dev/null +++ b/genai/package.json @@ -0,0 +1,27 @@ +{ + "name": "nodejs-genai-samples", + "private": true, + "license": "Apache-2.0", + "author": "Google LLC", + "engines": { + "node": ">=16.0.0" + }, + "files": [ + "*.js" + ], + "scripts": { + "test": "c8 mocha -p -j 2 --timeout 2400000 test/*.test.js test/**/*.test.js" + }, + "dependencies": { + "@google/genai": "^0.13.0", + "axios": "^1.6.2", + "supertest": "^7.0.0" + }, + "devDependencies": { + "c8": "^10.0.0", + "chai": "^4.5.0", + "mocha": "^10.0.0", + "sinon": "^18.0.0", + "uuid": "^10.0.0" + } +} diff --git a/genai/test/counttoken-with-txt.test.js b/genai/test/counttoken-with-txt.test.js new file mode 100644 index 0000000000..85d8f2153b --- /dev/null +++ b/genai/test/counttoken-with-txt.test.js @@ -0,0 +1,28 @@ +// 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('../count-tokens/counttoken-with-txt.js'); + +describe('counttoken-with-txt', async () => { + it('should return the total token count for a text prompt', async () => { + const output = await sample.countTokens(projectId); + assert(output > 0); + }); +}); diff --git a/genai/test/textgen-sys-instr-with-txt.test.js b/genai/test/textgen-sys-instr-with-txt.test.js new file mode 100644 index 0000000000..0162870b75 --- /dev/null +++ b/genai/test/textgen-sys-instr-with-txt.test.js @@ -0,0 +1,28 @@ +// 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('../text-generation/textgen-sys-instr-with-txt.js'); + +describe('textgen-sys-instr-with-txt', async () => { + it('should generate text content from a text prompt and with system instructions', async () => { + const output = await sample.generateContent(projectId); + assert(output.length > 0 && output.includes('bagels')); + }); +}); diff --git a/genai/test/textgen-with-multi-img.test.js b/genai/test/textgen-with-multi-img.test.js new file mode 100644 index 0000000000..64f80a6442 --- /dev/null +++ b/genai/test/textgen-with-multi-img.test.js @@ -0,0 +1,28 @@ +// 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('../text-generation/textgen-with-multi-img.js'); + +describe('textgen-with-multi-img', async () => { + it('should generate text content from a text prompt and multiple images', async () => { + const output = await sample.generateContent(projectId); + assert(output.length > 0 && output.includes('blueberry')); + }); +}); diff --git a/genai/test/textgen-with-txt-img.test.js b/genai/test/textgen-with-txt-img.test.js new file mode 100644 index 0000000000..fc4e4deb1b --- /dev/null +++ b/genai/test/textgen-with-txt-img.test.js @@ -0,0 +1,28 @@ +// 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('../text-generation/textgen-with-txt-img.js'); + +describe('textgen-with-txt-img', async () => { + it('should generate text content from a text prompt and an image', async () => { + const output = await sample.generateContent(projectId); + assert(output.length > 0 && output.includes('image')); + }); +}); diff --git a/genai/test/textgen-with-txt-stream.test.js b/genai/test/textgen-with-txt-stream.test.js new file mode 100644 index 0000000000..6e818a89cb --- /dev/null +++ b/genai/test/textgen-with-txt-stream.test.js @@ -0,0 +1,28 @@ +// 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('../text-generation/textgen-with-txt-stream.js'); + +describe('textgen-with-txt-stream', async () => { + it('should generate streaming text content from a text prompt', async () => { + const output = await sample.generateContent(projectId); + assert(output.length > 0 && output.includes('sky')); + }); +}); diff --git a/genai/test/textgen-with-txt.test.js b/genai/test/textgen-with-txt.test.js new file mode 100644 index 0000000000..d3d2473774 --- /dev/null +++ b/genai/test/textgen-with-txt.test.js @@ -0,0 +1,28 @@ +// 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('../text-generation/textgen-with-txt.js'); + +describe('textgen-with-txt', async () => { + it('should generate text content from a text prompt', async () => { + const output = await sample.generateContent(projectId); + assert(output.length > 0 && output.includes('AI')); + }); +}); diff --git a/genai/test/textgen-with-video.test.js b/genai/test/textgen-with-video.test.js new file mode 100644 index 0000000000..0f967cdfe0 --- /dev/null +++ b/genai/test/textgen-with-video.test.js @@ -0,0 +1,28 @@ +// 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('../text-generation/textgen-with-video.js'); + +describe('textgen-with-video', async () => { + it('should generate text content from a text prompt and a video', async () => { + const output = await sample.generateContent(projectId); + assert(output.length > 0 && output.includes('video')); + }); +}); diff --git a/genai/test/tools-func-desc-with-txt.test.js b/genai/test/tools-func-desc-with-txt.test.js new file mode 100644 index 0000000000..d627a52aaf --- /dev/null +++ b/genai/test/tools-func-desc-with-txt.test.js @@ -0,0 +1,28 @@ +// 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('../tools/tools-func-desc-with-txt.js'); + +describe('tools-func-desc-with-txt', async () => { + it('should generate a function call', async () => { + const output = await sample.generateContent(projectId); + assert(output.length > 0); + }); +}); diff --git a/genai/text-generation/textgen-sys-instr-with-txt.js b/genai/text-generation/textgen-sys-instr-with-txt.js new file mode 100644 index 0000000000..c08810d71d --- /dev/null +++ b/genai/text-generation/textgen-sys-instr-with-txt.js @@ -0,0 +1,57 @@ +// 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_textgen_sys_instr_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 ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const prompt = ` + User input: I like bagels. + Answer: + `; + + const response = await ai.models.generateContent({ + model: 'gemini-2.0-flash', + contents: prompt, + config: { + systemInstruction: [ + 'You are a language translator.', + 'Your mission is to translate text in English to French.', + ], + }, + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_sys_instr_with_txt] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-with-multi-img.js b/genai/text-generation/textgen-with-multi-img.js new file mode 100644 index 0000000000..13edbe4bea --- /dev/null +++ b/genai/text-generation/textgen-with-multi-img.js @@ -0,0 +1,64 @@ +// 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_textgen_with_multi_img] +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 ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const image1 = { + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/image/scones.jpg', + mimeType: 'image/jpeg', + }, + }; + + const image2 = { + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/image/fruit.png', + mimeType: 'image/png', + }, + }; + + const response = await ai.models.generateContent({ + model: 'gemini-2.0-flash', + contents: [ + image1, + image2, + 'Generate a list of all the objects contained in both images.', + ], + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_with_multi_img] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-with-txt-img.js b/genai/text-generation/textgen-with-txt-img.js new file mode 100644 index 0000000000..ec4b45200a --- /dev/null +++ b/genai/text-generation/textgen-with-txt-img.js @@ -0,0 +1,53 @@ +// 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_textgen_with_txt_img] +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 ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const image = { + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/image/scones.jpg', + mimeType: 'image/jpeg', + }, + }; + + const response = await ai.models.generateContent({ + model: 'gemini-2.0-flash', + contents: [image, 'What is shown in this image?'], + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_with_txt_img] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-with-txt-stream.js b/genai/text-generation/textgen-with-txt-stream.js new file mode 100644 index 0000000000..061151a5fa --- /dev/null +++ b/genai/text-generation/textgen-with-txt-stream.js @@ -0,0 +1,49 @@ +// 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_textgen_with_txt_stream] +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 ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await ai.models.generateContentStream({ + model: 'gemini-2.0-flash', + contents: 'Why is the sky blue?', + }); + + let response_text = ''; + for await (const chunk of response) { + response_text += chunk.text; + console.log(chunk.text); + } + return response_text; +} +// [END googlegenaisdk_textgen_with_txt_stream] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-with-txt.js b/genai/text-generation/textgen-with-txt.js new file mode 100644 index 0000000000..ea44a4009a --- /dev/null +++ b/genai/text-generation/textgen-with-txt.js @@ -0,0 +1,46 @@ +// 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_textgen_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 ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await ai.models.generateContent({ + model: 'gemini-2.0-flash', + contents: 'How does AI work?', + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_with_txt] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-with-video.js b/genai/text-generation/textgen-with-video.js new file mode 100644 index 0000000000..5ae4182522 --- /dev/null +++ b/genai/text-generation/textgen-with-video.js @@ -0,0 +1,59 @@ +// 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_textgen_with_video] +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 ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const prompt = ` + Analyze the provided video file, including its audio. + Summarize the main points of the video concisely. + Create a chapter breakdown with timestamps for key sections or topics discussed. + `; + + const video = { + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/video/pixel8.mp4', + mimeType: 'video/mp4', + }, + }; + + const response = await ai.models.generateContent({ + model: 'gemini-2.0-flash', + contents: [video, prompt], + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_with_video] + +module.exports = { + generateContent, +}; diff --git a/genai/tools/tools-func-desc-with-txt.js b/genai/tools/tools-func-desc-with-txt.js new file mode 100644 index 0000000000..6790de561a --- /dev/null +++ b/genai/tools/tools-func-desc-with-txt.js @@ -0,0 +1,91 @@ +// 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_func_desc_with_txt] +const {GoogleGenAI, Type} = 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 ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const get_album_sales = { + name: 'get_album_sales', + description: 'Gets the number of albums sold', + parameters: { + type: Type.OBJECT, + properties: { + albums: { + type: Type.ARRAY, + description: 'List of albums', + items: { + description: 'Album and its sales', + type: Type.OBJECT, + properties: { + album_name: { + type: Type.STRING, + description: 'Name of the music album', + }, + copies_sold: { + type: Type.INTEGER, + description: 'Number of copies sold', + }, + }, + }, + }, + }, + }, + }; + + const sales_tool = { + functionDeclarations: [get_album_sales], + }; + + const prompt = ` + At Stellar Sounds, a music label, 2024 was a rollercoaster. "Echoes of the Night", a debut synth-pop album, + surprisingly sold 350,000 copies, while veteran rock band "Crimson Tide's" latest, "Reckless Hearts", + lagged at 120,000. Their up-and-coming indie artist, "Luna Bloom's" EP, "Whispers of Dawn", + secured 75,000 sales. The biggest disappointment was the highly-anticipated rap album "Street Symphony" + only reaching 100,000 units. Overall, Stellar Sounds moved over 645,000 units this year, revealing unexpected + trends in music consumption. + `; + + const response = await ai.models.generateContent({ + model: 'gemini-2.0-flash', + contents: prompt, + config: { + tools: [sales_tool], + temperature: 0, + }, + }); + + console.log(response.functionCalls); + + return response.functionCalls; +} +// [END googlegenaisdk_tools_func_desc_with_txt] + +module.exports = { + generateContent, +};