Skip to content

Commit ecead08

Browse files
wanlin31copybara-github
authored andcommitted
chore: scrub and name prefix exclusion testing
FUTURE_COPYBARA_INTEGRATE_REVIEW=#1090 from googleapis:release-please--branches--main--components--genai bbf62d2 PiperOrigin-RevId: 833889208
1 parent 38cac5b commit ecead08

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

sdk-samples/copy_api_error.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
import {GoogleGenAI} from '@google/genai';
7+
8+
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
9+
const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
10+
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION;
11+
const GOOGLE_GENAI_USE_VERTEXAI = process.env.GOOGLE_GENAI_USE_VERTEXAI;
12+
13+
async function throwApiErrorForMLDev() {
14+
const ai = new GoogleGenAI({apiKey: GEMINI_API_KEY});
15+
const response = await ai.models.generateContent({
16+
model: 'non-existent-model',
17+
contents: 'Tell me a story in 300 words?',
18+
});
19+
console.log('text response: ', response.text);
20+
}
21+
22+
async function throwApiErrorForVertexAI() {
23+
const ai = new GoogleGenAI({
24+
vertexai: true,
25+
project: GOOGLE_CLOUD_PROJECT,
26+
location: GOOGLE_CLOUD_LOCATION,
27+
});
28+
const response = await ai.models.generateContent({
29+
model: 'non-existent-model',
30+
contents: 'Tell me a story in 300 words?',
31+
});
32+
33+
console.log('text response: ', response.text);
34+
}
35+
36+
async function main() {
37+
if (GOOGLE_GENAI_USE_VERTEXAI) {
38+
await throwApiErrorForVertexAI().catch((e) => {
39+
console.error('error name: ', e.name);
40+
console.error('error message: ', e.message);
41+
console.error('error status: ', e.status);
42+
});
43+
} else {
44+
await throwApiErrorForMLDev().catch((e) => {
45+
console.error('error name: ', e.name);
46+
console.error('error message: ', e.message);
47+
console.error('error status: ', e.status);
48+
});
49+
}
50+
}
51+
52+
main();

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
// Testing
8+
79
export {BaseUrlParameters, setDefaultBaseUrls} from './_base_url';
810
export * from './batches';
911
export * from './caches';

0 commit comments

Comments
 (0)