diff --git a/packages/components/credentials/GoogleAuth.credential.ts b/packages/components/credentials/GoogleAuth.credential.ts new file mode 100644 index 000000000..de4c88437 --- /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 c7079d053..1c491682c 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 cb8d757aa..afcfd3618 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",