Skip to content

Commit e29c4b7

Browse files
authored
Revert "refactor(genai): migrate region tags from generative-ai to genai folder (Batch 1)" (#4339)
* Revert "refactor(genai): migrate region tags from generative-ai to genai folder (Batch 2) (#4336)" This reverts commit 7517761. * Revert "refactor(genai): migrate region tags from generative-ai to genai folder (Batch 1) (#4335)" This reverts commit f2465a6.
1 parent 087a61d commit e29c4b7

29 files changed

Lines changed: 996 additions & 20 deletions

genai/count-tokens/counttoken-resp-with-txt.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
'use strict';
16-
// [START generativeaionvertexai_gemini_token_count]
16+
1717
// [START googlegenaisdk_counttoken_resp_with_txt]
1818
const {GoogleGenAI} = require('@google/genai');
1919

@@ -41,7 +41,6 @@ async function countTokens(
4141
return response.usageMetadata;
4242
}
4343
// [END googlegenaisdk_counttoken_resp_with_txt]
44-
// [END generativeaionvertexai_gemini_token_count]
4544

4645
module.exports = {
4746
countTokens,

genai/count-tokens/counttoken-with-txt-vid.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
'use strict';
1616

17-
// [START generativeaionvertexai_gemini_token_count_advanced]
1817
// [START googlegenaisdk_counttoken_with_txt_vid]
1918
const {GoogleGenAI} = require('@google/genai');
2019

@@ -48,7 +47,6 @@ async function countTokens(
4847
return response.totalTokens;
4948
}
5049
// [END googlegenaisdk_counttoken_with_txt_vid]
51-
// [END generativeaionvertexai_gemini_token_count_advanced]
5250

5351
module.exports = {
5452
countTokens,

genai/text-generation/textgen-sys-instr-with-txt.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
'use strict';
1616

17-
// [START generativeaionvertexai_gemini_translate]
18-
// [START generativeaionvertexai_gemini_system_instruction]
1917
// [START googlegenaisdk_textgen_sys_instr_with_txt]
2018
const {GoogleGenAI} = require('@google/genai');
2119

@@ -53,8 +51,6 @@ async function generateContent(
5351
return response.text;
5452
}
5553
// [END googlegenaisdk_textgen_sys_instr_with_txt]
56-
// [END generativeaionvertexai_gemini_system_instruction]
57-
// [END generativeaionvertexai_gemini_translate]
5854

5955
module.exports = {
6056
generateContent,

genai/text-generation/textgen-transcript-with-gcs-audio.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
'use strict';
16-
// [START generativeaionvertexai_gemini_audio_transcription]
16+
1717
// [START googlegenaisdk_textgen_transcript_with_gcs_audio]
1818
const {GoogleGenAI} = require('@google/genai');
1919

@@ -63,7 +63,6 @@ async function generateText(
6363
}
6464

6565
// [END googlegenaisdk_textgen_transcript_with_gcs_audio]
66-
// [END generativeaionvertexai_gemini_audio_transcription]
6766

6867
module.exports = {
6968
generateText,

genai/text-generation/textgen-with-gcs-audio.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
'use strict';
16-
// [START generativeaionvertexai_gemini_audio_summarization]
16+
1717
// [START googlegenaisdk_textgen_with_gcs_audio]
1818
const {GoogleGenAI} = require('@google/genai');
1919

@@ -55,7 +55,6 @@ async function generateText(
5555
return response.text;
5656
}
5757
// [END googlegenaisdk_textgen_with_gcs_audio]
58-
// [END generativeaionvertexai_gemini_audio_summarization]
5958

6059
module.exports = {
6160
generateText,

genai/text-generation/textgen-with-pdf.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
'use strict';
16-
// [START generativeaionvertexai_gemini_pdf]
16+
1717
// [START googlegenaisdk_textgen_with_pdf]
1818
const {GoogleGenAI} = require('@google/genai');
1919

@@ -59,7 +59,6 @@ async function generateText(
5959
}
6060

6161
// [END googlegenaisdk_textgen_with_pdf]
62-
// [END generativeaionvertexai_gemini_pdf]
6362

6463
module.exports = {
6564
generateText,

genai/text-generation/textgen-with-txt-stream.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
'use strict';
16-
// [START generativeaionvertexai_stream_text_basic]
16+
1717
// [START googlegenaisdk_textgen_with_txt_stream]
1818
const {GoogleGenAI} = require('@google/genai');
1919

@@ -43,7 +43,6 @@ async function generateContent(
4343
return response_text;
4444
}
4545
// [END googlegenaisdk_textgen_with_txt_stream]
46-
// [END generativeaionvertexai_stream_text_basic]
4746

4847
module.exports = {
4948
generateContent,

genai/text-generation/textgen-with-txt.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
'use strict';
16-
// [START generativeaionvertexai_gemini_generate_from_text_input]
16+
1717
// [START googlegenaisdk_textgen_with_txt]
1818
const {GoogleGenAI} = require('@google/genai');
1919

@@ -40,7 +40,6 @@ async function generateContent(
4040
return response.text;
4141
}
4242
// [END googlegenaisdk_textgen_with_txt]
43-
// [END generativeaionvertexai_gemini_generate_from_text_input]
4443

4544
module.exports = {
4645
generateContent,

genai/tools/tools-func-desc-with-txt.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
'use strict';
1616

17-
// [START generativeaionvertexai_function_calling_advanced]
1817
// [START googlegenaisdk_tools_func_desc_with_txt]
1918
const {GoogleGenAI, Type} = require('@google/genai');
2019

@@ -100,7 +99,6 @@ async function generateFunctionDesc(
10099
}
101100

102101
// [END googlegenaisdk_tools_func_desc_with_txt]
103-
// [END generativeaionvertexai_function_calling_advanced]
104102

105103
module.exports = {
106104
generateFunctionDesc,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2024 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+
// [START generativeaionvertexai_gemini_token_count]
16+
const {GoogleGenAI} = require('@google/genai');
17+
18+
/**
19+
* TODO(developer): Update these variables before running the sample.
20+
*/
21+
async function countTokens(
22+
projectId = 'PROJECT_ID',
23+
location = 'us-central1',
24+
model = 'gemini-2.5-flash'
25+
) {
26+
// Initialize the client with your Cloud project and location
27+
const client = new GoogleGenAI({
28+
vertexai: true,
29+
project: projectId,
30+
location: location,
31+
});
32+
33+
const contents = [
34+
{role: 'user', parts: [{text: 'How are you doing today?'}]},
35+
];
36+
37+
// Prompt tokens count
38+
const countTokensResp = await client.models.countTokens({
39+
model: model,
40+
contents: contents,
41+
});
42+
console.log('Prompt tokens count: ', countTokensResp);
43+
44+
// Send text to gemini
45+
const result = await client.models.generateContent({
46+
model: model,
47+
contents: contents,
48+
});
49+
50+
// Response tokens count
51+
const usageMetadata = result.usageMetadata;
52+
console.log('Response tokens count: ', usageMetadata);
53+
}
54+
// [END generativeaionvertexai_gemini_token_count]
55+
56+
countTokens(...process.argv.slice(2)).catch(err => {
57+
console.error(err.message);
58+
process.exitCode = 1;
59+
});

0 commit comments

Comments
 (0)