Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable first npm publish #8120

Merged
merged 4 commits into from
Apr 4, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/canary-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}}
NPM_TOKEN_TESTING: ${{secrets.NPM_TOKEN_TESTING}}
NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}}
NPM_TOKEN_VERTEX: ${{secrets.NPM_TOKEN_VERTEX}}
NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}}
NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}}
NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/prerelease-manual-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}}
NPM_TOKEN_TESTING: ${{secrets.NPM_TOKEN_TESTING}}
NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}}
NPM_TOKEN_VERTEX: ${{secrets.NPM_TOKEN_VERTEX}}
NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}}
NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}}
NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}}
NPM_TOKEN_TESTING: ${{secrets.NPM_TOKEN_TESTING}}
NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}}
NPM_TOKEN_VERTEX: ${{secrets.NPM_TOKEN_VERTEX}}
NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}}
NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}}
NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ jobs:
NPM_TOKEN_STORAGE_TYPES: ${{secrets.NPM_TOKEN_STORAGE_TYPES}}
NPM_TOKEN_TESTING: ${{secrets.NPM_TOKEN_TESTING}}
NPM_TOKEN_UTIL: ${{secrets.NPM_TOKEN_UTIL}}
NPM_TOKEN_VERTEX: ${{secrets.NPM_TOKEN_VERTEX}}
NPM_TOKEN_WEBCHANNEL_WRAPPER: ${{secrets.NPM_TOKEN_WEBCHANNEL_WRAPPER}}
NPM_TOKEN_FIREBASE: ${{secrets.NPM_TOKEN_FIREBASE}}
NPM_TOKEN_APP_COMPAT: ${{ secrets.NPM_TOKEN_APP_COMPAT }}
Expand Down
16 changes: 8 additions & 8 deletions packages/vertexai/src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import { ModelParams } from './types';
import { getGenerativeModel } from './api';
import { expect } from 'chai';
import { Vertex } from './public-types';
import { VertexAI } from './public-types';
import { GenerativeModel } from './models/generative-model';
import { VertexError } from './errors';

