From 850cbbf3d91a7927fd65f3e8764ecbc5ba004dc1 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 19:38:50 +0900 Subject: [PATCH 01/31] 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/31] 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/31] 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/31] 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/31] 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 2f0c40e503287e69c27311e2af29ce415fd7f6a7 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 22:32:42 +0900 Subject: [PATCH 06/31] Add GoogleVertexAI SVG icon --- packages/components/nodes/llms/GoogleVertexAI/vertexai.svg | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 packages/components/nodes/llms/GoogleVertexAI/vertexai.svg diff --git a/packages/components/nodes/llms/GoogleVertexAI/vertexai.svg b/packages/components/nodes/llms/GoogleVertexAI/vertexai.svg new file mode 100644 index 00000000..31244412 --- /dev/null +++ b/packages/components/nodes/llms/GoogleVertexAI/vertexai.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file From 5b5cec408ca16f6e265310274d400af7f2afc957 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 23:19:05 +0900 Subject: [PATCH 07/31] 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 08/31] 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 fd7ef866fb7e0698aa0bf23512f91593aaa751f5 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 23:59:51 +0900 Subject: [PATCH 09/31] add google-auth-library --- 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 a26f76c70505aa149941e58abc06e0f8ed31e962 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 3 Aug 2023 00:00:08 +0900 Subject: [PATCH 10/31] Add GoogleVertexAI_LLMs node class --- .../llms/GoogleVertexAI/googlevertexai.ts | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts diff --git a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts new file mode 100644 index 00000000..8a76c6af --- /dev/null +++ b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts @@ -0,0 +1,105 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' +import { GoogleVertexAI, GoogleVertexAITextInput } from 'langchain/llms/googlevertexai' + +class GoogleVertexAI_LLMs 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' + this.name = 'googlevertexai' + this.version = 1.0 + this.type = 'GoogleVertexAI' + this.icon = 'vertexai.svg' + this.category = 'LLMs' + this.description = 'Wrapper around GoogleVertexAI large language models' + this.baseClasses = [this.type, ...getBaseClasses(GoogleVertexAI)] + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'text-bison', + name: 'text-bison' + }, + { + label: 'code-bison', + name: 'code-bison' + }, + { + label: 'code-gecko', + name: 'code-gecko' + }, + { + label: 'text-bison@001', + name: 'text-bison@001' + }, + { + label: 'code-bison@001', + name: 'code-bison@001' + }, + { + label: 'code-gecko@001', + name: 'code-gecko@001' + }, + ], + default: 'text-bison', + }, + { + label: 'Temperature', + name: 'temperature', + type: 'number', + step: 0.1, + default: 0.7, + optional: true + }, + { + label: 'max Output Tokens', + name: 'maxOutputTokens', + type: 'number', + step: 1, + optional: true, + additionalParams: true + }, + { + label: 'Top Probability', + name: 'topP', + type: 'number', + step: 0.1, + optional: true, + additionalParams: true + }, + ] + } + + async init(nodeData: INodeData, _: string): Promise { + const temperature = nodeData.inputs?.temperature as string + const model = nodeData.inputs?.modelName as string + const maxOutputTokens = nodeData.inputs?.maxTokens as string + const topP = nodeData.inputs?.topP as string + + const obj: Partial = { + temperature: parseFloat(temperature), + model, + } + + if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) + if (topP) obj.topP = parseFloat(topP) + + const llm_model = new GoogleVertexAI(obj,) + return llm_model + } +} + +module.exports = { nodeClass: GoogleVertexAI_LLMs } \ No newline at end of file From 45069e10f24806501abb067e1528093f8b10a62f Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 3 Aug 2023 00:04:22 +0900 Subject: [PATCH 11/31] lint-fix --- .../nodes/llms/GoogleVertexAI/googlevertexai.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts index 8a76c6af..faf8e78b 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts @@ -52,9 +52,9 @@ class GoogleVertexAI_LLMs implements INode { { label: 'code-gecko@001', name: 'code-gecko@001' - }, + } ], - default: 'text-bison', + default: 'text-bison' }, { label: 'Temperature', @@ -79,7 +79,7 @@ class GoogleVertexAI_LLMs implements INode { step: 0.1, optional: true, additionalParams: true - }, + } ] } @@ -91,15 +91,15 @@ class GoogleVertexAI_LLMs implements INode { const obj: Partial = { temperature: parseFloat(temperature), - model, + model } if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) - const llm_model = new GoogleVertexAI(obj,) + const llm_model = new GoogleVertexAI(obj) return llm_model } } -module.exports = { nodeClass: GoogleVertexAI_LLMs } \ No newline at end of file +module.exports = { nodeClass: GoogleVertexAI_LLMs } From 24befbd5da9c423c6b17065ea14434660728104f Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 3 Aug 2023 00:08:24 +0900 Subject: [PATCH 12/31] Add GoogleVertexAI logo SVG file --- .../components/nodes/chatmodels/GoogleVertexAI/vertexai.svg | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 packages/components/nodes/chatmodels/GoogleVertexAI/vertexai.svg diff --git a/packages/components/nodes/chatmodels/GoogleVertexAI/vertexai.svg b/packages/components/nodes/chatmodels/GoogleVertexAI/vertexai.svg new file mode 100644 index 00000000..31244412 --- /dev/null +++ b/packages/components/nodes/chatmodels/GoogleVertexAI/vertexai.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file From d71a7d5790f17c2922cdfb56759ef01b30b52403 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 3 Aug 2023 00:09:26 +0900 Subject: [PATCH 13/31] Add google-auth-library dependency --- 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 16c008dba73fcb87be94d639bdf3f9eca428e2de Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 3 Aug 2023 00:21:13 +0900 Subject: [PATCH 14/31] Fix incorrect variable name for maxOutputTokens in GoogleVertexAI_LLMs class --- packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts index faf8e78b..754f3642 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts @@ -86,7 +86,7 @@ class GoogleVertexAI_LLMs implements INode { async init(nodeData: INodeData, _: string): Promise { const temperature = nodeData.inputs?.temperature as string const model = nodeData.inputs?.modelName as string - const maxOutputTokens = nodeData.inputs?.maxTokens as string + const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string const topP = nodeData.inputs?.topP as string const obj: Partial = { From fdb4450755de082551164d60571481a776175a76 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 3 Aug 2023 00:39:31 +0900 Subject: [PATCH 15/31] Add GoogleVertexAI chat model node class implementation --- .../GoogleVertexAI/GoogleVertexAI.ts | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts diff --git a/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts new file mode 100644 index 00000000..6ef96c21 --- /dev/null +++ b/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts @@ -0,0 +1,100 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' +import { ChatGoogleVertexAI, GoogleVertexAIChatInput } from 'langchain/chat_models/googlevertexai' + +class GoogleVertexAI_ChatModels 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 = 'ChatGoogleVertexAI' + this.name = 'chatGoogleVertexAI' + this.version = 1.0 + this.type = 'ChatGoogleVertexAI' + this.icon = 'vertexai.svg' + this.category = 'Chat Models' + this.description = 'Wrapper around VertexAI large language models that use the Chat endpoint' + this.baseClasses = [this.type, ...getBaseClasses(ChatGoogleVertexAI)] + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'chat-bison', + name: 'chat-bison' + }, + { + label: 'codechat-bison', + name: 'codechat-bison' + }, + { + label: 'chat-bison@001', + name: 'chat-bison@001' + }, + { + label: 'codechat-bison@001', + name: 'codechat-bison@001' + }, + ], + default: 'chat-bison', + optional: true + }, + { + label: 'Temperature', + name: 'temperature', + type: 'number', + step: 0.1, + default: 0.9, + optional: true + }, + { + label: 'Max Output Tokens', + name: 'maxOutputTokens', + type: 'number', + step: 1, + optional: true, + additionalParams: true + }, + { + label: 'Top Probability', + name: 'topP', + type: 'number', + step: 0.1, + optional: true, + additionalParams: true + }, + ] + } + + async init(nodeData: INodeData, _: string,): Promise { + const temperature = nodeData.inputs?.temperature as string + const model = nodeData.inputs?.modelName as string + const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string + const topP = nodeData.inputs?.topP as string + + const obj: Partial = { + temperature: parseFloat(temperature), + model, + } + + if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) + if (topP) obj.topP = parseFloat(topP) + + + + const chat_model = new ChatGoogleVertexAI(obj) + return chat_model + } +} + +module.exports = { nodeClass: GoogleVertexAI_ChatModels } From 7aaeab12c7e677ba7ae368f926516e48fc2b1093 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 3 Aug 2023 00:41:10 +0900 Subject: [PATCH 16/31] lint fix --- .../nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts index 6ef96c21..4ba2cf62 100644 --- a/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts @@ -44,7 +44,7 @@ class GoogleVertexAI_ChatModels implements INode { { label: 'codechat-bison@001', name: 'codechat-bison@001' - }, + } ], default: 'chat-bison', optional: true @@ -72,11 +72,11 @@ class GoogleVertexAI_ChatModels implements INode { step: 0.1, optional: true, additionalParams: true - }, + } ] } - async init(nodeData: INodeData, _: string,): Promise { + async init(nodeData: INodeData, _: string): Promise { const temperature = nodeData.inputs?.temperature as string const model = nodeData.inputs?.modelName as string const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string @@ -84,14 +84,12 @@ class GoogleVertexAI_ChatModels implements INode { const obj: Partial = { temperature: parseFloat(temperature), - model, + model } if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) - - const chat_model = new ChatGoogleVertexAI(obj) return chat_model } From 31cb4c1c64c83f4f13a7181652398a5da3a5b76c Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sat, 5 Aug 2023 03:18:29 +0900 Subject: [PATCH 17/31] 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 18/31] 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 19/31] 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 20/31] 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 21/31] 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 22/31] 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 23/31] 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 24/31] 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 From 701005ecb3cc79238be4af276d3e151730db3f8f Mon Sep 17 00:00:00 2001 From: Yongtae Date: Tue, 8 Aug 2023 12:36:48 +0900 Subject: [PATCH 25/31] remove un-use model name --- .../nodes/llms/GoogleVertexAI/googlevertexai.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts index 754f3642..023b80ad 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts @@ -40,18 +40,6 @@ class GoogleVertexAI_LLMs implements INode { { label: 'code-gecko', name: 'code-gecko' - }, - { - label: 'text-bison@001', - name: 'text-bison@001' - }, - { - label: 'code-bison@001', - name: 'code-bison@001' - }, - { - label: 'code-gecko@001', - name: 'code-gecko@001' } ], default: 'text-bison' From 7d6828a3613f292827a32c22a2f86a4720ce00fd Mon Sep 17 00:00:00 2001 From: Yongtae Date: Tue, 8 Aug 2023 12:46:12 +0900 Subject: [PATCH 26/31] Add Google Vertex Auth credential and make necessary changes for GoogleVertexAI --- .../credentials/GoogleAuth.credential.ts | 55 +++++++++++++++++++ .../llms/GoogleVertexAI/googlevertexai.ts | 38 ++++++++++--- packages/components/package.json | 2 +- 3 files changed, 87 insertions(+), 8 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..16b8e3b3 --- /dev/null +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -0,0 +1,55 @@ +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. You can also use the credential JSON object (either one)', + placeholder: 'your-path/application_default_credentials.json', + 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', + name: 'projectID', + description: 'Project ID of GCP. If not provided, it will be read from the credential file', + type: 'string', + optional: true, + additionalParams: true + } + ] + } +} + +module.exports = { credClass: GoogleVertexAuth } diff --git a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts index 023b80ad..4d9b3aed 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts @@ -1,6 +1,7 @@ -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' import { GoogleVertexAI, GoogleVertexAITextInput } from 'langchain/llms/googlevertexai' +import { GoogleAuthOptions } from 'google-auth-library' class GoogleVertexAI_LLMs implements INode { label: string @@ -23,6 +24,12 @@ class GoogleVertexAI_LLMs implements INode { this.category = 'LLMs' this.description = 'Wrapper around GoogleVertexAI large language models' this.baseClasses = [this.type, ...getBaseClasses(GoogleVertexAI)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleVertexAuth'] + } this.inputs = [ { label: 'Model Name', @@ -71,22 +78,39 @@ class GoogleVertexAI_LLMs implements INode { ] } - async init(nodeData: INodeData, _: string): Promise { + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) + const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) + const projectID = getCredentialParam('projectID', credentialData, nodeData) + + 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 + const temperature = nodeData.inputs?.temperature as string - const model = nodeData.inputs?.modelName as string + const modelName = nodeData.inputs?.modelName as string const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string const topP = nodeData.inputs?.topP as string const obj: Partial = { temperature: parseFloat(temperature), - model + model: modelName, + authOptions } if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) - const llm_model = new GoogleVertexAI(obj) - return llm_model + const model = new GoogleVertexAI(obj) + return model } } diff --git a/packages/components/package.json b/packages/components/package.json index cb8d757a..149b3259 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 fc3238348ff51d244f9b805c54118e69fc5edf13 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Tue, 8 Aug 2023 12:47:55 +0900 Subject: [PATCH 27/31] Update langchain dependency version to ^0.0.122 --- packages/components/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/package.json b/packages/components/package.json index 149b3259..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.122", + "langchain": "^0.0.122", "linkifyjs": "^4.1.1", "mammoth": "^1.5.1", "moment": "^2.29.3", From 812077c2aa19f64cff0e5f42ed59d7d8bf1a8731 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Tue, 8 Aug 2023 12:51:59 +0900 Subject: [PATCH 28/31] remove un-use model name --- .../nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts index 4ba2cf62..693cb2bc 100644 --- a/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts @@ -36,14 +36,6 @@ class GoogleVertexAI_ChatModels implements INode { { label: 'codechat-bison', name: 'codechat-bison' - }, - { - label: 'chat-bison@001', - name: 'chat-bison@001' - }, - { - label: 'codechat-bison@001', - name: 'codechat-bison@001' } ], default: 'chat-bison', From f7894ed4bf86a149d3e17c46186dd69bc4e69c1a Mon Sep 17 00:00:00 2001 From: Yongtae Date: Tue, 8 Aug 2023 13:06:38 +0900 Subject: [PATCH 29/31] Add Google Vertex AI credential support to GoogleVertexAI node --- .../credentials/GoogleAuth.credential.ts | 55 +++++++++++++++++++ .../GoogleVertexAI/GoogleVertexAI.ts | 39 ++++++++++--- packages/components/package.json | 2 +- 3 files changed, 88 insertions(+), 8 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..16b8e3b3 --- /dev/null +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -0,0 +1,55 @@ +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. You can also use the credential JSON object (either one)', + placeholder: 'your-path/application_default_credentials.json', + 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', + name: 'projectID', + description: 'Project ID of GCP. If not provided, it will be read from the credential file', + type: 'string', + optional: true, + additionalParams: true + } + ] + } +} + +module.exports = { credClass: GoogleVertexAuth } diff --git a/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts index 693cb2bc..a06ce0c9 100644 --- a/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts @@ -1,6 +1,7 @@ -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' import { ChatGoogleVertexAI, GoogleVertexAIChatInput } from 'langchain/chat_models/googlevertexai' +import { GoogleAuthOptions } from 'google-auth-library' class GoogleVertexAI_ChatModels implements INode { label: string @@ -23,6 +24,12 @@ class GoogleVertexAI_ChatModels implements INode { this.category = 'Chat Models' this.description = 'Wrapper around VertexAI large language models that use the Chat endpoint' this.baseClasses = [this.type, ...getBaseClasses(ChatGoogleVertexAI)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleVertexAuth'] + } this.inputs = [ { label: 'Model Name', @@ -68,22 +75,40 @@ class GoogleVertexAI_ChatModels implements INode { ] } - async init(nodeData: INodeData, _: string): Promise { + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) + const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) + const projectID = getCredentialParam('projectID', credentialData, nodeData) + + 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 + const temperature = nodeData.inputs?.temperature as string - const model = nodeData.inputs?.modelName as string + const modelName = nodeData.inputs?.modelName as string const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string const topP = nodeData.inputs?.topP as string const obj: Partial = { temperature: parseFloat(temperature), - model + model: modelName, + authOptions } if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) - const chat_model = new ChatGoogleVertexAI(obj) - return chat_model + const model = new ChatGoogleVertexAI(obj) + return model } } 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 95a40ea116579a8b1a86ce5119049a86c3f27673 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 9 Aug 2023 10:00:21 +0900 Subject: [PATCH 30/31] Rename GoogleVertexAI.ts to ChatGoogleVertexAI.ts in chatmodels folder --- .../GoogleVertexAI/{GoogleVertexAI.ts => ChatGoogleVertexAI.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/components/nodes/chatmodels/GoogleVertexAI/{GoogleVertexAI.ts => ChatGoogleVertexAI.ts} (100%) diff --git a/packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/chatmodels/GoogleVertexAI/ChatGoogleVertexAI.ts similarity index 100% rename from packages/components/nodes/chatmodels/GoogleVertexAI/GoogleVertexAI.ts rename to packages/components/nodes/chatmodels/GoogleVertexAI/ChatGoogleVertexAI.ts From 74abaa367c1b9a3033c7d8ee626b76ab8d7ce67f Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 9 Aug 2023 10:29:04 +0900 Subject: [PATCH 31/31] Rename GoogleVertexAI file --- .../llms/GoogleVertexAI/{googlevertexai.ts => GoogleVertexAI.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/components/nodes/llms/GoogleVertexAI/{googlevertexai.ts => GoogleVertexAI.ts} (100%) diff --git a/packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts similarity index 100% rename from packages/components/nodes/llms/GoogleVertexAI/googlevertexai.ts rename to packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts