Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dlarocque committed Jan 2, 2025
1 parent 8471bbc commit 5c518b1
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 30 deletions.
19 changes: 18 additions & 1 deletion packages/vertexai/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './vertexai-model';
export * from './generative-model';
export * from './imagen-model';
export * from './imagen-model';
10 changes: 5 additions & 5 deletions packages/vertexai/src/models/vertexai-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ use(sinonChai);
*/
class TestModel extends VertexAIModel {
/* eslint-disable @typescript-eslint/no-useless-constructor */
constructor(
vertexAI: VertexAI,
modelName: string
) {
constructor(vertexAI: VertexAI, modelName: string) {
super(vertexAI, modelName);
}
}
Expand All @@ -57,7 +54,10 @@ describe('VertexAIModel', () => {
expect(testModel.model).to.equal('publishers/google/models/my-model');
});
it('handles full model name', () => {
const testModel = new TestModel(fakeVertexAI, 'publishers/google/models/my-model');
const testModel = new TestModel(
fakeVertexAI,
'publishers/google/models/my-model'
);
expect(testModel.model).to.equal('publishers/google/models/my-model');
});
it('handles prefixed tuned model name', () => {
Expand Down
44 changes: 29 additions & 15 deletions packages/vertexai/src/models/vertexai-model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import { VertexAIError } from "../errors";
import { VertexAI, VertexAIErrorCode } from "../public-types";
import { VertexAIService } from "../service";
import { ApiSettings } from "../types/internal";
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { VertexAIError } from '../errors';
import { VertexAI, VertexAIErrorCode } from '../public-types';
import { VertexAIService } from '../service';
import { ApiSettings } from '../types/internal';

/**
* Base class for Vertex AI in Firebase model APIs.
Expand All @@ -10,7 +27,7 @@ import { ApiSettings } from "../types/internal";
*/
export class VertexAIModel {
/**
* The fully qualified model resource name to use for generating images
* The fully qualified model resource name to use for generating images
* (e.g. `publishers/google/models/imagen-3.0-generate-001`).
*/
readonly model: string;
Expand All @@ -22,25 +39,22 @@ export class VertexAIModel {

/**
* Constructs a new instance of the {@link VertexAIModel} class.
*
*
* This constructor should only be called from subclasses that provide
* a model API.
*
* @param vertexAI - An instance of the Vertex AI in Firebase SDK.
* @param modelName - The name of the model being used. It can be in one of the following formats:
* - `my-model` (short name, will resolve to `publishers/google/models/my-model`)
* - `models/my-model` (will resolve to `publishers/google/models/my-model`)
* - `publishers/my-publisher/models/my-model` (fully qualified model name)
*
* - `publishers/my-publisher/models/my-model` (fully qualified model name)
*
* @throws If the `apiKey` or `projectId` fields are missing in your
* Firebase config.
*
*
* @internal
*/
protected constructor(
vertexAI: VertexAI,
modelName: string
) {
protected constructor(vertexAI: VertexAI, modelName: string) {
this.model = VertexAIModel.normalizeModelName(modelName);

if (!vertexAI.app?.options?.apiKey) {
Expand Down Expand Up @@ -73,7 +87,7 @@ export class VertexAIModel {

/**
* Normalizes the given model name to a fully qualified model resource name.
*
*
* @param modelName - The model name to normalize.
* @returns The fully qualified model resource name.
*/
Expand All @@ -94,4 +108,4 @@ export class VertexAIModel {

return model;
}
}
}
29 changes: 23 additions & 6 deletions packages/vertexai/src/requests/imagen-image-format.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
/**
* @license
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Defines the image format for images output by Imagen.
*
* Use this class to specify the desired format (JPEG or PNG) and compression quality
* for images generated by Imagen. This is typically included as part of
* Use this class to specify the desired format (JPEG or PNG) and compression quality
* for images generated by Imagen. This is typically included as part of
* {@link ImagenModelParams}.
*
* @example
Expand All @@ -26,7 +43,7 @@ export class ImagenImageFormat {
compressionQuality?: number;

private constructor() {
this.mimeType = "image/png";
this.mimeType = 'image/png';
}

/**
Expand All @@ -38,7 +55,7 @@ export class ImagenImageFormat {
* @public
*/
static jpeg(compressionQuality: number): ImagenImageFormat {
return { mimeType: "image/jpeg", compressionQuality };
return { mimeType: 'image/jpeg', compressionQuality };
}

/**
Expand All @@ -49,6 +66,6 @@ export class ImagenImageFormat {
* @public
*/
static png(): ImagenImageFormat {
return { mimeType: "image/png" };
return { mimeType: 'image/png' };
}
}
}
2 changes: 1 addition & 1 deletion packages/vertexai/src/requests/request-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
GenerateContentRequest,
Part,
VertexAIErrorCode,
ImagenAspectRatio,
ImagenAspectRatio
} from '../types';
import { VertexAIError } from '../errors';
import { ImagenImageFormat } from './imagen-image-format';
Expand Down
4 changes: 2 additions & 2 deletions packages/vertexai/src/types/imagen/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { ImagenGenerationConfig, ImagenModelConfig } from "./requests";
import { ImagenGenerationConfig, ImagenModelConfig } from './requests';

/**
* A response from the REST API is expected to look like this in the success case:
Expand Down Expand Up @@ -130,4 +130,4 @@ export interface ImagenRequestConfig
* (for GCS requests only).
*/
gcsURI?: string;
}
}

0 comments on commit 5c518b1

Please sign in to comment.