From ad2afbdc26ae0cdba4dabd0f71280fc477e48376 Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 31 Jul 2025 11:07:36 +0200 Subject: [PATCH 1/6] linter and all modules from content cache --- .../contentcache_create_with_txt_gcs_pdf.js | 87 +++++++++++++++++++ genai/content_cache/contentcache_delete.js | 53 +++++++++++ genai/content_cache/contentcache_list.js | 56 ++++++++++++ genai/content_cache/contentcache_update.js | 80 +++++++++++++++++ .../contentcache_use_with_txt.js | 58 +++++++++++++ genai/package.json | 1 + 6 files changed, 335 insertions(+) create mode 100644 genai/content_cache/contentcache_create_with_txt_gcs_pdf.js create mode 100644 genai/content_cache/contentcache_delete.js create mode 100644 genai/content_cache/contentcache_list.js create mode 100644 genai/content_cache/contentcache_update.js create mode 100644 genai/content_cache/contentcache_use_with_txt.js diff --git a/genai/content_cache/contentcache_create_with_txt_gcs_pdf.js b/genai/content_cache/contentcache_create_with_txt_gcs_pdf.js new file mode 100644 index 0000000000..f5f84fea12 --- /dev/null +++ b/genai/content_cache/contentcache_create_with_txt_gcs_pdf.js @@ -0,0 +1,87 @@ +// 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_contentcache_create_with_txt_gcs_pdf] + +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, + httpOptions: { + apiVersion: 'v1' + } + }); + + const systemInstruction = ` + You are an expert researcher. You always stick to the facts in the sources provided, and never make up new facts. + Now look at these research papers, and answer the following questions. + `; + + + const contents = [ + { + role: "user", + parts: [ + { + fileData: { + fileUri: "gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf", + mimeType: "application/pdf", + } + }, + { + fileData: { + fileUri: "gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf", + mimeType: "application/pdf", + } + } + ] + } + ]; + + + const content_cache = await ai.caches.create({ + model: 'gemini-2.5-flash', + config: { + contents: contents, + systemInstruction: systemInstruction, + displayName: 'example-cache', + ttl: '86400s' + }, + }); + + + console.log(content_cache); + console.log(content_cache.name); + + return content_cache.name; + +} + +// [END googlegenaisdk_contentcache_create_with_txt_gcs_pdf] + +module.exports = { + generateContent, +}; \ No newline at end of file diff --git a/genai/content_cache/contentcache_delete.js b/genai/content_cache/contentcache_delete.js new file mode 100644 index 0000000000..923b6d6ed7 --- /dev/null +++ b/genai/content_cache/contentcache_delete.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_contentcache_delete] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +const CACHE_NAME = 'projects/448220130128/locations/us-central1/cachedContents/4839555542676406272' + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION, + cacheName = CACHE_NAME +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + httpOptions: { + apiVersion: 'v1' + } + }); + + console.log('Removing cache') + const contentCache = await ai.caches.delete({ + name: cacheName + }); + + console.log(contentCache.text); + + return contentCache; + +} +// [END googlegenaisdk_contentcache_delete] + +module.exports = { + generateContent, +}; \ No newline at end of file diff --git a/genai/content_cache/contentcache_list.js b/genai/content_cache/contentcache_list.js new file mode 100644 index 0000000000..fa7a795805 --- /dev/null +++ b/genai/content_cache/contentcache_list.js @@ -0,0 +1,56 @@ +// 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_contentcache_list] + +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, + httpOptions: { + apiVersion: 'v1' + } + }); + + const contentCacheList = await ai.caches.list() + + + // Access individual properties of a ContentCache object(s) + const contentCacheNames = [] + for (const contentCache of contentCacheList.pageInternal) { + console.log(`Cache \`${contentCache.name}\` for model \`${contentCache.model}\``); + console.log(`Last updated at: ${contentCache.updateTime}`); + console.log(`Expires at: ${contentCache.expireTime}`); + contentCacheNames.push(contentCache.name); + } + console.log() + + return contentCacheNames; + +} +// [END googlegenaisdk_contentcache_list] + +module.exports = { + generateContent, +}; \ No newline at end of file diff --git a/genai/content_cache/contentcache_update.js b/genai/content_cache/contentcache_update.js new file mode 100644 index 0000000000..7f09f898e1 --- /dev/null +++ b/genai/content_cache/contentcache_update.js @@ -0,0 +1,80 @@ +// 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_contentcache_update] +const {GoogleGenAI} = require('@google/genai'); +const { DateTime } = require('luxon'); + + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +const CACHE_NAME = 'projects/448220130128/locations/us-central1/cachedContents/4839555542676406272' + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION, + cacheName = CACHE_NAME +) { + + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + httpOptions: { + apiVersion: 'v1' + } + }); + + let contentCache = await ai.caches.get({ + name: cacheName + }); + + console.log('Expire time', contentCache.expireTime); + + contentCache = await ai.caches.update({ + name: cacheName, + config: { + ttl: '36000s' + } + }); + + const expireTime = DateTime.fromISO(contentCache.expireTime, { zone: 'utc' }); + const now = DateTime.utc(); + const timeDiff = expireTime.diff(now, ['seconds']); + + console.log('Expire time (after update):', expireTime.toISO()); + console.log('Expire time (in seconds):', Math.floor(timeDiff.seconds)); + + const nextWeekUtc = DateTime.utc().plus({ days: 7 }); + console.log('Next week (UTC):', nextWeekUtc.toISO()); + + contentCache = await ai.caches.update({ + name: cacheName, + config: { + expireTime: nextWeekUtc + } + }); + + console.log('Expire time (after update):', contentCache.expireTime); + return contentCache; + +} +// [END googlegenaisdk_contentcache_update] + +module.exports = { + generateContent, +}; \ No newline at end of file diff --git a/genai/content_cache/contentcache_use_with_txt.js b/genai/content_cache/contentcache_use_with_txt.js new file mode 100644 index 0000000000..eaf6b0023a --- /dev/null +++ b/genai/content_cache/contentcache_use_with_txt.js @@ -0,0 +1,58 @@ +// 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_contentcache_use_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'; + +const CACHE_NAME = 'projects/448220130128/locations/us-central1/cachedContents/8186785596975349760' + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION, + cacheName = CACHE_NAME +){ + + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + httpOptions: { + apiVersion: 'v1' + } + }); + + const response = await ai.models.generateContent({ + model: 'gemini-2.5-flash', + contents: 'Summarize the pdfs', + config: { + cachedContent: cacheName + }, + }); + + console.log(response.text); + + return response.text; + +} +// [END googlegenaisdk_contentcache_use_with_txt] + +module.exports = { + generateContent, +}; \ No newline at end of file diff --git a/genai/package.json b/genai/package.json index 1786d292d9..d27c6c0db2 100644 --- a/genai/package.json +++ b/genai/package.json @@ -15,6 +15,7 @@ "dependencies": { "@google/genai": "^0.13.0", "axios": "^1.6.2", + "luxon": "^3.7.1", "supertest": "^7.0.0" }, "devDependencies": { From 52fde9fc6dd67b20c99bce3946383a26a575c1ca Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 31 Jul 2025 12:56:31 +0200 Subject: [PATCH 2/6] content-cache code with a tests --- .../content-cache-create-with-txt-gcs-pdf.js} | 45 +++++++++---------- .../content-cache-delete.js} | 14 +++--- .../content-cache-list.js} | 18 ++++---- .../content-cache-update.js} | 28 ++++++------ .../content-cache-use-with-txt.js} | 15 +++---- ...ent-cache-create-use-update-delete.test.js | 39 ++++++++++++++++ genai/test/contentcache_list.test.js | 29 ++++++++++++ 7 files changed, 124 insertions(+), 64 deletions(-) rename genai/{content_cache/contentcache_create_with_txt_gcs_pdf.js => content-cache/content-cache-create-with-txt-gcs-pdf.js} (76%) rename genai/{content_cache/contentcache_delete.js => content-cache/content-cache-delete.js} (87%) rename genai/{content_cache/contentcache_list.js => content-cache/content-cache-list.js} (86%) rename genai/{content_cache/contentcache_update.js => content-cache/content-cache-update.js} (85%) rename genai/{content_cache/contentcache_use_with_txt.js => content-cache/content-cache-use-with-txt.js} (88%) create mode 100644 genai/test/content-cache-create-use-update-delete.test.js create mode 100644 genai/test/contentcache_list.test.js diff --git a/genai/content_cache/contentcache_create_with_txt_gcs_pdf.js b/genai/content-cache/content-cache-create-with-txt-gcs-pdf.js similarity index 76% rename from genai/content_cache/contentcache_create_with_txt_gcs_pdf.js rename to genai/content-cache/content-cache-create-with-txt-gcs-pdf.js index f5f84fea12..f6718ca637 100644 --- a/genai/content_cache/contentcache_create_with_txt_gcs_pdf.js +++ b/genai/content-cache/content-cache-create-with-txt-gcs-pdf.js @@ -23,16 +23,14 @@ 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, httpOptions: { - apiVersion: 'v1' - } + apiVersion: 'v1', + }, }); const systemInstruction = ` @@ -40,48 +38,45 @@ async function generateContent( Now look at these research papers, and answer the following questions. `; - const contents = [ { - role: "user", + role: 'user', parts: [ { fileData: { - fileUri: "gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf", - mimeType: "application/pdf", - } + fileUri: + 'gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf', + mimeType: 'application/pdf', + }, }, { fileData: { - fileUri: "gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf", - mimeType: "application/pdf", - } - } - ] - } + fileUri: 'gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf', + mimeType: 'application/pdf', + }, + }, + ], + }, ]; - - const content_cache = await ai.caches.create({ + const contentCache = await ai.caches.create({ model: 'gemini-2.5-flash', config: { contents: contents, systemInstruction: systemInstruction, displayName: 'example-cache', - ttl: '86400s' + ttl: '86400s', }, }); + console.log(contentCache); + console.log(contentCache.name); - console.log(content_cache); - console.log(content_cache.name); - - return content_cache.name; - + return contentCache.name; } // [END googlegenaisdk_contentcache_create_with_txt_gcs_pdf] module.exports = { generateContent, -}; \ No newline at end of file +}; diff --git a/genai/content_cache/contentcache_delete.js b/genai/content-cache/content-cache-delete.js similarity index 87% rename from genai/content_cache/contentcache_delete.js rename to genai/content-cache/content-cache-delete.js index 923b6d6ed7..52ff15c1f8 100644 --- a/genai/content_cache/contentcache_delete.js +++ b/genai/content-cache/content-cache-delete.js @@ -20,7 +20,8 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -const CACHE_NAME = 'projects/448220130128/locations/us-central1/cachedContents/4839555542676406272' +const CACHE_NAME = + 'projects/448220130128/locations/us-central1/cachedContents/4839555542676406272'; async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, @@ -32,22 +33,21 @@ async function generateContent( project: projectId, location: location, httpOptions: { - apiVersion: 'v1' - } + apiVersion: 'v1', + }, }); - console.log('Removing cache') + console.log('Removing cache'); const contentCache = await ai.caches.delete({ - name: cacheName + name: cacheName, }); console.log(contentCache.text); return contentCache; - } // [END googlegenaisdk_contentcache_delete] module.exports = { generateContent, -}; \ No newline at end of file +}; diff --git a/genai/content_cache/contentcache_list.js b/genai/content-cache/content-cache-list.js similarity index 86% rename from genai/content_cache/contentcache_list.js rename to genai/content-cache/content-cache-list.js index fa7a795805..0980b694ad 100644 --- a/genai/content_cache/contentcache_list.js +++ b/genai/content-cache/content-cache-list.js @@ -29,28 +29,28 @@ async function generateContent( project: projectId, location: location, httpOptions: { - apiVersion: 'v1' - } + apiVersion: 'v1', + }, }); - const contentCacheList = await ai.caches.list() - + const contentCacheList = await ai.caches.list(); // Access individual properties of a ContentCache object(s) - const contentCacheNames = [] + const contentCacheNames = []; for (const contentCache of contentCacheList.pageInternal) { - console.log(`Cache \`${contentCache.name}\` for model \`${contentCache.model}\``); + console.log( + `Cache \`${contentCache.name}\` for model \`${contentCache.model}\`` + ); console.log(`Last updated at: ${contentCache.updateTime}`); console.log(`Expires at: ${contentCache.expireTime}`); contentCacheNames.push(contentCache.name); } - console.log() + console.log(); return contentCacheNames; - } // [END googlegenaisdk_contentcache_list] module.exports = { generateContent, -}; \ No newline at end of file +}; diff --git a/genai/content_cache/contentcache_update.js b/genai/content-cache/content-cache-update.js similarity index 85% rename from genai/content_cache/contentcache_update.js rename to genai/content-cache/content-cache-update.js index 7f09f898e1..2470e29ab2 100644 --- a/genai/content_cache/contentcache_update.js +++ b/genai/content-cache/content-cache-update.js @@ -16,31 +16,30 @@ // [START googlegenaisdk_contentcache_update] const {GoogleGenAI} = require('@google/genai'); -const { DateTime } = require('luxon'); - +const {DateTime} = require('luxon'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -const CACHE_NAME = 'projects/448220130128/locations/us-central1/cachedContents/4839555542676406272' +const CACHE_NAME = + 'projects/448220130128/locations/us-central1/cachedContents/4839555542676406272'; async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION, cacheName = CACHE_NAME ) { - const ai = new GoogleGenAI({ vertexai: true, project: projectId, location: location, httpOptions: { - apiVersion: 'v1' - } + apiVersion: 'v1', + }, }); let contentCache = await ai.caches.get({ - name: cacheName + name: cacheName, }); console.log('Expire time', contentCache.expireTime); @@ -48,33 +47,32 @@ async function generateContent( contentCache = await ai.caches.update({ name: cacheName, config: { - ttl: '36000s' - } + ttl: '36000s', + }, }); - const expireTime = DateTime.fromISO(contentCache.expireTime, { zone: 'utc' }); + const expireTime = DateTime.fromISO(contentCache.expireTime, {zone: 'utc'}); const now = DateTime.utc(); const timeDiff = expireTime.diff(now, ['seconds']); console.log('Expire time (after update):', expireTime.toISO()); console.log('Expire time (in seconds):', Math.floor(timeDiff.seconds)); - const nextWeekUtc = DateTime.utc().plus({ days: 7 }); + const nextWeekUtc = DateTime.utc().plus({days: 7}); console.log('Next week (UTC):', nextWeekUtc.toISO()); contentCache = await ai.caches.update({ name: cacheName, config: { - expireTime: nextWeekUtc - } + expireTime: nextWeekUtc, + }, }); console.log('Expire time (after update):', contentCache.expireTime); return contentCache; - } // [END googlegenaisdk_contentcache_update] module.exports = { generateContent, -}; \ No newline at end of file +}; diff --git a/genai/content_cache/contentcache_use_with_txt.js b/genai/content-cache/content-cache-use-with-txt.js similarity index 88% rename from genai/content_cache/contentcache_use_with_txt.js rename to genai/content-cache/content-cache-use-with-txt.js index eaf6b0023a..20a6c28791 100644 --- a/genai/content_cache/contentcache_use_with_txt.js +++ b/genai/content-cache/content-cache-use-with-txt.js @@ -21,38 +21,37 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -const CACHE_NAME = 'projects/448220130128/locations/us-central1/cachedContents/8186785596975349760' +const CACHE_NAME = + 'projects/448220130128/locations/us-central1/cachedContents/8186785596975349760'; async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION, cacheName = CACHE_NAME -){ - +) { const ai = new GoogleGenAI({ vertexai: true, project: projectId, location: location, httpOptions: { - apiVersion: 'v1' - } + apiVersion: 'v1', + }, }); const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Summarize the pdfs', config: { - cachedContent: cacheName + cachedContent: cacheName, }, }); console.log(response.text); return response.text; - } // [END googlegenaisdk_contentcache_use_with_txt] module.exports = { generateContent, -}; \ No newline at end of file +}; diff --git a/genai/test/content-cache-create-use-update-delete.test.js b/genai/test/content-cache-create-use-update-delete.test.js new file mode 100644 index 0000000000..5638c27908 --- /dev/null +++ b/genai/test/content-cache-create-use-update-delete.test.js @@ -0,0 +1,39 @@ +'use strict'; + +const {assert} = require('chai'); +const {describe, it} = require('mocha'); + +const projectId = process.env.CAIP_PROJECT_ID; + +const createSample = require('../content-cache/content-cache-create-with-txt-gcs-pdf.js'); +const useSample = require('../content-cache/content-cache-use-with-txt.js'); +const updateSample = require('../content-cache/content-cache-update.js'); +const deleteSample = require('../content-cache/content-cache-delete.js'); + +describe('content-cache-create-use-update-delete', function () { + this.timeout(60000); + let contentCacheName; + + it('should create content cache', async () => { + contentCacheName = await createSample.generateContent(projectId); + assert.isString(contentCacheName); + assert.isAbove(contentCacheName.length, 0); + }); + + it('should update content cache', async () => { + await updateSample.generateContent(projectId, undefined, contentCacheName); + }); + + it('should use content cache', async () => { + const response = await useSample.generateContent( + projectId, + undefined, + contentCacheName + ); + assert.isString(response); + }); + + it('should delete content cache', async () => { + await deleteSample.generateContent(projectId, undefined, contentCacheName); + }); +}); diff --git a/genai/test/contentcache_list.test.js b/genai/test/contentcache_list.test.js new file mode 100644 index 0000000000..06fcf32db7 --- /dev/null +++ b/genai/test/contentcache_list.test.js @@ -0,0 +1,29 @@ +// 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('../content-cache/content-cache-list.js'); + +describe('contentcache-list', async () => { + it('should return object with names of catches', async () => { + const output = await sample.generateContent(projectId); + assert.isArray(output); + assert.isAbove(output.length, 0); + }); +}); From a2fccb5e08461ba5d1e1dc3b668567a8993caf88 Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 31 Jul 2025 12:58:36 +0200 Subject: [PATCH 3/6] content-cache code with tests --- genai/content-cache/content-cache-delete.js | 5 +---- genai/content-cache/content-cache-update.js | 4 +--- genai/content-cache/content-cache-use-with-txt.js | 4 +--- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/genai/content-cache/content-cache-delete.js b/genai/content-cache/content-cache-delete.js index 52ff15c1f8..a71c8c2e31 100644 --- a/genai/content-cache/content-cache-delete.js +++ b/genai/content-cache/content-cache-delete.js @@ -20,13 +20,10 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -const CACHE_NAME = - 'projects/448220130128/locations/us-central1/cachedContents/4839555542676406272'; - async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION, - cacheName = CACHE_NAME + cacheName ) { const ai = new GoogleGenAI({ vertexai: true, diff --git a/genai/content-cache/content-cache-update.js b/genai/content-cache/content-cache-update.js index 2470e29ab2..4bb6acb6dd 100644 --- a/genai/content-cache/content-cache-update.js +++ b/genai/content-cache/content-cache-update.js @@ -21,13 +21,11 @@ const {DateTime} = require('luxon'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -const CACHE_NAME = - 'projects/448220130128/locations/us-central1/cachedContents/4839555542676406272'; async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION, - cacheName = CACHE_NAME + cacheName ) { const ai = new GoogleGenAI({ vertexai: true, diff --git a/genai/content-cache/content-cache-use-with-txt.js b/genai/content-cache/content-cache-use-with-txt.js index 20a6c28791..c0148d9063 100644 --- a/genai/content-cache/content-cache-use-with-txt.js +++ b/genai/content-cache/content-cache-use-with-txt.js @@ -21,13 +21,11 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -const CACHE_NAME = - 'projects/448220130128/locations/us-central1/cachedContents/8186785596975349760'; async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION, - cacheName = CACHE_NAME + cacheName ) { const ai = new GoogleGenAI({ vertexai: true, From c01d51e925b8917c20896dccc3a8e7fc5abb7ef9 Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 1 Aug 2025 11:12:08 +0200 Subject: [PATCH 4/6] bumping version and fixing tests --- .../content-cache-create-use-update-delete.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/genai/test/content-cache-create-use-update-delete.test.js b/genai/test/content-cache-create-use-update-delete.test.js index 5638c27908..789c770eeb 100644 --- a/genai/test/content-cache-create-use-update-delete.test.js +++ b/genai/test/content-cache-create-use-update-delete.test.js @@ -1,3 +1,17 @@ +// 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'); From 09d739bebe729d728ad0e17da8727ed4c8eaa374 Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 1 Aug 2025 11:12:54 +0200 Subject: [PATCH 5/6] bumping version and fixing tests --- genai/content-cache/content-cache-update.js | 1 - genai/content-cache/content-cache-use-with-txt.js | 1 - 2 files changed, 2 deletions(-) diff --git a/genai/content-cache/content-cache-update.js b/genai/content-cache/content-cache-update.js index 4bb6acb6dd..17924a5dfc 100644 --- a/genai/content-cache/content-cache-update.js +++ b/genai/content-cache/content-cache-update.js @@ -21,7 +21,6 @@ const {DateTime} = require('luxon'); 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, diff --git a/genai/content-cache/content-cache-use-with-txt.js b/genai/content-cache/content-cache-use-with-txt.js index c0148d9063..759bce2ea6 100644 --- a/genai/content-cache/content-cache-use-with-txt.js +++ b/genai/content-cache/content-cache-use-with-txt.js @@ -21,7 +21,6 @@ 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, From d2adbeb48f6e7093972e421d13ec1515a75b5ae0 Mon Sep 17 00:00:00 2001 From: Guiners Date: Mon, 11 Aug 2025 17:08:11 +0200 Subject: [PATCH 6/6] adding samples, test, lints --- .../{contentcache_list.test.js => content-cache-list.test.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename genai/test/{contentcache_list.test.js => content-cache-list.test.js} (100%) diff --git a/genai/test/contentcache_list.test.js b/genai/test/content-cache-list.test.js similarity index 100% rename from genai/test/contentcache_list.test.js rename to genai/test/content-cache-list.test.js