mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 13:00:56 +03:00
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>
This commit is contained in:
@@ -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<INodeOptionsValue[]> {
|
||||
return await getModels(MODEL_TYPE.CHAT, 'chatGoogleVertexAI')
|
||||
},
|
||||
async listRegions(): Promise<INodeOptionsValue[]> {
|
||||
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)
|
||||
|
||||
+17
-4
@@ -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<INodeOptionsValue[]> {
|
||||
return await getModels(MODEL_TYPE.EMBEDDING, 'googlevertexaiEmbeddings')
|
||||
},
|
||||
async listRegions(): Promise<INodeOptionsValue[]> {
|
||||
return await getRegions(MODEL_TYPE.EMBEDDING, 'googlevertexaiEmbeddings')
|
||||
}
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user