From fbf087848a7cb63c25c1601414974177dfcefe82 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Wed, 23 Aug 2023 19:00:55 +0900 Subject: [PATCH 01/13] add Skip Extra Credential File on credentials --- .../components/credentials/GoogleAuth.credential.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts index 16b8e3b3..bd83a908 100644 --- a/packages/components/credentials/GoogleAuth.credential.ts +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -11,6 +11,13 @@ class GoogleVertexAuth implements INodeCredential { this.name = 'googleVertexAuth' this.version = 1.0 this.inputs = [ + { + label: 'Skip Extra Credential File', + name: 'skipExtraCredentialFile', + description: 'Enable this if you are using GCP and do not need to register an extra credential file', + type: 'boolean', + optional: true + }, { label: 'Google Application Credential File Path', name: 'googleApplicationCredentialFilePath', @@ -35,11 +42,14 @@ class GoogleVertexAuth implements INodeCredential { "token_uri": ..., "auth_provider_x509_cert_url": ..., "client_x509_cert_url": ... + }`, type: 'string', rows: 4, optional: true }, + + { label: 'Project ID', name: 'projectID', From 51e9cdf4c10d106b633d07b2ae9f09201c395119 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 24 Aug 2023 11:39:12 +0900 Subject: [PATCH 02/13] implementation of llm model --- .../GoogleVertexAIEmbedding.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 23bd3565..99ee78b5 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -38,23 +38,33 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) + const skipExtraCredentialFile = getCredentialParam('skipExtraCredentialFile', credentialData, nodeData) - if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + if (!skipExtraCredentialFile && !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 inputs = [ + googleApplicationCredentialFilePath, + googleApplicationCredential, + skipExtraCredentialFile + ]; + + if (inputs.filter(Boolean).length > 1) { + throw new Error('Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.') + } const authOptions: GoogleAuthOptions = {} - if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath - else if (!googleApplicationCredentialFilePath && googleApplicationCredential) - authOptions.credentials = JSON.parse(googleApplicationCredential) + if (!skipExtraCredentialFile){ + if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath + else if (!googleApplicationCredentialFilePath && googleApplicationCredential) + authOptions.credentials = JSON.parse(googleApplicationCredential) - if (projectID) authOptions.projectId = projectID - - const obj: GoogleVertexAIEmbeddingsParams = { - authOptions + if (projectID) authOptions.projectId = projectID } + const obj: GoogleVertexAIEmbeddingsParams = {} + if (authOptions) obj.authOptions = authOptions + const model = new GoogleVertexAIEmbeddings(obj) return model } From 0830b8fbe573e3c0ac6429831cf56c338dc46ea7 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 24 Aug 2023 11:39:22 +0900 Subject: [PATCH 03/13] implementation of embedding model --- .../llms/GoogleVertexAI/GoogleVertexAI.ts | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts index 4d9b3aed..ef04883b 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts @@ -80,20 +80,32 @@ class GoogleVertexAI_LLMs implements INode { async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const skipExtraCredentialFile = getCredentialParam('skipExtraCredentialFile', credentialData, nodeData) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) - if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + + if (!skipExtraCredentialFile && !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 inputs = [ + googleApplicationCredentialFilePath, + googleApplicationCredential, + skipExtraCredentialFile + ]; + + if (inputs.filter(Boolean).length > 1) { + throw new Error('Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.') + } const authOptions: GoogleAuthOptions = {} - if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath - else if (!googleApplicationCredentialFilePath && googleApplicationCredential) - authOptions.credentials = JSON.parse(googleApplicationCredential) - if (projectID) authOptions.projectId = projectID + if (!skipExtraCredentialFile){ + 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 modelName = nodeData.inputs?.modelName as string @@ -103,9 +115,10 @@ class GoogleVertexAI_LLMs implements INode { const obj: Partial = { temperature: parseFloat(temperature), model: modelName, - authOptions } + if (authOptions) obj.authOptions = authOptions + if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) From d9113da6bb0c1b897c5432d301125706cbc40841 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 24 Aug 2023 11:42:49 +0900 Subject: [PATCH 04/13] lint fix --- .../credentials/GoogleAuth.credential.ts | 1 - .../GoogleVertexAIEmbedding.ts | 17 ++++++++-------- .../llms/GoogleVertexAI/GoogleVertexAI.ts | 20 +++++++++---------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts index bd83a908..bd9decd0 100644 --- a/packages/components/credentials/GoogleAuth.credential.ts +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -49,7 +49,6 @@ class GoogleVertexAuth implements INodeCredential { optional: true }, - { label: 'Project ID', name: 'projectID', diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 99ee78b5..a443e9f0 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -43,19 +43,18 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) throw new Error('Please specify your Google Application Credential') - const inputs = [ - googleApplicationCredentialFilePath, - googleApplicationCredential, - skipExtraCredentialFile - ]; - + const inputs = [googleApplicationCredentialFilePath, googleApplicationCredential, skipExtraCredentialFile] + if (inputs.filter(Boolean).length > 1) { - throw new Error('Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.') + throw new Error( + 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.' + ) } const authOptions: GoogleAuthOptions = {} - if (!skipExtraCredentialFile){ - if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath + if (!skipExtraCredentialFile) { + if (googleApplicationCredentialFilePath && !googleApplicationCredential) + authOptions.keyFile = googleApplicationCredentialFilePath else if (!googleApplicationCredentialFilePath && googleApplicationCredential) authOptions.credentials = JSON.parse(googleApplicationCredential) diff --git a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts index ef04883b..cb8ae61c 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts @@ -85,22 +85,20 @@ class GoogleVertexAI_LLMs implements INode { const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) - if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) throw new Error('Please specify your Google Application Credential') - const inputs = [ - googleApplicationCredentialFilePath, - googleApplicationCredential, - skipExtraCredentialFile - ]; - + const inputs = [googleApplicationCredentialFilePath, googleApplicationCredential, skipExtraCredentialFile] + if (inputs.filter(Boolean).length > 1) { - throw new Error('Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.') + throw new Error( + 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.' + ) } const authOptions: GoogleAuthOptions = {} - if (!skipExtraCredentialFile){ - if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath + if (!skipExtraCredentialFile) { + if (googleApplicationCredentialFilePath && !googleApplicationCredential) + authOptions.keyFile = googleApplicationCredentialFilePath else if (!googleApplicationCredentialFilePath && googleApplicationCredential) authOptions.credentials = JSON.parse(googleApplicationCredential) @@ -114,7 +112,7 @@ class GoogleVertexAI_LLMs implements INode { const obj: Partial = { temperature: parseFloat(temperature), - model: modelName, + model: modelName } if (authOptions) obj.authOptions = authOptions From d696ffeb85aaee942f8b693c6efaf240bee437b3 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 24 Aug 2023 12:14:44 +0900 Subject: [PATCH 05/13] implementation of chat model --- .../GoogleVertexAI/ChatGoogleVertexAI.ts | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/components/nodes/chatmodels/GoogleVertexAI/ChatGoogleVertexAI.ts b/packages/components/nodes/chatmodels/GoogleVertexAI/ChatGoogleVertexAI.ts index a06ce0c9..b7786e7c 100644 --- a/packages/components/nodes/chatmodels/GoogleVertexAI/ChatGoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/GoogleVertexAI/ChatGoogleVertexAI.ts @@ -20,9 +20,9 @@ class GoogleVertexAI_ChatModels implements INode { this.name = 'chatGoogleVertexAI' this.version = 1.0 this.type = 'ChatGoogleVertexAI' - this.icon = 'vertexai.svg' + this.icon = 'vertexa1i.svg' this.category = 'Chat Models' - this.description = 'Wrapper around VertexAI large language models that use the Chat endpoint' + this.description = 'wassyoi' this.baseClasses = [this.type, ...getBaseClasses(ChatGoogleVertexAI)] this.credential = { label: 'Connect Credential', @@ -37,7 +37,7 @@ class GoogleVertexAI_ChatModels implements INode { type: 'options', options: [ { - label: 'chat-bison', + label: 'chat-bison11111', name: 'chat-bison' }, { @@ -45,7 +45,7 @@ class GoogleVertexAI_ChatModels implements INode { name: 'codechat-bison' } ], - default: 'chat-bison', + default: 'chat-bison11111', optional: true }, { @@ -77,21 +77,31 @@ class GoogleVertexAI_ChatModels implements INode { async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const skipExtraCredentialFile = getCredentialParam('skipExtraCredentialFile', credentialData, nodeData) 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') + // if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) + // throw new Error('Please specify your Google Application Credential') + + const inputs = [googleApplicationCredentialFilePath, googleApplicationCredential, skipExtraCredentialFile] + + if (inputs.filter(Boolean).length > 1) { + throw new Error( + 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.' + ) + } const authOptions: GoogleAuthOptions = {} - if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath - else if (!googleApplicationCredentialFilePath && googleApplicationCredential) - authOptions.credentials = JSON.parse(googleApplicationCredential) + if (!skipExtraCredentialFile) { + if (googleApplicationCredentialFilePath && !googleApplicationCredential) + authOptions.keyFile = googleApplicationCredentialFilePath + else if (!googleApplicationCredentialFilePath && googleApplicationCredential) + authOptions.credentials = JSON.parse(googleApplicationCredential) - if (projectID) authOptions.projectId = projectID + if (projectID) authOptions.projectId = projectID + } const temperature = nodeData.inputs?.temperature as string const modelName = nodeData.inputs?.modelName as string @@ -100,9 +110,9 @@ class GoogleVertexAI_ChatModels implements INode { const obj: Partial = { temperature: parseFloat(temperature), - model: modelName, - authOptions + model: modelName } + if (authOptions) obj.authOptions = authOptions if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) From 32b0e1584d4ae47e5b76559c4400c790f3dd0a3a Mon Sep 17 00:00:00 2001 From: Yongtae Date: Thu, 24 Aug 2023 12:33:45 +0900 Subject: [PATCH 06/13] refactoring_chatmodel --- .../ChatGoogleVertexAI/ChatGoogleVertexAI.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts index b7786e7c..c958de5f 100644 --- a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts @@ -20,9 +20,9 @@ class GoogleVertexAI_ChatModels implements INode { this.name = 'chatGoogleVertexAI' this.version = 1.0 this.type = 'ChatGoogleVertexAI' - this.icon = 'vertexa1i.svg' + this.icon = 'vertexai.svg' this.category = 'Chat Models' - this.description = 'wassyoi' + this.description = 'Wrapper around VertexAI large language models that use the Chat endpoint' this.baseClasses = [this.type, ...getBaseClasses(ChatGoogleVertexAI)] this.credential = { label: 'Connect Credential', @@ -37,7 +37,7 @@ class GoogleVertexAI_ChatModels implements INode { type: 'options', options: [ { - label: 'chat-bison11111', + label: 'chat-bison', name: 'chat-bison' }, { @@ -45,7 +45,7 @@ class GoogleVertexAI_ChatModels implements INode { name: 'codechat-bison' } ], - default: 'chat-bison11111', + default: 'chat-bison', optional: true }, { @@ -82,8 +82,8 @@ class GoogleVertexAI_ChatModels implements INode { const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) - // if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) - // throw new Error('Please specify your Google Application Credential') + if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error('Please specify your Google Application Credential') const inputs = [googleApplicationCredentialFilePath, googleApplicationCredential, skipExtraCredentialFile] From eddf742c73e3a16e59c1c1b64767f554acbd83f6 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Fri, 25 Aug 2023 00:35:47 +0900 Subject: [PATCH 07/13] Revert "add Skip Extra Credential File on credentials" This reverts commit fbf087848a7cb63c25c1601414974177dfcefe82. --- packages/components/credentials/GoogleAuth.credential.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts index bd9decd0..16b8e3b3 100644 --- a/packages/components/credentials/GoogleAuth.credential.ts +++ b/packages/components/credentials/GoogleAuth.credential.ts @@ -11,13 +11,6 @@ class GoogleVertexAuth implements INodeCredential { this.name = 'googleVertexAuth' this.version = 1.0 this.inputs = [ - { - label: 'Skip Extra Credential File', - name: 'skipExtraCredentialFile', - description: 'Enable this if you are using GCP and do not need to register an extra credential file', - type: 'boolean', - optional: true - }, { label: 'Google Application Credential File Path', name: 'googleApplicationCredentialFilePath', @@ -42,13 +35,11 @@ class GoogleVertexAuth implements INodeCredential { "token_uri": ..., "auth_provider_x509_cert_url": ..., "client_x509_cert_url": ... - }`, type: 'string', rows: 4, optional: true }, - { label: 'Project ID', name: 'projectID', From 495919a1d8a35f2561d333f80cf8e7007ae2085f Mon Sep 17 00:00:00 2001 From: Yongtae Date: Fri, 25 Aug 2023 00:40:25 +0900 Subject: [PATCH 08/13] Revert "implementation of embedding model" This reverts commit 0830b8fbe573e3c0ac6429831cf56c338dc46ea7. --- .../components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts index cb8ae61c..22133535 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts @@ -80,11 +80,11 @@ class GoogleVertexAI_LLMs implements INode { async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) - const skipExtraCredentialFile = getCredentialParam('skipExtraCredentialFile', credentialData, nodeData) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) + if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) throw new Error('Please specify your Google Application Credential') const inputs = [googleApplicationCredentialFilePath, googleApplicationCredential, skipExtraCredentialFile] @@ -115,8 +115,6 @@ class GoogleVertexAI_LLMs implements INode { model: modelName } - if (authOptions) obj.authOptions = authOptions - if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) From 9dff0646ce3768232f39ce24eb679e258e147135 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Fri, 25 Aug 2023 16:47:44 +0900 Subject: [PATCH 09/13] adopt optional credential on LLM --- .../llms/GoogleVertexAI/GoogleVertexAI.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts index 22133535..b379ad47 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts @@ -28,7 +28,10 @@ class GoogleVertexAI_LLMs implements INode { label: 'Connect Credential', name: 'credential', type: 'credential', - credentialNames: ['googleVertexAuth'] + credentialNames: ['googleVertexAuth'], + optional: true, + description: + 'Google Vertex AI credential. If you are using a GCP service like Cloud Run, or if you have installed default credentials on your local machine, you do not need to set this credential.' } this.inputs = [ { @@ -84,19 +87,15 @@ class GoogleVertexAI_LLMs implements INode { const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) - - if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) - throw new Error('Please specify your Google Application Credential') - const inputs = [googleApplicationCredentialFilePath, googleApplicationCredential, skipExtraCredentialFile] - - if (inputs.filter(Boolean).length > 1) { - throw new Error( - 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.' - ) - } - const authOptions: GoogleAuthOptions = {} - if (!skipExtraCredentialFile) { + if (Object.keys(credentialData).length !== 0) { + if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error('Please specify your Google Application Credential') + if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error( + 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path or Google Credential JSON Object' + ) + if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath else if (!googleApplicationCredentialFilePath && googleApplicationCredential) @@ -114,6 +113,7 @@ class GoogleVertexAI_LLMs implements INode { temperature: parseFloat(temperature), model: modelName } + if (Object.keys(authOptions).length !== 0) obj.authOptions = authOptions if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) From ed8d9bf050b636c3bf01cdb199178168df563584 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Fri, 25 Aug 2023 17:05:47 +0900 Subject: [PATCH 10/13] optional credential on chatmodel --- .../ChatGoogleVertexAI/ChatGoogleVertexAI.ts | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts index c958de5f..93081b55 100644 --- a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts @@ -77,24 +77,20 @@ class GoogleVertexAI_ChatModels implements INode { async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) - const skipExtraCredentialFile = getCredentialParam('skipExtraCredentialFile', credentialData, nodeData) const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) - if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) - throw new Error('Please specify your Google Application Credential') - - const inputs = [googleApplicationCredentialFilePath, googleApplicationCredential, skipExtraCredentialFile] - - if (inputs.filter(Boolean).length > 1) { - throw new Error( - 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.' - ) - } - const authOptions: GoogleAuthOptions = {} - if (!skipExtraCredentialFile) { + console.log('credentialData', credentialData) + if (Object.keys(credentialData).length !== 0) { + if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error('Please specify your Google Application Credential') + if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error( + 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path or Google Credential JSON Object' + ) + if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath else if (!googleApplicationCredentialFilePath && googleApplicationCredential) @@ -112,7 +108,7 @@ class GoogleVertexAI_ChatModels implements INode { temperature: parseFloat(temperature), model: modelName } - if (authOptions) obj.authOptions = authOptions + if (Object.keys(authOptions).length !== 0) obj.authOptions = authOptions if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) if (topP) obj.topP = parseFloat(topP) From f929a57c71ed5201425c3d6cf1105e4258d492be Mon Sep 17 00:00:00 2001 From: Yongtae Date: Fri, 25 Aug 2023 17:05:58 +0900 Subject: [PATCH 11/13] optional credential on Embedding --- .../GoogleVertexAIEmbedding.ts | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index a443e9f0..fdf7ea97 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -28,7 +28,10 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { label: 'Connect Credential', name: 'credential', type: 'credential', - credentialNames: ['googleVertexAuth'] + credentialNames: ['googleVertexAuth'], + optional: true, + description: + 'Google Vertex AI credential. If you are using a GCP service like Cloud Run, or if you have installed default credentials on your local machine, you do not need to set this credential.' } this.inputs = [] } @@ -38,21 +41,16 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) - const skipExtraCredentialFile = getCredentialParam('skipExtraCredentialFile', credentialData, nodeData) - - if (!skipExtraCredentialFile && !googleApplicationCredentialFilePath && !googleApplicationCredential) - throw new Error('Please specify your Google Application Credential') - - const inputs = [googleApplicationCredentialFilePath, googleApplicationCredential, skipExtraCredentialFile] - - if (inputs.filter(Boolean).length > 1) { - throw new Error( - 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path, Google Credential JSON Object, or Skip Extra Credential File.' - ) - } const authOptions: GoogleAuthOptions = {} - if (!skipExtraCredentialFile) { + if (Object.keys(credentialData).length !== 0) { + if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error('Please specify your Google Application Credential') + if (!googleApplicationCredentialFilePath && !googleApplicationCredential) + throw new Error( + 'Error: More than one component has been inputted. Please use only one of the following: Google Application Credential File Path or Google Credential JSON Object' + ) + if (googleApplicationCredentialFilePath && !googleApplicationCredential) authOptions.keyFile = googleApplicationCredentialFilePath else if (!googleApplicationCredentialFilePath && googleApplicationCredential) @@ -60,9 +58,8 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { if (projectID) authOptions.projectId = projectID } - const obj: GoogleVertexAIEmbeddingsParams = {} - if (authOptions) obj.authOptions = authOptions + if (Object.keys(authOptions).length !== 0) obj.authOptions = authOptions const model = new GoogleVertexAIEmbeddings(obj) return model From 97a05ed3c41add938125938dd64edb9aa44dd038 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Fri, 25 Aug 2023 17:22:36 +0900 Subject: [PATCH 12/13] Remove unnecessary console.log statement and add error handling for missing Google Application Credential --- .../nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts index 93081b55..559270b4 100644 --- a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts @@ -82,7 +82,6 @@ class GoogleVertexAI_ChatModels implements INode { const projectID = getCredentialParam('projectID', credentialData, nodeData) const authOptions: GoogleAuthOptions = {} - console.log('credentialData', credentialData) if (Object.keys(credentialData).length !== 0) { if (!googleApplicationCredentialFilePath && !googleApplicationCredential) throw new Error('Please specify your Google Application Credential') From ecf71c8db7a61287cf8edef69a5b01d62bb4ab41 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Fri, 25 Aug 2023 17:24:03 +0900 Subject: [PATCH 13/13] Add optional Google Vertex AI credential input with description --- .../chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts index 559270b4..a7ac4259 100644 --- a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts @@ -28,7 +28,10 @@ class GoogleVertexAI_ChatModels implements INode { label: 'Connect Credential', name: 'credential', type: 'credential', - credentialNames: ['googleVertexAuth'] + credentialNames: ['googleVertexAuth'], + optional: true, + description: + 'Google Vertex AI credential. If you are using a GCP service like Cloud Run, or if you have installed default credentials on your local machine, you do not need to set this credential.' } this.inputs = [ {