Skip to content

Commit ed0e0d4

Browse files
committed
[Vertex AI] Add apiVersion parameter to RequestOptions
1 parent 3aefcc3 commit ed0e0d4

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

packages/vertexai/src/requests/request.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import chaiAsPromised from 'chai-as-promised';
2222
import { RequestUrl, Task, getHeaders, makeRequest } from './request';
2323
import { ApiSettings } from '../types/internal';
2424
import { DEFAULT_API_VERSION } from '../constants';
25-
import { VertexAIErrorCode } from '../types';
25+
import { ApiVersion, VertexAIErrorCode } from '../types';
2626
import { VertexAIError } from '../errors';
2727
import { getMockResponse } from '../../test-utils/mock-response';
2828

@@ -74,6 +74,18 @@ describe('request methods', () => {
7474
);
7575
expect(url.toString()).to.include(DEFAULT_API_VERSION);
7676
});
77+
it('custom apiVersion', async () => {
78+
const url = new RequestUrl(
79+
'models/model-name',
80+
Task.GENERATE_CONTENT,
81+
fakeApiSettings,
82+
false,
83+
{ apiVersion: ApiVersion.V1 }
84+
);
85+
expect(url.toString()).to.include(ApiVersion.V1);
86+
// TODO: Update test to set ApiVersion.V1BETA when ApiVersion.V1 becomes the default.
87+
expect(ApiVersion.V1).to.not.equal(DEFAULT_API_VERSION);
88+
});
7789
it('custom baseUrl', async () => {
7890
const url = new RequestUrl(
7991
'models/model-name',

packages/vertexai/src/requests/request.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export class RequestUrl {
4242
public requestOptions?: RequestOptions
4343
) {}
4444
toString(): string {
45-
// TODO: allow user-set option if that feature becomes available
46-
const apiVersion = DEFAULT_API_VERSION;
45+
const apiVersion = this.requestOptions?.apiVersion || DEFAULT_API_VERSION;
4746
const baseUrl = this.requestOptions?.baseUrl || DEFAULT_BASE_URL;
4847
let url = `${baseUrl}/${apiVersion}`;
4948
url += `/projects/${this.apiSettings.project}`;

packages/vertexai/src/types/enums.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ export type Role = (typeof POSSIBLE_ROLES)[number];
2727
*/
2828
export const POSSIBLE_ROLES = ['user', 'model', 'function', 'system'] as const;
2929

30+
/**
31+
* Supported API versions for the Vertex AI in Firebase endpoint.
32+
* @public
33+
*/
34+
export enum ApiVersion {
35+
/** The stable channel for version 1 of the API. */
36+
V1 = 'v1',
37+
/** The beta channel for version 1 of the API. */
38+
V1BETA = 'v1beta'
39+
}
40+
3041
/**
3142
* Harm categories that would cause prompts or candidates to be blocked.
3243
* @public

packages/vertexai/src/types/requests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import { TypedSchema } from '../requests/schema-builder';
1919
import { Content, Part } from './content';
2020
import {
21+
ApiVersion,
2122
FunctionCallingMode,
2223
HarmBlockMethod,
2324
HarmBlockThreshold,
@@ -129,6 +130,11 @@ export interface RequestOptions {
129130
* Base url for endpoint. Defaults to https://firebasevertexai.googleapis.com
130131
*/
131132
baseUrl?: string;
133+
/**
134+
* API version for endpoint. Defaults to <code>"v1beta"</code>
135+
* (<code>{@link ApiVersion.V1BETA}</code>).
136+
*/
137+
apiVersion?: ApiVersion;
132138
}
133139

134140
/**

0 commit comments

Comments
 (0)