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 { 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 & Partial = { 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 }