From 2f0c40e503287e69c27311e2af29ce415fd7f6a7 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 22:32:42 +0900 Subject: [PATCH 1/8] 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 fd7ef866fb7e0698aa0bf23512f91593aaa751f5 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 2 Aug 2023 23:59:51 +0900 Subject: [PATCH 2/8] 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 3/8] 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 4/8] 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 16c008dba73fcb87be94d639bdf3f9eca428e2de Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 3 Aug 2023 00:21:13 +0900 Subject: [PATCH 5/8] 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 701005ecb3cc79238be4af276d3e151730db3f8f Mon Sep 17 00:00:00 2001 From: Yongtae Date: Tue, 8 Aug 2023 12:36:48 +0900 Subject: [PATCH 6/8] 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 7/8] 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 8/8] 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",