Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions genai/test/textgen-async-with-txt.test.js
Original file line number Diff line number Diff line change
@@ -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('../text-generation/textgen-async-with-txt.js');

describe('textgen-async-with-txt', () => {
it('should generate text content from a text prompt and with system instructions', async function () {
this.timeout(100000);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
29 changes: 29 additions & 0 deletions genai/test/textgen-chat-stream-with-txt.test.js
Original file line number Diff line number Diff line change
@@ -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('../text-generation/textgen-chat-stream-with-txt.js');

describe('textgen-chat-stream-with-txt', () => {
it('should generate text content from a mute video', async function () {
this.timeout(100000);
const output = await sample.generateText(projectId);
assert.isTrue(output);
});
});
29 changes: 29 additions & 0 deletions genai/test/textgen-chat-with-txt.test.js
Original file line number Diff line number Diff line change
@@ -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('../text-generation/textgen-chat-with-txt.js');

describe('textgen-chat-with-txt', () => {
it('should generate chat content from a text prompt', async function () {
this.timeout(100000);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
2 changes: 1 addition & 1 deletion genai/test/textgen-code-with-pdf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const sample = require('../text-generation/textgen-code-with-pdf.js');
describe('textgen-code-with-pdf', () => {
it('should generate text content from a pdf', async function () {
this.timeout(100000);
const output = await sample.generateContent(projectId);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
29 changes: 29 additions & 0 deletions genai/test/textgen-config-with-txt.test.js
Original file line number Diff line number Diff line change
@@ -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('../text-generation/textgen-config-with-txt.js');

describe('textgen-config-with-txt', () => {
it('should generate text content from a text prompt with config', async function () {
this.timeout(100000);
const output = await sample.generateContent(projectId);
assert(output.length > 0);
});
});
29 changes: 29 additions & 0 deletions genai/test/textgen-with-mute-video.test.js
Original file line number Diff line number Diff line change
@@ -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('../text-generation/textgen-with-mute-video.js');

describe('textgen-with-mute-video', () => {
it('should generate text content from a mute video', async function () {
this.timeout(100000);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
56 changes: 56 additions & 0 deletions genai/text-generation/textgen-async-with-txt.js
Original file line number Diff line number Diff line change
@@ -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_textgen_async_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 generateText(
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:
'Compose a song about the adventures of a time-traveling squirrel.',
config: {
responseMimeType: 'text/plain',
},
});

console.log(response.text);

// Example response:
// (Verse 1)
// Sammy the nugget, a furry little friend
// Had a knack for adventure, beyond all comprehend

return response.text;
}

// [END googlegenaisdk_textgen_async_with_txt]

module.exports = {
generateText,
};
54 changes: 54 additions & 0 deletions genai/text-generation/textgen-chat-stream-with-txt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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_chat_stream_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 generateText(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const chatSession = client.chats.create({
model: 'gemini-2.5-flash',
});

for await (const chunk of await chatSession.sendMessageStream({
message: 'Why is the sky blue?',
})) {
console.log(chunk.text);
}
// Example response:
// The
// sky appears blue due to a phenomenon called **Rayleigh scattering**. Here's
// a breakdown of why:
// ...
return true;
}

// [END googlegenaisdk_textgen_chat_stream_with_txt]

module.exports = {
generateText,
};
61 changes: 61 additions & 0 deletions genai/text-generation/textgen-chat-with-txt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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_chat_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 generateText(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const chatSession = client.chats.create({
model: 'gemini-2.5-flash',
history: [
{
role: 'user',
parts: [{text: 'Hello'}],
},
{
role: 'model',
parts: [{text: 'Great to meet you. What would you like to know?'}],
},
],
});

const response = await chatSession.sendMessage({message: 'Tell me a story.'});
console.log(response.text);

// Example response:
// Okay, here's a story for you:
// ...

return response.text;
}

// [END googlegenaisdk_textgen_chat_with_txt]

module.exports = {
generateText,
};
4 changes: 2 additions & 2 deletions genai/text-generation/textgen-code-with-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +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';

async function generateContent(
async function generateText(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
Expand Down Expand Up @@ -74,5 +74,5 @@ async function generateContent(
// [END googlegenaisdk_textgen_code_with_pdf]

module.exports = {
generateContent,
generateText,
};
Loading
Loading