File size: 1,732 Bytes
4114d85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { HuggingFaceInferenceEmbeddings, HuggingFaceInferenceEmbeddingsParams } from 'langchain/embeddings/hf'
class HuggingFaceInferenceEmbedding_Embeddings implements INode {
label: string
name: string
type: string
icon: string
category: string
description: string
baseClasses: string[]
inputs: INodeParams[]
constructor() {
this.label = 'HuggingFace Inference Embeddings'
this.name = 'huggingFaceInferenceEmbeddings'
this.type = 'HuggingFaceInferenceEmbeddings'
this.icon = 'huggingface.png'
this.category = 'Embeddings'
this.description = 'HuggingFace Inference API to generate embeddings for a given text'
this.baseClasses = [this.type, ...getBaseClasses(HuggingFaceInferenceEmbeddings)]
this.inputs = [
{
label: 'HuggingFace Api Key',
name: 'apiKey',
type: 'password'
},
{
label: 'Model',
name: 'modelName',
type: 'string',
optional: true
}
]
}
async init(nodeData: INodeData): Promise<any> {
const apiKey = nodeData.inputs?.apiKey as string
const modelName = nodeData.inputs?.modelName as string
const obj: Partial<HuggingFaceInferenceEmbeddingsParams> = {
apiKey
}
if (modelName) obj.model = modelName
const model = new HuggingFaceInferenceEmbeddings(obj)
return model
}
}
module.exports = { nodeClass: HuggingFaceInferenceEmbedding_Embeddings }
|