mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-25 11:01:01 +03:00
02fe500f21
# Conflicts: # packages/components/nodes/cache/RedisCache/RedisCache.ts # packages/components/nodes/cache/RedisCache/RedisEmbeddingsCache.ts # packages/components/nodes/chains/ConversationChain/ConversationChain.ts # packages/components/nodes/tools/RetrieverTool/RetrieverTool.ts # packages/components/nodes/vectorstores/Qdrant/Qdrant.ts # packages/components/nodes/vectorstores/Redis/Redis.ts # packages/components/nodes/vectorstores/Redis/RedisSearchBase.ts # packages/components/nodes/vectorstores/Redis/Redis_Existing.ts # packages/components/nodes/vectorstores/Redis/Redis_Upsert.ts # packages/components/src/agents.ts
77 lines
2.8 KiB
TypeScript
77 lines
2.8 KiB
TypeScript
import { AzureOpenAIInput, OpenAIEmbeddings, OpenAIEmbeddingsParams } from '@langchain/openai'
|
|
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
|
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
|
|
|
class AzureOpenAIEmbedding_Embeddings implements INode {
|
|
label: string
|
|
name: string
|
|
version: number
|
|
type: string
|
|
icon: string
|
|
category: string
|
|
description: string
|
|
baseClasses: string[]
|
|
credential: INodeParams
|
|
inputs: INodeParams[]
|
|
|
|
constructor() {
|
|
this.label = 'Azure OpenAI Embeddings'
|
|
this.name = 'azureOpenAIEmbeddings'
|
|
this.version = 1.0
|
|
this.type = 'AzureOpenAIEmbeddings'
|
|
this.icon = 'Azure.svg'
|
|
this.category = 'Embeddings'
|
|
this.description = 'Azure OpenAI API to generate embeddings for a given text'
|
|
this.baseClasses = [this.type, ...getBaseClasses(OpenAIEmbeddings)]
|
|
this.credential = {
|
|
label: 'Connect Credential',
|
|
name: 'credential',
|
|
type: 'credential',
|
|
credentialNames: ['azureOpenAIApi']
|
|
}
|
|
this.inputs = [
|
|
{
|
|
label: 'Batch Size',
|
|
name: 'batchSize',
|
|
type: 'number',
|
|
default: '100',
|
|
optional: true,
|
|
additionalParams: true
|
|
},
|
|
{
|
|
label: 'Timeout',
|
|
name: 'timeout',
|
|
type: 'number',
|
|
optional: true,
|
|
additionalParams: true
|
|
}
|
|
]
|
|
}
|
|
|
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
|
const batchSize = nodeData.inputs?.batchSize as string
|
|
const timeout = nodeData.inputs?.timeout as string
|
|
|
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
|
const azureOpenAIApiKey = getCredentialParam('azureOpenAIApiKey', credentialData, nodeData)
|
|
const azureOpenAIApiInstanceName = getCredentialParam('azureOpenAIApiInstanceName', credentialData, nodeData)
|
|
const azureOpenAIApiDeploymentName = getCredentialParam('azureOpenAIApiDeploymentName', credentialData, nodeData)
|
|
const azureOpenAIApiVersion = getCredentialParam('azureOpenAIApiVersion', credentialData, nodeData)
|
|
|
|
const obj: Partial<OpenAIEmbeddingsParams> & Partial<AzureOpenAIInput> = {
|
|
azureOpenAIApiKey,
|
|
azureOpenAIApiInstanceName,
|
|
azureOpenAIApiDeploymentName,
|
|
azureOpenAIApiVersion
|
|
}
|
|
|
|
if (batchSize) obj.batchSize = parseInt(batchSize, 10)
|
|
if (timeout) obj.timeout = parseInt(timeout, 10)
|
|
|
|
const model = new OpenAIEmbeddings(obj)
|
|
return model
|
|
}
|
|
}
|
|
|
|
module.exports = { nodeClass: AzureOpenAIEmbedding_Embeddings }
|