mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Chore/Add base options to azure chat openai (#3886)
* add base options to azure chat openai * add base options to embeddings
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { AzureOpenAIInput, ChatOpenAI as LangchainChatOpenAI, OpenAIChatInput } from '@langchain/openai'
|
||||
import { AzureOpenAIInput, ChatOpenAI as LangchainChatOpenAI, OpenAIChatInput, ClientOptions, LegacyOpenAIInput } from '@langchain/openai'
|
||||
import { BaseCache } from '@langchain/core/caches'
|
||||
import { BaseLLMParams } from '@langchain/core/language_models/llms'
|
||||
import { ICommonObject, IMultiModalOption, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface'
|
||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { ChatOpenAI } from '../ChatOpenAI/FlowiseChatOpenAI'
|
||||
import { getModels, MODEL_TYPE } from '../../../src/modelLoader'
|
||||
import { BaseChatModelParams } from '@langchain/core/language_models/chat_models'
|
||||
|
||||
const serverCredentialsExists =
|
||||
!!process.env.AZURE_OPENAI_API_KEY &&
|
||||
@@ -27,7 +28,7 @@ class AzureChatOpenAI_ChatModels implements INode {
|
||||
constructor() {
|
||||
this.label = 'Azure ChatOpenAI'
|
||||
this.name = 'azureChatOpenAI'
|
||||
this.version = 6.0
|
||||
this.version = 7.0
|
||||
this.type = 'AzureChatOpenAI'
|
||||
this.icon = 'Azure.svg'
|
||||
this.category = 'Chat Models'
|
||||
@@ -116,6 +117,13 @@ class AzureChatOpenAI_ChatModels implements INode {
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'BaseOptions',
|
||||
name: 'baseOptions',
|
||||
type: 'json',
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Allow Image Uploads',
|
||||
name: 'allowImageUploads',
|
||||
@@ -169,6 +177,7 @@ class AzureChatOpenAI_ChatModels implements INode {
|
||||
const cache = nodeData.inputs?.cache as BaseCache
|
||||
const topP = nodeData.inputs?.topP as string
|
||||
const basePath = nodeData.inputs?.basepath as string
|
||||
const baseOptions = nodeData.inputs?.baseOptions
|
||||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const azureOpenAIApiKey = getCredentialParam('azureOpenAIApiKey', credentialData, nodeData)
|
||||
@@ -179,7 +188,10 @@ class AzureChatOpenAI_ChatModels implements INode {
|
||||
const allowImageUploads = nodeData.inputs?.allowImageUploads as boolean
|
||||
const imageResolution = nodeData.inputs?.imageResolution as string
|
||||
|
||||
const obj: Partial<AzureOpenAIInput> & BaseLLMParams & Partial<OpenAIChatInput> = {
|
||||
const obj: Partial<AzureOpenAIInput> &
|
||||
BaseLLMParams &
|
||||
Partial<OpenAIChatInput> &
|
||||
BaseChatModelParams & { configuration?: ClientOptions & LegacyOpenAIInput } = {
|
||||
temperature: parseFloat(temperature),
|
||||
modelName,
|
||||
azureOpenAIApiKey,
|
||||
@@ -196,6 +208,16 @@ class AzureChatOpenAI_ChatModels implements INode {
|
||||
if (cache) obj.cache = cache
|
||||
if (topP) obj.topP = parseFloat(topP)
|
||||
if (basePath) obj.azureOpenAIBasePath = basePath
|
||||
if (baseOptions) {
|
||||
try {
|
||||
const parsedBaseOptions = typeof baseOptions === 'object' ? baseOptions : JSON.parse(baseOptions)
|
||||
obj.configuration = {
|
||||
defaultHeaders: parsedBaseOptions
|
||||
}
|
||||
} catch (exception) {
|
||||
console.error('Error parsing base options', exception)
|
||||
}
|
||||
}
|
||||
|
||||
const multiModalOption: IMultiModalOption = {
|
||||
image: {
|
||||
|
||||
Reference in New Issue
Block a user