Skip to content

Commit 5e5b2a1

Browse files
StonoHenryHengZJ
andauthored
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 <henryheng@flowiseai.com>
1 parent cf965f3 commit 5e5b2a1

File tree

3 files changed

+127
-21
lines changed

3 files changed

+127
-21
lines changed

packages/components/models.json

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,50 @@
697697
"input_cost": 2.5e-7,
698698
"output_cost": 1.25e-6
699699
}
700+
],
701+
"regions": [
702+
{ "label": "us-east1", "name": "us-east1" },
703+
{ "label": "us-east4", "name": "us-east4" },
704+
{ "label": "us-central1", "name": "us-central1" },
705+
{ "label": "us-west1", "name": "us-west1" },
706+
{ "label": "europe-west4", "name": "europe-west4" },
707+
{ "label": "europe-west1", "name": "europe-west1" },
708+
{ "label": "europe-west3", "name": "europe-west3" },
709+
{ "label": "europe-west2", "name": "europe-west2" },
710+
{ "label": "asia-east1", "name": "asia-east1" },
711+
{ "label": "asia-southeast1", "name": "asia-southeast1" },
712+
{ "label": "asia-northeast1", "name": "asia-northeast1" },
713+
{ "label": "asia-south1", "name": "asia-south1" },
714+
{ "label": "australia-southeast1", "name": "australia-southeast1" },
715+
{ "label": "southamerica-east1", "name": "southamerica-east1" },
716+
{ "label": "africa-south1", "name": "africa-south1" },
717+
{ "label": "asia-east2", "name": "asia-east2" },
718+
{ "label": "asia-northeast2", "name": "asia-northeast2" },
719+
{ "label": "asia-northeast3", "name": "asia-northeast3" },
720+
{ "label": "asia-south2", "name": "asia-south2" },
721+
{ "label": "asia-southeast2", "name": "asia-southeast2" },
722+
{ "label": "australia-southeast2", "name": "australia-southeast2" },
723+
{ "label": "europe-central2", "name": "europe-central2" },
724+
{ "label": "europe-north1", "name": "europe-north1" },
725+
{ "label": "europe-north2", "name": "europe-north2" },
726+
{ "label": "europe-southwest1", "name": "europe-southwest1" },
727+
{ "label": "europe-west10", "name": "europe-west10" },
728+
{ "label": "europe-west12", "name": "europe-west12" },
729+
{ "label": "europe-west6", "name": "europe-west6" },
730+
{ "label": "europe-west8", "name": "europe-west8" },
731+
{ "label": "europe-west9", "name": "europe-west9" },
732+
{ "label": "me-central1", "name": "me-central1" },
733+
{ "label": "me-central2", "name": "me-central2" },
734+
{ "label": "me-west1", "name": "me-west1" },
735+
{ "label": "northamerica-northeast1", "name": "northamerica-northeast1" },
736+
{ "label": "northamerica-northeast2", "name": "northamerica-northeast2" },
737+
{ "label": "northamerica-south1", "name": "northamerica-south1" },
738+
{ "label": "southamerica-west1", "name": "southamerica-west1" },
739+
{ "label": "us-east5", "name": "us-east5" },
740+
{ "label": "us-south1", "name": "us-south1" },
741+
{ "label": "us-west2", "name": "us-west2" },
742+
{ "label": "us-west3", "name": "us-west3" },
743+
{ "label": "us-west4", "name": "us-west4" }
700744
]
701745
},
702746
{
@@ -1747,29 +1791,65 @@
17471791
"name": "googlevertexaiEmbeddings",
17481792
"models": [
17491793
{
1750-
"label": "multimodalembedding",
1751-
"name": "multimodalembedding"
1794+
"label": "gemini-embedding-001",
1795+
"name": "gemini-embedding-001"
17521796
},
17531797
{
17541798
"label": "text-embedding-004",
17551799
"name": "text-embedding-004"
17561800
},
17571801
{
1758-
"label": "text-multilingual-embedding-002",
1759-
"name": "text-multilingual-embedding-002"
1760-
},
1761-
{
1762-
"label": "textembedding-gecko@001",
1763-
"name": "textembedding-gecko@001"
1802+
"label": "text-embedding-005",
1803+
"name": "text-embedding-005"
17641804
},
17651805
{
1766-
"label": "textembedding-gecko@latest",
1767-
"name": "textembedding-gecko@latest"
1768-
},
1769-
{
1770-
"label": "textembedding-gecko-multilingual@latest",
1771-
"name": "textembedding-gecko-multilingual@latest"
1806+
"label": "text-multilingual-embedding-002",
1807+
"name": "text-multilingual-embedding-002"
17721808
}
1809+
],
1810+
"regions": [
1811+
{ "label": "us-east1", "name": "us-east1" },
1812+
{ "label": "us-east4", "name": "us-east4" },
1813+
{ "label": "us-central1", "name": "us-central1" },
1814+
{ "label": "us-west1", "name": "us-west1" },
1815+
{ "label": "europe-west4", "name": "europe-west4" },
1816+
{ "label": "europe-west1", "name": "europe-west1" },
1817+
{ "label": "europe-west3", "name": "europe-west3" },
1818+
{ "label": "europe-west2", "name": "europe-west2" },
1819+
{ "label": "asia-east1", "name": "asia-east1" },
1820+
{ "label": "asia-southeast1", "name": "asia-southeast1" },
1821+
{ "label": "asia-northeast1", "name": "asia-northeast1" },
1822+
{ "label": "asia-south1", "name": "asia-south1" },
1823+
{ "label": "australia-southeast1", "name": "australia-southeast1" },
1824+
{ "label": "southamerica-east1", "name": "southamerica-east1" },
1825+
{ "label": "africa-south1", "name": "africa-south1" },
1826+
{ "label": "asia-east2", "name": "asia-east2" },
1827+
{ "label": "asia-northeast2", "name": "asia-northeast2" },
1828+
{ "label": "asia-northeast3", "name": "asia-northeast3" },
1829+
{ "label": "asia-south2", "name": "asia-south2" },
1830+
{ "label": "asia-southeast2", "name": "asia-southeast2" },
1831+
{ "label": "australia-southeast2", "name": "australia-southeast2" },
1832+
{ "label": "europe-central2", "name": "europe-central2" },
1833+
{ "label": "europe-north1", "name": "europe-north1" },
1834+
{ "label": "europe-north2", "name": "europe-north2" },
1835+
{ "label": "europe-southwest1", "name": "europe-southwest1" },
1836+
{ "label": "europe-west10", "name": "europe-west10" },
1837+
{ "label": "europe-west12", "name": "europe-west12" },
1838+
{ "label": "europe-west6", "name": "europe-west6" },
1839+
{ "label": "europe-west8", "name": "europe-west8" },
1840+
{ "label": "europe-west9", "name": "europe-west9" },
1841+
{ "label": "me-central1", "name": "me-central1" },
1842+
{ "label": "me-central2", "name": "me-central2" },
1843+
{ "label": "me-west1", "name": "me-west1" },
1844+
{ "label": "northamerica-northeast1", "name": "northamerica-northeast1" },
1845+
{ "label": "northamerica-northeast2", "name": "northamerica-northeast2" },
1846+
{ "label": "northamerica-south1", "name": "northamerica-south1" },
1847+
{ "label": "southamerica-west1", "name": "southamerica-west1" },
1848+
{ "label": "us-east5", "name": "us-east5" },
1849+
{ "label": "us-south1", "name": "us-south1" },
1850+
{ "label": "us-west2", "name": "us-west2" },
1851+
{ "label": "us-west3", "name": "us-west3" },
1852+
{ "label": "us-west4", "name": "us-west4" }
17731853
]
17741854
},
17751855
{

packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseCache } from '@langchain/core/caches'
2-
import { ChatVertexAI as LcChatVertexAI, ChatVertexAIInput } from '@langchain/google-vertexai'
2+
import { ChatVertexAIInput, ChatVertexAI as LcChatVertexAI } from '@langchain/google-vertexai'
33
import {
44
ICommonObject,
55
IMultiModalOption,
@@ -9,8 +9,8 @@ import {
99
INodeParams,
1010
IVisionChatModal
1111
} from '../../../src/Interface'
12+
import { getModels, getRegions, MODEL_TYPE } from '../../../src/modelLoader'
1213
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
13-
import { getModels, MODEL_TYPE } from '../../../src/modelLoader'
1414

1515
const DEFAULT_IMAGE_MAX_TOKEN = 8192
1616
const DEFAULT_IMAGE_MODEL = 'gemini-1.5-flash-latest'
@@ -65,7 +65,7 @@ class GoogleVertexAI_ChatModels implements INode {
6565
constructor() {
6666
this.label = 'ChatGoogleVertexAI'
6767
this.name = 'chatGoogleVertexAI'
68-
this.version = 5.2
68+
this.version = 5.3
6969
this.type = 'ChatGoogleVertexAI'
7070
this.icon = 'GoogleVertex.svg'
7171
this.category = 'Chat Models'
@@ -87,6 +87,14 @@ class GoogleVertexAI_ChatModels implements INode {
8787
type: 'BaseCache',
8888
optional: true
8989
},
90+
{
91+
label: 'Region',
92+
description: 'Region to use for the model.',
93+
name: 'region',
94+
type: 'asyncOptions',
95+
loadMethod: 'listRegions',
96+
optional: true
97+
},
9098
{
9199
label: 'Model Name',
92100
name: 'modelName',
@@ -169,6 +177,9 @@ class GoogleVertexAI_ChatModels implements INode {
169177
loadMethods = {
170178
async listModels(): Promise<INodeOptionsValue[]> {
171179
return await getModels(MODEL_TYPE.CHAT, 'chatGoogleVertexAI')
180+
},
181+
async listRegions(): Promise<INodeOptionsValue[]> {
182+
return await getRegions(MODEL_TYPE.CHAT, 'chatGoogleVertexAI')
172183
}
173184
}
174185

@@ -203,6 +214,7 @@ class GoogleVertexAI_ChatModels implements INode {
203214
const topK = nodeData.inputs?.topK as string
204215
const streaming = nodeData.inputs?.streaming as boolean
205216
const thinkingBudget = nodeData.inputs?.thinkingBudget as string
217+
const region = nodeData.inputs?.region as string
206218

207219
const allowImageUploads = nodeData.inputs?.allowImageUploads as boolean
208220

@@ -223,6 +235,7 @@ class GoogleVertexAI_ChatModels implements INode {
223235
if (cache) obj.cache = cache
224236
if (topK) obj.topK = parseFloat(topK)
225237
if (thinkingBudget) obj.thinkingBudget = parseInt(thinkingBudget, 10)
238+
if (region) obj.location = region
226239

227240
const model = new ChatVertexAI(nodeData.id, obj)
228241
model.setMultiModalOption(multiModalOption)

packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { VertexAIEmbeddings, GoogleVertexAIEmbeddingsInput } from '@langchain/google-vertexai'
1+
import { GoogleVertexAIEmbeddingsInput, VertexAIEmbeddings } from '@langchain/google-vertexai'
22
import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface'
3+
import { MODEL_TYPE, getModels, getRegions } from '../../../src/modelLoader'
34
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
4-
import { MODEL_TYPE, getModels } from '../../../src/modelLoader'
55

66
class GoogleVertexAIEmbedding_Embeddings implements INode {
77
label: string
@@ -18,7 +18,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode {
1818
constructor() {
1919
this.label = 'GoogleVertexAI Embeddings'
2020
this.name = 'googlevertexaiEmbeddings'
21-
this.version = 2.0
21+
this.version = 2.1
2222
this.type = 'GoogleVertexAIEmbeddings'
2323
this.icon = 'GoogleVertex.svg'
2424
this.category = 'Embeddings'
@@ -39,7 +39,15 @@ class GoogleVertexAIEmbedding_Embeddings implements INode {
3939
name: 'modelName',
4040
type: 'asyncOptions',
4141
loadMethod: 'listModels',
42-
default: 'textembedding-gecko@001'
42+
default: 'text-embedding-004'
43+
},
44+
{
45+
label: 'Region',
46+
description: 'Region to use for the model.',
47+
name: 'region',
48+
type: 'asyncOptions',
49+
loadMethod: 'listRegions',
50+
optional: true
4351
}
4452
]
4553
}
@@ -48,12 +56,16 @@ class GoogleVertexAIEmbedding_Embeddings implements INode {
4856
loadMethods = {
4957
async listModels(): Promise<INodeOptionsValue[]> {
5058
return await getModels(MODEL_TYPE.EMBEDDING, 'googlevertexaiEmbeddings')
59+
},
60+
async listRegions(): Promise<INodeOptionsValue[]> {
61+
return await getRegions(MODEL_TYPE.EMBEDDING, 'googlevertexaiEmbeddings')
5162
}
5263
}
5364

5465
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
5566
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
5667
const modelName = nodeData.inputs?.modelName as string
68+
const region = nodeData.inputs?.region as string
5769
const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData)
5870
const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData)
5971
const projectID = getCredentialParam('projectID', credentialData, nodeData)
@@ -78,6 +90,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode {
7890
model: modelName
7991
}
8092
if (Object.keys(authOptions).length !== 0) obj.authOptions = authOptions
93+
if (region) obj.location = region
8194

8295
const model = new VertexAIEmbeddings(obj)
8396
return model

0 commit comments

Comments
 (0)