From 850cbbf3d91a7927fd65f3e8764ecbc5ba004dc1 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 19:38:50 +0900 Subject: [PATCH 01/15] Add Google Vertex AI Embedding SVG icon file --- .../nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/components/nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg new file mode 100644 index 00000000..efc3589c --- /dev/null +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg @@ -0,0 +1 @@ + \ No newline at end of file From 2b8cf7acdc28e04388b2c666d9c7cd1d9909a717 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 19:39:07 +0900 Subject: [PATCH 02/15] Add Google Vertex AI embedding icon --- .../nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg index efc3589c..31244412 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/vertexai.svg @@ -1 +1,2 @@ + \ No newline at end of file From 129f411c26a3f21a27fe5973536a0911bdc05c29 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 22:16:43 +0900 Subject: [PATCH 03/15] add google-auth-library in package --- packages/components/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/package.json b/packages/components/package.json index 85267d38..cb8d757a 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -36,6 +36,7 @@ "express": "^4.17.3", "faiss-node": "^0.2.2", "form-data": "^4.0.0", + "google-auth-library": "^9.0.0", "graphql": "^16.6.0", "html-to-text": "^9.0.5", "langchain": "^0.0.117", From 6f80f87c552c43a5d829e08d77018fc7b4180a59 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 22:16:54 +0900 Subject: [PATCH 04/15] Add GoogleVertexAIEmbedding_Embeddings class for GoogleVertexAIEmbeddings --- .../GoogleVertexAIEmbedding.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts new file mode 100644 index 00000000..05ceb415 --- /dev/null +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -0,0 +1,56 @@ +import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams} from "langchain/embeddings/googlevertexai"; +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses} from '../../../src/utils' + +class GoogleVertexAIEmbedding_Embeddings implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + credential: INodeParams + inputs: INodeParams[] + + + constructor() { + this.label = 'GoogleVertexAI Embeddings' + this.name = 'googlevertexaiEmbeddings' + this.version = 1.0 + this.type = 'GoogleVertexAIEmbeddings' + this.icon = 'vertexai.svg' + this.category = 'Embeddings' + this.description = 'Google vertexAI API to generate embeddings for a given text' + this.baseClasses = [this.type, ...getBaseClasses(GoogleVertexAIEmbeddings)] + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'textembedding-gecko', + name: 'textembedding-gecko' + } + ], + default: 'textembedding-gecko', + } + ] + } + + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + + const model = nodeData.inputs?.modelName as string + const obj: GoogleVertexAIEmbeddingsParams = { + model + } + + const embedding = new GoogleVertexAIEmbeddings(obj); + return embedding + } +} + +module.exports = { nodeClass: GoogleVertexAIEmbedding_Embeddings } \ No newline at end of file From 63d920158cb588881b7ff275bfa8120b941496f5 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 22:28:49 +0900 Subject: [PATCH 05/15] lint-fix --- .../GoogleVertexAIEmbedding.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 05ceb415..d92bd7d8 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -1,6 +1,6 @@ -import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams} from "langchain/embeddings/googlevertexai"; +import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams } from 'langchain/embeddings/googlevertexai' import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' -import { getBaseClasses} from '../../../src/utils' +import { getBaseClasses } from '../../../src/utils' class GoogleVertexAIEmbedding_Embeddings implements INode { label: string @@ -14,7 +14,6 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { credential: INodeParams inputs: INodeParams[] - constructor() { this.label = 'GoogleVertexAI Embeddings' this.name = 'googlevertexaiEmbeddings' @@ -35,22 +34,20 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { name: 'textembedding-gecko' } ], - default: 'textembedding-gecko', + default: 'textembedding-gecko' } ] } - async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { - const model = nodeData.inputs?.modelName as string const obj: GoogleVertexAIEmbeddingsParams = { model } - const embedding = new GoogleVertexAIEmbeddings(obj); + const embedding = new GoogleVertexAIEmbeddings(obj) return embedding } } -module.exports = { nodeClass: GoogleVertexAIEmbedding_Embeddings } \ No newline at end of file +module.exports = { nodeClass: GoogleVertexAIEmbedding_Embeddings } From 5b5cec408ca16f6e265310274d400af7f2afc957 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 23:19:05 +0900 Subject: [PATCH 06/15] Remove unnecessary import statement and parameter in the async init function --- .../GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index d92bd7d8..894ccab5 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -1,5 +1,5 @@ import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams } from 'langchain/embeddings/googlevertexai' -import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { INode, INodeData, INodeParams } from '../../../src/Interface' import { getBaseClasses } from '../../../src/utils' class GoogleVertexAIEmbedding_Embeddings implements INode { @@ -39,7 +39,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { ] } - async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + async init(nodeData: INodeData, _: string): Promise { const model = nodeData.inputs?.modelName as string const obj: GoogleVertexAIEmbeddingsParams = { model From d408c06ab0906b1239d252d3c82f5515e4bc9d2a Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 23:19:59 +0900 Subject: [PATCH 07/15] Add support for 'textembedding-gecko@001' in GoogleVertexAIEmbedding --- .../GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 894ccab5..c7079d05 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -32,6 +32,10 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { { label: 'textembedding-gecko', name: 'textembedding-gecko' + }, + { + label: 'textembedding-gecko@001', + name: 'textembedding-gecko@001' } ], default: 'textembedding-gecko' From 31cb4c1c64c83f4f13a7181652398a5da3a5b76c Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sat, 5 Aug 2023 03:18:29 +0900 Subject: [PATCH 08/15] Add Google Vertex Auth credential and update langchain version --- .../credentials/GoogleAuth.credential.ts | 25 +++++++++++++++++++ .../GoogleVertexAIEmbedding.ts | 22 +++++++++++++--- packages/components/package.json | 2 +- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 packages/components/credentials/GoogleAuth.credential.ts diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts new file mode 100644 index 00000000..de4c8843 --- /dev/null +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -0,0 +1,25 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class GoogleVertexAuth implements INodeCredential { + label: string + name: string + version: number + inputs: INodeParams[] + + constructor() { + this.label = 'Google Vertex Auth' + this.name = 'googleVertexAuth' + this.version = 1.0 + this.inputs = [ + { + label: 'Google Application Credential File Path', + name: 'googleApplicationCredentialFilePath', + description: 'Path to your google application credential json file', + placeholder: 'your-path/application_default_credentials.json', + type: 'string' + } + ] + } +} + +module.exports = { credClass: GoogleVertexAuth } \ No newline at end of file diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index c7079d05..1c491682 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -1,6 +1,6 @@ import { GoogleVertexAIEmbeddings, GoogleVertexAIEmbeddingsParams } from 'langchain/embeddings/googlevertexai' -import { INode, INodeData, INodeParams } from '../../../src/Interface' -import { getBaseClasses } from '../../../src/utils' +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' class GoogleVertexAIEmbedding_Embeddings implements INode { label: string @@ -23,6 +23,12 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { this.category = 'Embeddings' this.description = 'Google vertexAI API to generate embeddings for a given text' this.baseClasses = [this.type, ...getBaseClasses(GoogleVertexAIEmbeddings)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleVertexAuth'] + } this.inputs = [ { label: 'Model Name', @@ -43,10 +49,18 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { ] } - async init(nodeData: INodeData, _: string): Promise { + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const model = nodeData.inputs?.modelName as string + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) + + const authOptions = { + keyFile: googleApplicationCredentialFilePath, + }; const obj: GoogleVertexAIEmbeddingsParams = { - model + model:model, + authOptions, + } const embedding = new GoogleVertexAIEmbeddings(obj) diff --git a/packages/components/package.json b/packages/components/package.json index cb8d757a..afcfd361 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -39,7 +39,7 @@ "google-auth-library": "^9.0.0", "graphql": "^16.6.0", "html-to-text": "^9.0.5", - "langchain": "^0.0.117", + "langchain": "^0.0.122", "linkifyjs": "^4.1.1", "mammoth": "^1.5.1", "moment": "^2.29.3", From 6ef37eade3443dc30f3704ccbe1a450cc9aae8ec Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sat, 5 Aug 2023 03:19:35 +0900 Subject: [PATCH 09/15] remove model name --- .../GoogleVertexAIEmbedding.ts | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 1c491682..3d76585d 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -29,28 +29,10 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { type: 'credential', credentialNames: ['googleVertexAuth'] } - this.inputs = [ - { - label: 'Model Name', - name: 'modelName', - type: 'options', - options: [ - { - label: 'textembedding-gecko', - name: 'textembedding-gecko' - }, - { - label: 'textembedding-gecko@001', - name: 'textembedding-gecko@001' - } - ], - default: 'textembedding-gecko' - } - ] + this.inputs = [] } async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { - const model = nodeData.inputs?.modelName as string const credentialData = await getCredentialData(nodeData.credential ?? '', options) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) @@ -58,7 +40,6 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { keyFile: googleApplicationCredentialFilePath, }; const obj: GoogleVertexAIEmbeddingsParams = { - model:model, authOptions, } From c3b90e38750802cfe322cafb7c39ff0bc2ffd788 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sat, 5 Aug 2023 03:28:00 +0900 Subject: [PATCH 10/15] 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 From 31543994040e6131b5de78cd2aa757025d7d6812 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sat, 5 Aug 2023 03:29:03 +0900 Subject: [PATCH 11/15] lint fix GoogleAuth and GoogleVertexAIEmbedding code --- .../components/credentials/GoogleAuth.credential.ts | 2 +- .../GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts index de4c8843..484ff522 100644 --- a/packages/components/credentials/GoogleAuth.credential.ts +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -22,4 +22,4 @@ class GoogleVertexAuth implements INodeCredential { } } -module.exports = { credClass: GoogleVertexAuth } \ No newline at end of file +module.exports = { credClass: GoogleVertexAuth } diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 9a7525a6..205e12ef 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -46,7 +46,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { type: 'string', additionalParams: true, optional: true - }, + } ] } @@ -56,14 +56,14 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) - const authOptions:GoogleAuthOptions = { - keyFile: googleApplicationCredentialFilePath, - }; + const authOptions: GoogleAuthOptions = { + keyFile: googleApplicationCredentialFilePath + } if (projectID) authOptions.projectId = projectID const obj: GoogleVertexAIEmbeddingsParams = { - authOptions, + authOptions } if (location) obj.location = location From adffc7cb1d64c6632e6b46ac2476a3786ac05363 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sat, 5 Aug 2023 03:33:26 +0900 Subject: [PATCH 12/15] Add error handling for missing Google Application Credential file path --- .../GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 205e12ef..7b859e77 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -55,6 +55,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { const location = nodeData.inputs?.location as string const credentialData = await getCredentialData(nodeData.credential ?? '', options) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) + if (!googleApplicationCredentialFilePath) throw new Error('Please specify your Google Application Credential file path') const authOptions: GoogleAuthOptions = { keyFile: googleApplicationCredentialFilePath From d6844655ccc4cfc08faf73922d907cd98b760cf8 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sat, 5 Aug 2023 12:08:39 +0900 Subject: [PATCH 13/15] Unify the names of what is being returned --- .../GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 7b859e77..dbcc9c62 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -68,8 +68,8 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { } if (location) obj.location = location - const embedding = new GoogleVertexAIEmbeddings(obj) - return embedding + const model = new GoogleVertexAIEmbeddings(obj) + return model } } From a0d0d5e6e3ddfe22a00b4083ff8d5c7fcb01f2d0 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Mon, 7 Aug 2023 12:11:35 +0900 Subject: [PATCH 14/15] move project id and remove location --- .../credentials/GoogleAuth.credential.ts | 8 +++++++ .../GoogleVertexAIEmbedding.ts | 23 ++----------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts index 484ff522..d06d32b1 100644 --- a/packages/components/credentials/GoogleAuth.credential.ts +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -17,6 +17,14 @@ class GoogleVertexAuth implements INodeCredential { description: 'Path to your google application credential json file', placeholder: 'your-path/application_default_credentials.json', type: 'string' + }, + { + label: 'Project ID', + name: 'projectID', + description: 'Project ID of GCP. If not provided, it will be read from the credential file', + type: 'string', + optional: true, + additionalParams: true } ] } diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index dbcc9c62..d68911a9 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -30,32 +30,14 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { type: 'credential', credentialNames: ['googleVertexAuth'] } - 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 - } - ] + this.inputs = [] } 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) if (!googleApplicationCredentialFilePath) throw new Error('Please specify your Google Application Credential file path') + const projectID = getCredentialParam('projectID', credentialData, nodeData) const authOptions: GoogleAuthOptions = { keyFile: googleApplicationCredentialFilePath @@ -66,7 +48,6 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { const obj: GoogleVertexAIEmbeddingsParams = { authOptions } - if (location) obj.location = location const model = new GoogleVertexAIEmbeddings(obj) return model From 9e0d2ccb3ac084d45e9ddb41a8f6854ee6cd138a Mon Sep 17 00:00:00 2001 From: Yongtae Date: Tue, 8 Aug 2023 10:39:13 +0900 Subject: [PATCH 15/15] Refactor GoogleAuth.credential to support both file path and JSON object credentials. Update GoogleVertexAIEmbedding to handle both cases --- .../credentials/GoogleAuth.credential.ts | 26 +++++++++++++++++-- .../GoogleVertexAIEmbedding.ts | 14 +++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts index d06d32b1..16b8e3b3 100644 --- a/packages/components/credentials/GoogleAuth.credential.ts +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -14,9 +14,31 @@ class GoogleVertexAuth implements INodeCredential { { label: 'Google Application Credential File Path', name: 'googleApplicationCredentialFilePath', - description: 'Path to your google application credential json file', + description: + 'Path to your google application credential json file. You can also use the credential JSON object (either one)', placeholder: 'your-path/application_default_credentials.json', - type: 'string' + type: 'string', + optional: true + }, + { + label: 'Google Credential JSON Object', + name: 'googleApplicationCredential', + description: 'JSON object of your google application credential. You can also use the file path (either one)', + placeholder: `{ + "type": ..., + "project_id": ..., + "private_key_id": ..., + "private_key": ..., + "client_email": ..., + "client_id": ..., + "auth_uri": ..., + "token_uri": ..., + "auth_provider_x509_cert_url": ..., + "client_x509_cert_url": ... +}`, + type: 'string', + rows: 4, + optional: true }, { label: 'Project ID', diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index d68911a9..23bd3565 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -36,12 +36,18 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) - if (!googleApplicationCredentialFilePath) throw new Error('Please specify your Google Application Credential file path') + const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) - const authOptions: GoogleAuthOptions = { - keyFile: googleApplicationCredentialFilePath - } + if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error('Please specify your Google Application Credential') + if (googleApplicationCredentialFilePath && googleApplicationCredential) + throw new Error('Please use either Google Application Credential File Path or Google Credential JSON Object') + + const authOptions: GoogleAuthOptions = {} + if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath + else if (!googleApplicationCredentialFilePath && googleApplicationCredential) + authOptions.credentials = JSON.parse(googleApplicationCredential) if (projectID) authOptions.projectId = projectID