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
6 changes: 5 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,11 @@ 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
8 changes: 7 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,14 @@ export async function listModels(
): Promise<Model[]> {
const fetch = (await import('node-fetch')).default;
const accessToken = await authClient.getAccessToken();

// Global endpoint uses base URL without location prefix
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
9 changes: 6 additions & 3 deletions js/plugins/vertexai/src/modelgarden/v2/llama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ async function resolveOptions(
clientOptions: ClientOptions,
requestConfig?: LlamaConfig
) {
const baseUrlTemplate =
clientOptions.baseUrlTemplate ??
'https://{location}-aiplatform.googleapis.com/v1/projects/{projectId}/locations/{location}/endpoints/openapi';
const location = requestConfig?.location || clientOptions.location;
const defaultTemplate = location === 'global'
? 'https://aiplatform.googleapis.com/v1/projects/{projectId}/locations/{location}/endpoints/openapi'
: 'https://{location}-aiplatform.googleapis.com/v1/projects/{projectId}/locations/{location}/endpoints/openapi';

const baseUrlTemplate = clientOptions.baseUrlTemplate ?? defaultTemplate;

const baseURL = baseUrlTemplate
.replace(/{location}/g, location)
.replace(/{projectId}/g, clientOptions.projectId);
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,11 @@ 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