Merge pull request #129 from FlowiseAI/feature/HuggingFaceInferenceEmbeddings

Feature/HuggingFaceInferenceEmbeddings
This commit is contained in:
Ong Chung Yau 2023-05-20 20:34:57 +07:00 committed by GitHub
commit c2f86377fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,53 @@
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 }

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

View File

@ -17,7 +17,7 @@
"license": "SEE LICENSE IN LICENSE.md",
"dependencies": {
"@dqbd/tiktoken": "^1.0.7",
"@huggingface/inference": "^1.6.3",
"@huggingface/inference": "1",
"@pinecone-database/pinecone": "^0.0.12",
"@supabase/supabase-js": "^2.21.0",
"axios": "^0.27.2",