Skip to content

[DO NOT MERGE] feat(vertexai): Add support for setting the API version - wait for the release date #17000

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

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ class _ChatWidgetState extends State<ChatWidget> {
FirebaseVertexAI.instanceFor(auth: FirebaseAuth.instance);
_model = vertex_instance.generativeModel(
model: 'gemini-1.5-flash',
requestOptions: RequestOptions(apiVersion: ApiVersion.v1beta),
);
_functionCallModel = vertex_instance.generativeModel(
model: 'gemini-1.5-flash',
tools: [
Tool.functionDeclarations([fetchWeatherTool]),
],
requestOptions: RequestOptions(apiVersion: ApiVersion.v1beta),
);
_chat = _model.startChat();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ export 'src/function_calling.dart'
Tool,
ToolConfig;
export 'src/model.dart' show GenerativeModel;
export 'src/request_options.dart' show ApiVersion, RequestOptions;
export 'src/schema.dart' show Schema, SchemaType;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'api.dart';
import 'content.dart';
import 'function_calling.dart';
import 'model.dart';
import 'request_options.dart';

const _defaultLocation = 'us-central1';

Expand Down Expand Up @@ -96,6 +97,7 @@ class FirebaseVertexAI extends FirebasePluginPlatform {
List<Tool>? tools,
ToolConfig? toolConfig,
Content? systemInstruction,
RequestOptions? requestOptions,
}) {
return createGenerativeModel(
model: model,
Expand All @@ -108,6 +110,7 @@ class FirebaseVertexAI extends FirebasePluginPlatform {
tools: tools,
toolConfig: toolConfig,
systemInstruction: systemInstruction,
requestOptions: requestOptions,
);
}
}
21 changes: 15 additions & 6 deletions packages/firebase_vertexai/firebase_vertexai/lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import 'api.dart';
import 'client.dart';
import 'content.dart';
import 'function_calling.dart';
import 'request_options.dart';
import 'vertex_version.dart';

const _baseUrl = 'firebasevertexai.googleapis.com';
const _apiVersion = 'v1beta';
const _defaultApiVersion = ApiVersion.v1beta;

/// [Task] enum class for [GenerativeModel] to make request.
enum Task {
Expand Down Expand Up @@ -77,9 +78,10 @@ final class GenerativeModel {
List<Tool>? tools,
ToolConfig? toolConfig,
Content? systemInstruction,
RequestOptions? requestOptions,
http.Client? httpClient,
}) : _model = _normalizeModelName(model),
_baseUri = _vertexUri(app, location),
_baseUri = _vertexUri(app, location, requestOptions),
_safetySettings = safetySettings ?? [],
_generationConfig = generationConfig,
_tools = tools,
Expand All @@ -101,9 +103,10 @@ final class GenerativeModel {
List<Tool>? tools,
ToolConfig? toolConfig,
Content? systemInstruction,
RequestOptions? requestOptions,
ApiClient? apiClient,
}) : _model = _normalizeModelName(model),
_baseUri = _vertexUri(app, location),
_baseUri = _vertexUri(app, location, requestOptions),
_safetySettings = safetySettings ?? [],
_generationConfig = generationConfig,
_tools = tools,
Expand Down Expand Up @@ -135,11 +138,13 @@ final class GenerativeModel {
return (prefix: parts.first, name: parts.skip(1).join('/'));
}

static Uri _vertexUri(FirebaseApp app, String location) {
var projectId = app.options.projectId;
static Uri _vertexUri(
FirebaseApp app, String location, RequestOptions? requestOptions) {
final projectId = app.options.projectId;
final apiVersion = requestOptions?.apiVersion ?? _defaultApiVersion;
return Uri.https(
_baseUrl,
'/$_apiVersion/projects/$projectId/locations/$location/publishers/google',
'/${apiVersion.versionIdentifier}/projects/$projectId/locations/$location/publishers/google',
);
}

Expand Down Expand Up @@ -295,6 +300,7 @@ GenerativeModel createGenerativeModel({
List<Tool>? tools,
ToolConfig? toolConfig,
Content? systemInstruction,
RequestOptions? requestOptions,
}) =>
GenerativeModel._(
model: model,
Expand All @@ -307,6 +313,7 @@ GenerativeModel createGenerativeModel({
tools: tools,
toolConfig: toolConfig,
systemInstruction: systemInstruction,
requestOptions: requestOptions,
);

/// Creates a model with an overridden [ApiClient] for testing.
Expand All @@ -324,6 +331,7 @@ GenerativeModel createModelWithClient({
List<SafetySetting>? safetySettings,
List<Tool>? tools,
ToolConfig? toolConfig,
RequestOptions? requestOptions,
}) =>
GenerativeModel._constructTestModel(
model: model,
Expand All @@ -336,4 +344,5 @@ GenerativeModel createModelWithClient({
systemInstruction: systemInstruction,
tools: tools,
toolConfig: toolConfig,
requestOptions: requestOptions,
apiClient: client);
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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.

/// Configuration parameters for sending requests to the backend.
final class RequestOptions {
/// Constructor
RequestOptions({this.apiVersion});

/// The API version to use in requests to the backend.
final ApiVersion? apiVersion;
}

/// API versions for the Vertex AI in Firebase endpoint.
enum ApiVersion {
/// The stable channel for version 1 of the API.
v1('v1'),

/// The beta channel for version 1 of the API.
v1beta('v1beta');

const ApiVersion(this.versionIdentifier);

/// The identifier for the API version.
final String versionIdentifier;

@override
String toString() => name;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be versionIdentifier for better clarity?

}
Loading