const fakeVertex: Vertex = {
const fakeVertexAI: VertexAI = {
app: {
name: 'DEFAULT',
automaticDataCollectionEnabled: true,
Expand All @@ -35,30 +35,30 @@ const fakeVertex: Vertex = {

describe('Top level API', () => {
it('getGenerativeModel throws if no model is provided', () => {
expect(() => getGenerativeModel(fakeVertex, {} as ModelParams)).to.throw(
expect(() => getGenerativeModel(fakeVertexAI, {} as ModelParams)).to.throw(
VertexError.NO_MODEL
);
});
it('getGenerativeModel throws if no apiKey is provided', () => {
const fakeVertexNoApiKey = {
...fakeVertex,
...fakeVertexAI,
app: { options: { projectId: 'my-project' } }
} as Vertex;
} as VertexAI;
expect(() =>
getGenerativeModel(fakeVertexNoApiKey, { model: 'my-model' })
).to.throw(VertexError.NO_API_KEY);
});
it('getGenerativeModel throws if no projectId is provided', () => {
const fakeVertexNoProject = {
...fakeVertex,
...fakeVertexAI,
app: { options: { apiKey: 'my-key' } }
} as Vertex;
} as VertexAI;
expect(() =>
getGenerativeModel(fakeVertexNoProject, { model: 'my-model' })
).to.throw(VertexError.NO_PROJECT_ID);
});
it('getGenerativeModel gets a GenerativeModel', () => {
const genModel = getGenerativeModel(fakeVertex, { model: 'my-model' });
const genModel = getGenerativeModel(fakeVertexAI, { model: 'my-model' });
expect(genModel).to.be.an.instanceOf(GenerativeModel);
expect(genModel.model).to.equal('publishers/google/models/my-model');
});
Expand Down
16 changes: 8 additions & 8 deletions packages/vertexai/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { FirebaseApp, getApp, _getProvider } from '@firebase/app';
import { Provider } from '@firebase/component';
import { getModularInstance } from '@firebase/util';
import { DEFAULT_LOCATION, VERTEX_TYPE } from './constants';
import { VertexService } from './service';
import { Vertex, VertexOptions } from './public-types';
import { VertexAIService } from './service';
import { VertexAI, VertexAIOptions } from './public-types';
import { ERROR_FACTORY, VertexError } from './errors';
import { ModelParams, RequestOptions } from './types';
import { GenerativeModel } from './models/generative-model';
Expand All @@ -31,21 +31,21 @@ export { GenerativeModel };

declare module '@firebase/component' {
interface NameServiceMapping {
[VERTEX_TYPE]: VertexService;
[VERTEX_TYPE]: VertexAIService;
}
}

/**
* Returns an {@link Vertex} instance for the given app.
* Returns an {@link VertexAI} instance for the given app.
*
* @public
*
* @param app - The {@link @firebase/app#FirebaseApp} to use.
*/
export function getVertex(
export function getVertexAI(
app: FirebaseApp = getApp(),
options?: VertexOptions
): Vertex {
options?: VertexAIOptions
): VertexAI {
app = getModularInstance(app);
// Dependencies
const vertexProvider: Provider<'vertex'> = _getProvider(app, VERTEX_TYPE);
Expand All @@ -56,7 +56,7 @@ export function getVertex(
}

export function getGenerativeModel(
vertex: Vertex,
vertex: VertexAI,
modelParams: ModelParams,
requestOptions?: RequestOptions
): GenerativeModel {
Expand Down
4 changes: 2 additions & 2 deletions packages/vertexai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import { registerVersion, _registerComponent } from '@firebase/app';
import { VertexService } from './service';
import { VertexAIService } from './service';
import { VERTEX_TYPE } from './constants';
import { Component, ComponentType } from '@firebase/component';
import { name, version } from '../package.json';
Expand All @@ -41,7 +41,7 @@ function registerVertex(): void {
// getImmediate for FirebaseApp will always succeed
const app = container.getProvider('app').getImmediate();
const appCheckProvider = container.getProvider('app-check-internal');
return new VertexService(app, appCheckProvider, { location });
return new VertexAIService(app, appCheckProvider, { location });
},
ComponentType.PUBLIC
).setMultipleInstances(true)
Expand Down
12 changes: 6 additions & 6 deletions packages/vertexai/src/models/generative-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
import { expect } from 'chai';
import { GenerativeModel } from './generative-model';
import { Vertex } from '../public-types';
import { VertexAI } from '../public-types';

const fakeVertex: Vertex = {
const fakeVertexAI: VertexAI = {
app: {
name: 'DEFAULT',
automaticDataCollectionEnabled: true,
Expand All @@ -32,23 +32,23 @@ const fakeVertex: Vertex = {

describe('GenerativeModel', () => {
it('handles plain model name', () => {
const genModel = new GenerativeModel(fakeVertex, { model: 'my-model' });
const genModel = new GenerativeModel(fakeVertexAI, { model: 'my-model' });
expect(genModel.model).to.equal('publishers/google/models/my-model');
});
it('handles models/ prefixed model name', () => {
const genModel = new GenerativeModel(fakeVertex, {
const genModel = new GenerativeModel(fakeVertexAI, {
model: 'models/my-model'
});
expect(genModel.model).to.equal('publishers/google/models/my-model');
});
it('handles full model name', () => {
const genModel = new GenerativeModel(fakeVertex, {
const genModel = new GenerativeModel(fakeVertexAI, {
model: 'publishers/google/models/my-model'
});
expect(genModel.model).to.equal('publishers/google/models/my-model');
});
it('handles prefixed tuned model name', () => {
const genModel = new GenerativeModel(fakeVertex, {
const genModel = new GenerativeModel(fakeVertexAI, {
model: 'tunedModels/my-model'
});
expect(genModel.model).to.equal('tunedModels/my-model');
Expand Down
20 changes: 10 additions & 10 deletions packages/vertexai/src/models/generative-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import {
import { ChatSession } from '../methods/chat-session';
import { countTokens } from '../methods/count-tokens';
import { formatGenerateContentInput } from '../requests/request-helpers';
import { Vertex } from '../public-types';
import { VertexAI } from '../public-types';
import { ERROR_FACTORY, VertexError } from '../errors';
import { ApiSettings } from '../types/internal';
import { VertexService } from '../service';
import { VertexAIService } from '../service';

/**
* Class for generative model APIs.
Expand All @@ -54,23 +54,23 @@ export class GenerativeModel {
tools?: Tool[];

constructor(
vertex: Vertex,
vertexAI: VertexAI,
modelParams: ModelParams,
requestOptions?: RequestOptions
) {
if (!vertex.app?.options?.apiKey) {
if (!vertexAI.app?.options?.apiKey) {
throw ERROR_FACTORY.create(VertexError.NO_API_KEY);
} else if (!vertex.app?.options?.projectId) {
} else if (!vertexAI.app?.options?.projectId) {
throw ERROR_FACTORY.create(VertexError.NO_PROJECT_ID);
} else {
this._apiSettings = {
apiKey: vertex.app.options.apiKey,
project: vertex.app.options.projectId,
location: vertex.location
apiKey: vertexAI.app.options.apiKey,
project: vertexAI.app.options.projectId,
location: vertexAI.location
};
if ((vertex as VertexService).appCheck) {
if ((vertexAI as VertexAIService).appCheck) {
this._apiSettings.getAppCheckToken = () =>
(vertex as VertexService).appCheck!.getToken();
(vertexAI as VertexAIService).appCheck!.getToken();
}
}
if (modelParams.model.includes('/')) {
Expand Down
8 changes: 4 additions & 4 deletions packages/vertexai/src/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ import { FirebaseApp } from '@firebase/app';
export * from './types';

/**
* An instance of Firebase Vertex.
* An instance of Firebase Vertex AI.
* @public
*/
export interface Vertex {
export interface VertexAI {
/**
* The {@link @firebase/app#FirebaseApp} this {@link Vertex} instance is associated with.
* The {@link @firebase/app#FirebaseApp} this {@link VertexAI} instance is associated with.
*/
app: FirebaseApp;
location: string;
}

export interface VertexOptions {
export interface VertexAIOptions {
location?: string;
}
6 changes: 3 additions & 3 deletions packages/vertexai/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
*/

import { FirebaseApp, _FirebaseService } from '@firebase/app';
import { Vertex, VertexOptions } from './public-types';
import { VertexAI, VertexAIOptions } from './public-types';
import {
AppCheckInternalComponentName,
FirebaseAppCheckInternal
} from '@firebase/app-check-interop-types';
import { Provider } from '@firebase/component';
import { DEFAULT_LOCATION } from './constants';

export class VertexService implements Vertex, _FirebaseService {
export class VertexAIService implements VertexAI, _FirebaseService {
appCheck: FirebaseAppCheckInternal | null;
location: string;

constructor(
public app: FirebaseApp,
appCheckProvider?: Provider<AppCheckInternalComponentName>,
public options?: VertexOptions
public options?: VertexAIOptions
) {
const appCheck = appCheckProvider?.getImmediate({ optional: true });
this.appCheck = appCheck || null;
Expand Down
10 changes: 7 additions & 3 deletions scripts/release/utils/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ export async function publishInCI(
continue;
}
} catch (e) {
// 404 from NPM indicates the package doesn't exist there.
console.log(`Skipping pkg: ${pkg} - it has never been published to NPM.`);
continue;
if (version !== '0.0.1') {
// 404 from NPM indicates the package doesn't exist there.
console.log(
`Skipping pkg: ${pkg} - it has never been published to NPM.`
);
continue;
}
}

const tag = `${pkg}@${version}`;
Expand Down
Loading