From 87f6ba469683a313a928677aa568a0a8bd585e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B6rgens?= Date: Mon, 8 Dec 2025 15:34:19 +0100 Subject: [PATCH] fix(3651): resolve correct path for global endpoint --- .../vertexai/src/evaluation/evaluator_factory.ts | 5 ++++- js/plugins/vertexai/src/list-models.ts | 5 ++++- .../vertexai/src/modelgarden/legacy/model_garden.ts | 12 +++++++++--- js/plugins/vertexai/src/modelgarden/v2/llama.ts | 11 ++++++++--- js/plugins/vertexai/src/predict.ts | 5 ++++- .../vectorsearch/vector_search/upsert_datapoints.ts | 5 ++++- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/js/plugins/vertexai/src/evaluation/evaluator_factory.ts b/js/plugins/vertexai/src/evaluation/evaluator_factory.ts index de0c0c939e..89494a22c7 100644 --- a/js/plugins/vertexai/src/evaluation/evaluator_factory.ts +++ b/js/plugins/vertexai/src/evaluation/evaluator_factory.ts @@ -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', diff --git a/js/plugins/vertexai/src/list-models.ts b/js/plugins/vertexai/src/list-models.ts index 0a51c7ff10..aeef06d876 100644 --- a/js/plugins/vertexai/src/list-models.ts +++ b/js/plugins/vertexai/src/list-models.ts @@ -38,8 +38,11 @@ export async function listModels( ): Promise { 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: { diff --git a/js/plugins/vertexai/src/modelgarden/legacy/model_garden.ts b/js/plugins/vertexai/src/modelgarden/legacy/model_garden.ts index 81506b85bd..97425bd19e 100644 --- a/js/plugins/vertexai/src/modelgarden/legacy/model_garden.ts +++ b/js/plugins/vertexai/src/modelgarden/legacy/model_garden.ts @@ -115,10 +115,16 @@ export function modelGardenOpenaiCompatibleModel( request: GenerateRequest ): Promise => { 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(), diff --git a/js/plugins/vertexai/src/modelgarden/v2/llama.ts b/js/plugins/vertexai/src/modelgarden/v2/llama.ts index 3893266f45..8e03af1e6e 100644 --- a/js/plugins/vertexai/src/modelgarden/v2/llama.ts +++ b/js/plugins/vertexai/src/modelgarden/v2/llama.ts @@ -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({ diff --git a/js/plugins/vertexai/src/predict.ts b/js/plugins/vertexai/src/predict.ts index e7e932c1c0..77d26b6e5b 100644 --- a/js/plugins/vertexai/src/predict.ts +++ b/js/plugins/vertexai/src/predict.ts @@ -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` ); diff --git a/js/plugins/vertexai/src/vectorsearch/vector_search/upsert_datapoints.ts b/js/plugins/vertexai/src/vectorsearch/vector_search/upsert_datapoints.ts index 6e6245df59..cb37abbac5 100644 --- a/js/plugins/vertexai/src/vectorsearch/vector_search/upsert_datapoints.ts +++ b/js/plugins/vertexai/src/vectorsearch/vector_search/upsert_datapoints.ts @@ -45,7 +45,10 @@ export async function upsertDatapoints( ): Promise { 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) => {