From 5e5b2a18e2c7efd0d10d025c2acc16f883dc057c Mon Sep 17 00:00:00 2001 From: Karl Stoney Date: Fri, 18 Jul 2025 11:28:23 +0100 Subject: [PATCH] Added region support to chatGoogleVertexAi (#4839) * Added region support to chatGoogleVertexAi * Added region to the vertex ai embeddings loader too * Updated the available vertex text embedding models to be valid * Update ChatGoogleVertexAI.ts * Update GoogleVertexAIEmbedding.ts --------- Co-authored-by: Henry Heng --- packages/components/models.json | 108 +++++++++++++++--- .../ChatGoogleVertexAI/ChatGoogleVertexAI.ts | 19 ++- .../GoogleVertexAIEmbedding.ts | 21 +++- 3 files changed, 127 insertions(+), 21 deletions(-) diff --git a/packages/components/models.json b/packages/components/models.json index fb78df106..a85be0670 100644 --- a/packages/components/models.json +++ b/packages/components/models.json @@ -697,6 +697,50 @@ "input_cost": 2.5e-7, "output_cost": 1.25e-6 } + ], + "regions": [ + { "label": "us-east1", "name": "us-east1" }, + { "label": "us-east4", "name": "us-east4" }, + { "label": "us-central1", "name": "us-central1" }, + { "label": "us-west1", "name": "us-west1" }, + { "label": "europe-west4", "name": "europe-west4" }, + { "label": "europe-west1", "name": "europe-west1" }, + { "label": "europe-west3", "name": "europe-west3" }, + { "label": "europe-west2", "name": "europe-west2" }, + { "label": "asia-east1", "name": "asia-east1" }, + { "label": "asia-southeast1", "name": "asia-southeast1" }, + { "label": "asia-northeast1", "name": "asia-northeast1" }, + { "label": "asia-south1", "name": "asia-south1" }, + { "label": "australia-southeast1", "name": "australia-southeast1" }, + { "label": "southamerica-east1", "name": "southamerica-east1" }, + { "label": "africa-south1", "name": "africa-south1" }, + { "label": "asia-east2", "name": "asia-east2" }, + { "label": "asia-northeast2", "name": "asia-northeast2" }, + { "label": "asia-northeast3", "name": "asia-northeast3" }, + { "label": "asia-south2", "name": "asia-south2" }, + { "label": "asia-southeast2", "name": "asia-southeast2" }, + { "label": "australia-southeast2", "name": "australia-southeast2" }, + { "label": "europe-central2", "name": "europe-central2" }, + { "label": "europe-north1", "name": "europe-north1" }, + { "label": "europe-north2", "name": "europe-north2" }, + { "label": "europe-southwest1", "name": "europe-southwest1" }, + { "label": "europe-west10", "name": "europe-west10" }, + { "label": "europe-west12", "name": "europe-west12" }, + { "label": "europe-west6", "name": "europe-west6" }, + { "label": "europe-west8", "name": "europe-west8" }, + { "label": "europe-west9", "name": "europe-west9" }, + { "label": "me-central1", "name": "me-central1" }, + { "label": "me-central2", "name": "me-central2" }, + { "label": "me-west1", "name": "me-west1" }, + { "label": "northamerica-northeast1", "name": "northamerica-northeast1" }, + { "label": "northamerica-northeast2", "name": "northamerica-northeast2" }, + { "label": "northamerica-south1", "name": "northamerica-south1" }, + { "label": "southamerica-west1", "name": "southamerica-west1" }, + { "label": "us-east5", "name": "us-east5" }, + { "label": "us-south1", "name": "us-south1" }, + { "label": "us-west2", "name": "us-west2" }, + { "label": "us-west3", "name": "us-west3" }, + { "label": "us-west4", "name": "us-west4" } ] }, { @@ -1747,29 +1791,65 @@ "name": "googlevertexaiEmbeddings", "models": [ { - "label": "multimodalembedding", - "name": "multimodalembedding" + "label": "gemini-embedding-001", + "name": "gemini-embedding-001" }, { "label": "text-embedding-004", "name": "text-embedding-004" }, + { + "label": "text-embedding-005", + "name": "text-embedding-005" + }, { "label": "text-multilingual-embedding-002", "name": "text-multilingual-embedding-002" - }, - { - "label": "textembedding-gecko@001", - "name": "textembedding-gecko@001" - }, - { - "label": "textembedding-gecko@latest", - "name": "textembedding-gecko@latest" - }, - { - "label": "textembedding-gecko-multilingual@latest", - "name": "textembedding-gecko-multilingual@latest" } + ], + "regions": [ + { "label": "us-east1", "name": "us-east1" }, + { "label": "us-east4", "name": "us-east4" }, + { "label": "us-central1", "name": "us-central1" }, + { "label": "us-west1", "name": "us-west1" }, + { "label": "europe-west4", "name": "europe-west4" }, + { "label": "europe-west1", "name": "europe-west1" }, + { "label": "europe-west3", "name": "europe-west3" }, + { "label": "europe-west2", "name": "europe-west2" }, + { "label": "asia-east1", "name": "asia-east1" }, + { "label": "asia-southeast1", "name": "asia-southeast1" }, + { "label": "asia-northeast1", "name": "asia-northeast1" }, + { "label": "asia-south1", "name": "asia-south1" }, + { "label": "australia-southeast1", "name": "australia-southeast1" }, + { "label": "southamerica-east1", "name": "southamerica-east1" }, + { "label": "africa-south1", "name": "africa-south1" }, + { "label": "asia-east2", "name": "asia-east2" }, + { "label": "asia-northeast2", "name": "asia-northeast2" }, + { "label": "asia-northeast3", "name": "asia-northeast3" }, + { "label": "asia-south2", "name": "asia-south2" }, + { "label": "asia-southeast2", "name": "asia-southeast2" }, + { "label": "australia-southeast2", "name": "australia-southeast2" }, + { "label": "europe-central2", "name": "europe-central2" }, + { "label": "europe-north1", "name": "europe-north1" }, + { "label": "europe-north2", "name": "europe-north2" }, + { "label": "europe-southwest1", "name": "europe-southwest1" }, + { "label": "europe-west10", "name": "europe-west10" }, + { "label": "europe-west12", "name": "europe-west12" }, + { "label": "europe-west6", "name": "europe-west6" }, + { "label": "europe-west8", "name": "europe-west8" }, + { "label": "europe-west9", "name": "europe-west9" }, + { "label": "me-central1", "name": "me-central1" }, + { "label": "me-central2", "name": "me-central2" }, + { "label": "me-west1", "name": "me-west1" }, + { "label": "northamerica-northeast1", "name": "northamerica-northeast1" }, + { "label": "northamerica-northeast2", "name": "northamerica-northeast2" }, + { "label": "northamerica-south1", "name": "northamerica-south1" }, + { "label": "southamerica-west1", "name": "southamerica-west1" }, + { "label": "us-east5", "name": "us-east5" }, + { "label": "us-south1", "name": "us-south1" }, + { "label": "us-west2", "name": "us-west2" }, + { "label": "us-west3", "name": "us-west3" }, + { "label": "us-west4", "name": "us-west4" } ] }, { diff --git a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts index 2116a25eb..e27c36093 100644 --- a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts @@ -1,5 +1,5 @@ import { BaseCache } from '@langchain/core/caches' -import { ChatVertexAI as LcChatVertexAI, ChatVertexAIInput } from '@langchain/google-vertexai' +import { ChatVertexAIInput, ChatVertexAI as LcChatVertexAI } from '@langchain/google-vertexai' import { ICommonObject, IMultiModalOption, @@ -9,8 +9,8 @@ import { INodeParams, IVisionChatModal } from '../../../src/Interface' +import { getModels, getRegions, MODEL_TYPE } from '../../../src/modelLoader' import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' -import { getModels, MODEL_TYPE } from '../../../src/modelLoader' const DEFAULT_IMAGE_MAX_TOKEN = 8192 const DEFAULT_IMAGE_MODEL = 'gemini-1.5-flash-latest' @@ -65,7 +65,7 @@ class GoogleVertexAI_ChatModels implements INode { constructor() { this.label = 'ChatGoogleVertexAI' this.name = 'chatGoogleVertexAI' - this.version = 5.2 + this.version = 5.3 this.type = 'ChatGoogleVertexAI' this.icon = 'GoogleVertex.svg' this.category = 'Chat Models' @@ -87,6 +87,14 @@ class GoogleVertexAI_ChatModels implements INode { type: 'BaseCache', optional: true }, + { + label: 'Region', + description: 'Region to use for the model.', + name: 'region', + type: 'asyncOptions', + loadMethod: 'listRegions', + optional: true + }, { label: 'Model Name', name: 'modelName', @@ -169,6 +177,9 @@ class GoogleVertexAI_ChatModels implements INode { loadMethods = { async listModels(): Promise { return await getModels(MODEL_TYPE.CHAT, 'chatGoogleVertexAI') + }, + async listRegions(): Promise { + return await getRegions(MODEL_TYPE.CHAT, 'chatGoogleVertexAI') } } @@ -203,6 +214,7 @@ class GoogleVertexAI_ChatModels implements INode { const topK = nodeData.inputs?.topK as string const streaming = nodeData.inputs?.streaming as boolean const thinkingBudget = nodeData.inputs?.thinkingBudget as string + const region = nodeData.inputs?.region as string const allowImageUploads = nodeData.inputs?.allowImageUploads as boolean @@ -223,6 +235,7 @@ class GoogleVertexAI_ChatModels implements INode { if (cache) obj.cache = cache if (topK) obj.topK = parseFloat(topK) if (thinkingBudget) obj.thinkingBudget = parseInt(thinkingBudget, 10) + if (region) obj.location = region const model = new ChatVertexAI(nodeData.id, obj) model.setMultiModalOption(multiModalOption) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index b34fd954c..20e40c1ff 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -1,7 +1,7 @@ -import { VertexAIEmbeddings, GoogleVertexAIEmbeddingsInput } from '@langchain/google-vertexai' +import { GoogleVertexAIEmbeddingsInput, VertexAIEmbeddings } from '@langchain/google-vertexai' import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface' +import { MODEL_TYPE, getModels, getRegions } from '../../../src/modelLoader' import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' -import { MODEL_TYPE, getModels } from '../../../src/modelLoader' class GoogleVertexAIEmbedding_Embeddings implements INode { label: string @@ -18,7 +18,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { constructor() { this.label = 'GoogleVertexAI Embeddings' this.name = 'googlevertexaiEmbeddings' - this.version = 2.0 + this.version = 2.1 this.type = 'GoogleVertexAIEmbeddings' this.icon = 'GoogleVertex.svg' this.category = 'Embeddings' @@ -39,7 +39,15 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { name: 'modelName', type: 'asyncOptions', loadMethod: 'listModels', - default: 'textembedding-gecko@001' + default: 'text-embedding-004' + }, + { + label: 'Region', + description: 'Region to use for the model.', + name: 'region', + type: 'asyncOptions', + loadMethod: 'listRegions', + optional: true } ] } @@ -48,12 +56,16 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { loadMethods = { async listModels(): Promise { return await getModels(MODEL_TYPE.EMBEDDING, 'googlevertexaiEmbeddings') + }, + async listRegions(): Promise { + return await getRegions(MODEL_TYPE.EMBEDDING, 'googlevertexaiEmbeddings') } } async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const modelName = nodeData.inputs?.modelName as string + const region = nodeData.inputs?.region as string const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) @@ -78,6 +90,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { model: modelName } if (Object.keys(authOptions).length !== 0) obj.authOptions = authOptions + if (region) obj.location = region const model = new VertexAIEmbeddings(obj) return model