From c3b90e38750802cfe322cafb7c39ff0bc2ffd788 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sat, 5 Aug 2023 03:28:00 +0900 Subject: [PATCH] Add optional inputs for project ID and location in GoogleVertexAIEmbedding --- .../GoogleVertexAIEmbedding.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 3d76585d..9a7525a6 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -1,6 +1,7 @@ import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams } from 'langchain/embeddings/googlevertexai' import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { GoogleAuthOptions } from 'google-auth-library' class GoogleVertexAIEmbedding_Embeddings implements INode { label: string @@ -29,20 +30,42 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { type: 'credential', credentialNames: ['googleVertexAuth'] } - this.inputs = [] + this.inputs = [ + { + label: 'Project ID', + name: 'projectID', + description: 'project id of GCP', + type: 'string', + additionalParams: true, + optional: true + }, + { + label: 'location', + name: 'location', + description: 'location of API', + type: 'string', + additionalParams: true, + optional: true + }, + ] } async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const projectID = nodeData.inputs?.projectID as string + const location = nodeData.inputs?.location as string const credentialData = await getCredentialData(nodeData.credential ?? '', options) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) - const authOptions = { + const authOptions:GoogleAuthOptions = { keyFile: googleApplicationCredentialFilePath, }; + + if (projectID) authOptions.projectId = projectID + const obj: GoogleVertexAIEmbeddingsParams = { authOptions, - } + if (location) obj.location = location const embedding = new GoogleVertexAIEmbeddings(obj) return embedding