Skip to content
Open
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
5 changes: 4 additions & 1 deletion js/plugins/vertexai/src/evaluation/evaluator_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export class EvaluatorFactory {

metadata.input = request;
const client = await this.auth.getClient();
const url = `https://${this.location}-aiplatform.googleapis.com/v1beta1/${locationName}:evaluateInstances`;
const baseUrl = this.location === 'global'
? 'https://aiplatform.googleapis.com'
: `https://${this.location}-aiplatform.googleapis.com`;
const url = `${baseUrl}/v1beta1/${locationName}:evaluateInstances`;
const response = await client.request({
url,
method: 'POST',
Expand Down
5 changes: 4 additions & 1 deletion js/plugins/vertexai/src/list-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ export async function listModels(
): Promise<Model[]> {
const fetch = (await import('node-fetch')).default;
const accessToken = await authClient.getAccessToken();
const baseUrl = location === 'global'
? 'https://aiplatform.googleapis.com'
: `https://${location}-aiplatform.googleapis.com`;
const response = await fetch(
`https://${location}-aiplatform.googleapis.com/v1beta1/publishers/google/models`,
`${baseUrl}/v1beta1/publishers/google/models`,
{
method: 'GET',
headers: {
Expand Down
12 changes: 9 additions & 3 deletions js/plugins/vertexai/src/modelgarden/legacy/model_garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ export function modelGardenOpenaiCompatibleModel(
request: GenerateRequest<typeof ModelGardenModelConfigSchema>
): Promise<OpenAI> => {
const requestLocation = request.config?.location || location;
const baseUrl = requestLocation === 'global'
? baseUrlTemplate!
.replace(/{location}-aiplatform\.googleapis\.com/g, 'aiplatform.googleapis.com')
.replace(/{location}/g, requestLocation)
.replace(/{projectId}/g, projectId)
: baseUrlTemplate!
.replace(/{location}/g, requestLocation)
.replace(/{projectId}/g, projectId);
return new OpenAI({
baseURL: baseUrlTemplate!
.replace(/{location}/g, requestLocation)
.replace(/{projectId}/g, projectId),
baseURL: baseUrl,
apiKey: (await googleAuth.getAccessToken())!,
defaultHeaders: {
'X-Goog-Api-Client': getGenkitClientHeader(),
Expand Down
11 changes: 8 additions & 3 deletions js/plugins/vertexai/src/modelgarden/v2/llama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,14 @@ async function resolveOptions(
clientOptions.baseUrlTemplate ??
'https://{location}-aiplatform.googleapis.com/v1/projects/{projectId}/locations/{location}/endpoints/openapi';
const location = requestConfig?.location || clientOptions.location;
const baseURL = baseUrlTemplate
.replace(/{location}/g, location)
.replace(/{projectId}/g, clientOptions.projectId);
const baseURL = location === 'global'
? baseUrlTemplate
.replace(/{location}-aiplatform\.googleapis\.com/g, 'aiplatform.googleapis.com')
.replace(/{location}/g, location)
.replace(/{projectId}/g, clientOptions.projectId)
: baseUrlTemplate
.replace(/{location}/g, location)
.replace(/{projectId}/g, clientOptions.projectId);
const apiKey = await clientOptions.authClient.getAccessToken();
if (!apiKey) {
throw new GenkitError({
Expand Down
5 changes: 4 additions & 1 deletion js/plugins/vertexai/src/predict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ function endpoint(options: {
location: string;
model: string;
}) {
const baseUrl = options.location === 'global'
? 'https://aiplatform.googleapis.com'
: `https://${options.location}-aiplatform.googleapis.com`;
return (
`https://${options.location}-aiplatform.googleapis.com/v1/` +
`${baseUrl}/v1/` +
`projects/${options.projectId}/locations/${options.location}/` +
`publishers/google/models/${options.model}:predict`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export async function upsertDatapoints(
): Promise<void> {
const { datapoints, authClient, projectId, location, indexId } = params;
const accessToken = await authClient.getAccessToken();
const url = `https://${location}-aiplatform.googleapis.com/v1/projects/${projectId}/locations/${location}/indexes/${indexId}:upsertDatapoints`;
const baseUrl = location === 'global'
? 'https://aiplatform.googleapis.com'
: `https://${location}-aiplatform.googleapis.com`;
const url = `${baseUrl}/v1/projects/${projectId}/locations/${location}/indexes/${indexId}:upsertDatapoints`;

const requestBody = {
datapoints: datapoints.map((dp) => {
Expand Down