Skip to content

Commit d83b22e

Browse files
committed
Import firebase config from secret file
1 parent ae05e53 commit d83b22e

File tree

7 files changed

+38
-26
lines changed

7 files changed

+38
-26
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,7 @@ vertexai-sdk-test-data
103103
mocks-lookup.ts
104104

105105
# temp changeset output
106-
changeset-temp.json
106+
changeset-temp.json
107+
108+
# Vertex AI integration test Firebase project config
109+
packages/vertexai/integration/firebase-config.ts

config/karma.base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const config = {
6060
preprocessors: {
6161
'test/**/*.ts': ['webpack', 'sourcemap'],
6262
'src/**/*.test.ts': ['webpack', 'sourcemap'],
63-
'integration/**/*.test.ts': ['webpack', 'sourcemap']
63+
'integration/**/*.ts': ['webpack', 'sourcemap']
6464
},
6565

6666
mime: { 'text/x-typescript': ['ts', 'tsx'] },

packages/vertexai/integration/chat.test.ts

Whitespace-only changes.

packages/vertexai/integration/constants.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
import { Content, GenerationConfig, HarmBlockMethod, HarmBlockThreshold, HarmCategory, SafetySetting } from "../src";
22

3-
// TODO (dlarocque): Use seperate Firebase config specifically for Vertex AI
4-
// TODO (dlarocque): Load this from environment variables, so we can set the config as a
5-
// secret in CI.
6-
export const config = {
7-
apiKey: "AIzaSyBNHCyZ-bpv-WA-HpXTmigJm2aq3z1kaH8",
8-
authDomain: "jscore-sandbox-141b5.firebaseapp.com",
9-
databaseURL: "https://jscore-sandbox-141b5.firebaseio.com",
10-
projectId: "jscore-sandbox-141b5",
11-
storageBucket: "jscore-sandbox-141b5.appspot.com",
12-
messagingSenderId: "280127633210",
13-
appId: "1:280127633210:web:1eb2f7e8799c4d5a46c203",
14-
measurementId: "G-1VL38N8YFE"
15-
};
16-
173
export const MODEL_NAME = 'gemini-1.5-pro';
184

19-
/// TODO (dlarocque): Fix the naming on these.
205
export const generationConfig: GenerationConfig = {
216
temperature: 0,
227
topP: 0,
23-
topK: 1,
248
responseMimeType: 'text/plain'
259
}
2610

packages/vertexai/integration/count-tokens.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { expect } from "chai";
22
import { Modality, getGenerativeModel, getVertexAI } from "../src";
3-
import { MODEL_NAME, generationConfig, systemInstruction, safetySettings, config } from "./constants";
3+
import { MODEL_NAME, generationConfig, systemInstruction, safetySettings, } from "./constants";
44
import { initializeApp } from "@firebase/app";
5+
import { FIREBASE_CONFIG } from "./firebase-config";
56

67
describe('Count Tokens', () => {
78

8-
before(() => initializeApp(config))
9+
before(() => initializeApp(FIREBASE_CONFIG))
910

1011
it('CountTokens text', async () => {
1112
const vertexAI = getVertexAI();
@@ -28,4 +29,10 @@ describe('Count Tokens', () => {
2829
expect(response.promptTokensDetails![0].modality).to.equal(Modality.TEXT);
2930
expect(response.promptTokensDetails![0].tokenCount).to.equal(6);
3031
});
32+
// TODO (dlarocque): Test countTokens() with the following:
33+
// - inline data
34+
// - public storage reference
35+
// - private storage reference (testing auth integration)
36+
// - count tokens
37+
// - JSON schema
3138
});

packages/vertexai/integration/generate-content.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { expect } from "chai";
2-
import { getGenerativeModel, getVertexAI } from "../src";
3-
import { MODEL_NAME, generationConfig, systemInstruction, safetySettings, config } from "./constants";
2+
import { Modality, getGenerativeModel, getVertexAI } from "../src";
3+
import { MODEL_NAME, generationConfig, systemInstruction, safetySettings } from "./constants";
44
import { initializeApp } from "@firebase/app";
5+
import { FIREBASE_CONFIG } from "./firebase-config";
56

67
// Token counts are only expected to differ by at most this number of tokens.
78
// Set to 1 for whitespace that is not always present.
89
const TOKEN_COUNT_DELTA = 1;
910

1011
describe('Generate Content', () => {
1112

12-
before(() => initializeApp(config))
13+
before(() => initializeApp(FIREBASE_CONFIG))
1314

1415
it('generateContent', async () => {
1516
const vertexAI = getVertexAI();
@@ -29,9 +30,18 @@ describe('Generate Content', () => {
2930
const trimmedText = response.text().trim();
3031
expect(trimmedText).to.equal('Mountain View');
3132

32-
console.log(JSON.stringify(response));
33-
3433
expect(response.usageMetadata).to.not.be.null;
3534
expect(response.usageMetadata!.promptTokenCount).to.be.closeTo(21, TOKEN_COUNT_DELTA);
35+
expect(response.usageMetadata!.candidatesTokenCount).to.be.closeTo(4, TOKEN_COUNT_DELTA);
36+
expect(response.usageMetadata!.totalTokenCount).to.be.closeTo(25, TOKEN_COUNT_DELTA*2);
37+
expect(response.usageMetadata!.promptTokensDetails).to.not.be.null;
38+
expect(response.usageMetadata!.promptTokensDetails!.length).to.equal(1);
39+
expect(response.usageMetadata!.promptTokensDetails![0].modality).to.equal(Modality.TEXT);
40+
expect(response.usageMetadata!.promptTokensDetails![0].tokenCount).to.equal(21);
41+
expect(response.usageMetadata!.candidatesTokensDetails).to.not.be.null;
42+
expect(response.usageMetadata!.candidatesTokensDetails!.length).to.equal(1);
43+
expect(response.usageMetadata!.candidatesTokensDetails![0].modality).to.equal(Modality.TEXT);
44+
expect(response.usageMetadata!.candidatesTokensDetails![0].tokenCount).to.equal(4);
3645
});
46+
// TODO (dlarocque): Test generateContentStream
3747
});

packages/vertexai/karma.conf.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818
const karmaBase = require('../../config/karma.base');
1919
const { argv } = require('yargs');
2020

21+
// Validate that required environment variables are defined
22+
if (!process.env.VERTEXAI_INTEGRATION_FIREBASE_CONFIG_JSON) {
23+
throw new Error('VERTEXAI_INTEGRATION_FIREBASE_CONFIG_JSON is not defined in env. Set this env variable to be the JSON of a Firebase project config to run the integration tests with.')
24+
}
25+
2126
module.exports = function (config) {
2227
const karmaConfig = {
2328
...karmaBase,
2429

2530
// files to load into karma
2631
files: (() => {
2732
if (argv.integration) {
28-
return ['integration/**/*.test.ts'];
33+
return ['integration/**'];
2934
} else {
3035
return ['src/**/*.test.ts'];
3136
}
@@ -34,7 +39,10 @@ module.exports = function (config) {
3439
// frameworks to use
3540
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
3641
frameworks: ['mocha']
42+
3743
};
3844

45+
config.client.args.push(process.env.VERTEXAI_INTEGRATION_FIREBASE_CONFIG_JSON);
46+
3947
config.set(karmaConfig);
4048
};

0 commit comments

Comments
 (0)