Skip to content

Commit ba6e10f

Browse files
committed
feat(genai): Add GenAI SDK samples (1)
1 parent 72824d9 commit ba6e10f

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

genai/package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "nodejs-genai-samples",
3+
"private": true,
4+
"license": "Apache-2.0",
5+
"author": "Google LLC",
6+
"engines": {
7+
"node": ">=16.0.0"
8+
},
9+
"files": [
10+
"*.js"
11+
],
12+
"scripts": {
13+
"test": "c8 mocha -p -j 2 --timeout 2400000 test/*.test.js test/**/*.test.js"
14+
},
15+
"dependencies": {
16+
"@google/genai": "^0.13.0",
17+
"axios": "^1.6.2",
18+
"supertest": "^7.0.0"
19+
},
20+
"devDependencies": {
21+
"c8": "^10.0.0",
22+
"chai": "^4.5.0",
23+
"mocha": "^10.0.0",
24+
"sinon": "^18.0.0",
25+
"uuid": "^10.0.0"
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
20+
const projectId = process.env.CAIP_PROJECT_ID;
21+
const sample = require('../text-generation/textgen-with-txt.js');
22+
23+
describe('textgen-with-txt', async () => {
24+
it('should generate text content from a text prompt', async () => {
25+
const output = await sample.generateContent(projectId);
26+
assert(output.length > 0);
27+
});
28+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
// [START googlegenaisdk_textgen_with_txt]
18+
const {GoogleGenAI} = require('@google/genai');
19+
20+
async function generateContent(
21+
projectId = process.env.GOOGLE_CLOUD_PROJECT,
22+
location = process.env.GOOGLE_CLOUD_LOCATION || 'global'
23+
) {
24+
const ai = new GoogleGenAI({
25+
vertexai: true,
26+
project: projectId,
27+
location: location,
28+
});
29+
30+
const response = await ai.models.generateContent({
31+
model: 'gemini-2.0-flash',
32+
contents: 'How does AI work?',
33+
});
34+
35+
return response.text;
36+
}
37+
// [END googlegenaisdk_textgen_with_txt]
38+
39+
module.exports = {
40+
generateContent,
41+
};

0 commit comments

Comments
 (0)