Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 18 additions & 2 deletions packages/genkit_google_genai/lib/src/api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,24 @@ class GenerativeLanguageBaseClient {

Future<Map<String, dynamic>> listPublisherModels({
required String projectId,
String publisher = 'google',
}) async {
// Vertex AI endpoint for publisher models uses v1beta1 and does not have the 'projects/...' in the path
// when using this specific endpoint, but it requires the google user project header (or just works with ADC).
// The base URL for this is https://{location}-aiplatform.googleapis.com
// And path is /v1beta1/publishers/google/models
final url = 'v1beta1/publishers/google/models';
// And path is /v1beta1/publishers/{publisher}/models
final safePublisher = Uri.encodeComponent(publisher);
final url = 'v1beta1/publishers/$safePublisher/models';
return await _call('GET', url, null, {'x-goog-user-project': projectId});
}

Future<Map<String, dynamic>> chatCompletions(
Map<String, dynamic> request,
) async {
final url = '${apiUrlPrefix}chat/completions';
return await _call('POST', url, request);
}

Future<Map<String, dynamic>> predict(
Map<String, dynamic> request, {
required String model,
Expand Down Expand Up @@ -197,4 +206,11 @@ class GenerativeLanguageBaseClient {
status: StatusCodes.INTERNAL,
);
}

Stream<Map<String, dynamic>> streamChatCompletions(
Map<String, dynamic> request,
) async* {
final url = '${apiUrlPrefix}chat/completions';
yield* _callStream('POST', url, request);
}
}
10 changes: 10 additions & 0 deletions packages/genkit_vertexai/lib/genkit_vertexai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:genkit/plugin.dart';
import 'package:genkit_google_genai/genkit_google_genai.dart';
import 'package:http/http.dart' as http;

import 'src/meta_model.dart';
import 'src/vertex_api_client.dart';

export 'package:genkit_google_genai/genkit_google_genai.dart'
Expand All @@ -31,6 +32,7 @@ export 'package:genkit_google_genai/genkit_google_genai.dart'
TextEmbedderOptions,
ThinkingConfig,
VoiceConfig;
export 'src/meta_model.dart' show VertexAiMetaOptions;

const VertexAiPluginHandle vertexAI = VertexAiPluginHandle();

Expand All @@ -53,6 +55,14 @@ class VertexAiPluginHandle {
return modelRef('vertexai/$name', customOptions: GeminiOptions.$schema);
}

ModelRef<VertexAiMetaOptions> meta(String name) {
final modelName = name.startsWith('meta/') ? name.substring(5) : name;
return modelRef(
'vertexai/$modelName',
customOptions: VertexAiMetaOptions.$schema,
);
}

EmbedderRef<TextEmbedderOptions> textEmbedding(String name) {
return embedderRef(
'vertexai/$name',
Expand Down
Loading
Loading