mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 01:00:46 +03:00
827de07e94
* ChatOpenAI LlamaIndex support BasePath Param * Add BasePath parameter setting support to ChatOpenAI LlamaIndex * Add BasePath parameter setting support to ChatOpenAI LlamaIndex
97 lines
3.2 KiB
TypeScript
97 lines
3.2 KiB
TypeScript
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
|
import { OpenAIEmbedding } from 'llamaindex'
|
|
|
|
class OpenAIEmbedding_LlamaIndex_Embeddings implements INode {
|
|
label: string
|
|
name: string
|
|
version: number
|
|
type: string
|
|
icon: string
|
|
category: string
|
|
description: string
|
|
baseClasses: string[]
|
|
tags: string[]
|
|
credential: INodeParams
|
|
inputs: INodeParams[]
|
|
|
|
constructor() {
|
|
this.label = 'OpenAI Embedding'
|
|
this.name = 'openAIEmbedding_LlamaIndex'
|
|
this.version = 1.0
|
|
this.type = 'OpenAIEmbedding'
|
|
this.icon = 'openai.svg'
|
|
this.category = 'Embeddings'
|
|
this.description = 'OpenAI Embedding specific for LlamaIndex'
|
|
this.baseClasses = [this.type, 'BaseEmbedding_LlamaIndex', ...getBaseClasses(OpenAIEmbedding)]
|
|
this.tags = ['LlamaIndex']
|
|
this.credential = {
|
|
label: 'Connect Credential',
|
|
name: 'credential',
|
|
type: 'credential',
|
|
credentialNames: ['openAIApi']
|
|
}
|
|
this.inputs = [
|
|
{
|
|
label: 'Model Name',
|
|
name: 'modelName',
|
|
type: 'options',
|
|
options: [
|
|
{
|
|
label: 'text-embedding-3-large',
|
|
name: 'text-embedding-3-large'
|
|
},
|
|
{
|
|
label: 'text-embedding-3-small',
|
|
name: 'text-embedding-3-small'
|
|
},
|
|
{
|
|
label: 'text-embedding-ada-002',
|
|
name: 'text-embedding-ada-002'
|
|
}
|
|
],
|
|
default: 'text-embedding-ada-002',
|
|
optional: true
|
|
},
|
|
{
|
|
label: 'Timeout',
|
|
name: 'timeout',
|
|
type: 'number',
|
|
optional: true,
|
|
additionalParams: true
|
|
},
|
|
{
|
|
label: 'BasePath',
|
|
name: 'basepath',
|
|
type: 'string',
|
|
optional: true,
|
|
additionalParams: true
|
|
}
|
|
]
|
|
}
|
|
|
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
|
const timeout = nodeData.inputs?.timeout as string
|
|
const modelName = nodeData.inputs?.modelName as string
|
|
const basePath = nodeData.inputs?.basepath as string
|
|
|
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
|
const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData)
|
|
|
|
const obj: Partial<OpenAIEmbedding> = {
|
|
apiKey: openAIApiKey,
|
|
model: modelName
|
|
}
|
|
if (timeout) obj.timeout = parseInt(timeout, 10)
|
|
if (basePath) {
|
|
obj.additionalSessionOptions = {
|
|
baseURL: basePath
|
|
}
|
|
}
|
|
const model = new OpenAIEmbedding(obj)
|
|
return model
|
|
}
|
|
}
|
|
|
|
module.exports = { nodeClass: OpenAIEmbedding_LlamaIndex_Embeddings }
|