diff --git a/packages/components/credentials/JinaApi.credential.ts b/packages/components/credentials/JinaApi.credential.ts new file mode 100644 index 00000000000..4041c7befbd --- /dev/null +++ b/packages/components/credentials/JinaApi.credential.ts @@ -0,0 +1,25 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class JinaAICredential implements INodeCredential { + label: string + name: string + version: number + description: string + inputs: INodeParams[] + + constructor() { + this.label = 'JinaAI API' + this.name = 'jinaAIApi' + this.version = 1.0 + this.description = 'You can get your API key from official console here.' + this.inputs = [ + { + label: 'JinaAI API Key', + name: 'jinaAIAPIKey', + type: 'password' + } + ] + } +} + +module.exports = { credClass: JinaAICredential } diff --git a/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.svg b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.svg new file mode 100644 index 00000000000..95b99d8b5e5 --- /dev/null +++ b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts new file mode 100644 index 00000000000..a85c4f88f33 --- /dev/null +++ b/packages/components/nodes/embeddings/JinaAIEmbedding/JinaAIEmbedding.ts @@ -0,0 +1,58 @@ +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { JinaEmbeddings, JinaEmbeddingsParams } from '@langchain/community/embeddings/jina' + +class JinaAIEmbedding_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 = 'Jina Embeddings' + this.name = 'jinaEmbeddings' + this.version = 1.0 + this.type = 'JinaEmbeddings' + this.icon = 'JinaAIEmbedding.svg' + this.category = 'Embeddings' + this.description = 'JinaAI API to generate embeddings for a given text' + this.baseClasses = [this.type, ...getBaseClasses(JinaEmbeddings)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['jinaAIApi'] + } + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'string', + default: 'jina-embeddings-v2-base-en', + description: 'Refer to JinaAI documentation for available models' + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const apiKey = getCredentialParam('jinaAIAPIKey', credentialData, nodeData) + + const obj: JinaEmbeddingsParams = { + apiKey: apiKey, + model: modelName + } + + const model = new JinaEmbeddings(obj) + return model + } +} + +module.exports = { nodeClass: JinaAIEmbedding_Embeddings }