File size: 1,611 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 { OpenAIEmbeddings, OpenAIEmbeddingsParams } from 'langchain/embeddings/openai'
class LocalAIEmbedding_Embeddings implements INode {
label: string
name: string
type: string
icon: string
category: string
description: string
baseClasses: string[]
inputs: INodeParams[]
constructor() {
this.label = 'LocalAI Embeddings'
this.name = 'localAIEmbeddings'
this.type = 'LocalAI Embeddings'
this.icon = 'localai.png'
this.category = 'Embeddings'
this.description = 'Use local embeddings models like llama.cpp'
this.baseClasses = [this.type, 'Embeddings']
this.inputs = [
{
label: 'Base Path',
name: 'basePath',
type: 'string',
placeholder: 'http://localhost:8080/v1'
},
{
label: 'Model Name',
name: 'modelName',
type: 'string',
placeholder: 'text-embedding-ada-002'
}
]
}
async init(nodeData: INodeData): Promise<any> {
const modelName = nodeData.inputs?.modelName as string
const basePath = nodeData.inputs?.basePath as string
const obj: Partial<OpenAIEmbeddingsParams> & { openAIApiKey?: string } = {
modelName,
openAIApiKey: 'sk-'
}
const model = new OpenAIEmbeddings(obj, { basePath })
return model
}
}
module.exports = { nodeClass: LocalAIEmbedding_Embeddings }
|