add endpoint to HF

This commit is contained in:
Henry
2023-07-07 17:36:23 +01:00
parent 4dd43fb2c4
commit 0923a35683
8 changed files with 316 additions and 4 deletions
@@ -1,6 +1,6 @@
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { getBaseClasses } from '../../../src/utils'
import { HuggingFaceInferenceEmbeddings, HuggingFaceInferenceEmbeddingsParams } from 'langchain/embeddings/hf'
import { HuggingFaceInferenceEmbeddings, HuggingFaceInferenceEmbeddingsParams } from './core'
class HuggingFaceInferenceEmbedding_Embeddings implements INode {
label: string
@@ -31,6 +31,14 @@ class HuggingFaceInferenceEmbedding_Embeddings implements INode {
name: 'modelName',
type: 'string',
optional: true
},
{
label: 'Endpoint',
name: 'endpoint',
type: 'string',
placeholder: 'https://xyz.eu-west-1.aws.endpoints.huggingface.cloud/sentence-transformers/all-MiniLM-L6-v2',
description: 'Using your own inference endpoint',
optional: true
}
]
}
@@ -38,12 +46,14 @@ class HuggingFaceInferenceEmbedding_Embeddings implements INode {
async init(nodeData: INodeData): Promise<any> {
const apiKey = nodeData.inputs?.apiKey as string
const modelName = nodeData.inputs?.modelName as string
const endpoint = nodeData.inputs?.endpoint as string
const obj: Partial<HuggingFaceInferenceEmbeddingsParams> = {
apiKey
}
if (modelName) obj.model = modelName
if (endpoint) obj.endpoint = endpoint
const model = new HuggingFaceInferenceEmbeddings(obj)
return model