mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 01:01:11 +03:00
Bugfix/Override config vars (#3524)
update bugfix for override config vars
This commit is contained in:
@@ -529,7 +529,8 @@ const compileMultiAgentsGraph = async (params: MultiAgentsGraphParams) => {
|
|||||||
const newNodeInstance = new nodeModule.nodeClass()
|
const newNodeInstance = new nodeModule.nodeClass()
|
||||||
|
|
||||||
let flowNodeData = cloneDeep(workerNode.data)
|
let flowNodeData = cloneDeep(workerNode.data)
|
||||||
if (overrideConfig && apiOverrideStatus) flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides)
|
if (overrideConfig && apiOverrideStatus)
|
||||||
|
flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides, variableOverrides)
|
||||||
flowNodeData = await resolveVariables(
|
flowNodeData = await resolveVariables(
|
||||||
appServer.AppDataSource,
|
appServer.AppDataSource,
|
||||||
flowNodeData,
|
flowNodeData,
|
||||||
@@ -569,7 +570,8 @@ const compileMultiAgentsGraph = async (params: MultiAgentsGraphParams) => {
|
|||||||
|
|
||||||
let flowNodeData = cloneDeep(supervisorNode.data)
|
let flowNodeData = cloneDeep(supervisorNode.data)
|
||||||
|
|
||||||
if (overrideConfig && apiOverrideStatus) flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides)
|
if (overrideConfig && apiOverrideStatus)
|
||||||
|
flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides, variableOverrides)
|
||||||
flowNodeData = await resolveVariables(
|
flowNodeData = await resolveVariables(
|
||||||
appServer.AppDataSource,
|
appServer.AppDataSource,
|
||||||
flowNodeData,
|
flowNodeData,
|
||||||
@@ -758,7 +760,8 @@ const compileSeqAgentsGraph = async (params: SeqAgentsGraphParams) => {
|
|||||||
const newNodeInstance = new nodeModule.nodeClass()
|
const newNodeInstance = new nodeModule.nodeClass()
|
||||||
|
|
||||||
flowNodeData = cloneDeep(node.data)
|
flowNodeData = cloneDeep(node.data)
|
||||||
if (overrideConfig && apiOverrideStatus) flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides)
|
if (overrideConfig && apiOverrideStatus)
|
||||||
|
flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides, variableOverrides)
|
||||||
flowNodeData = await resolveVariables(
|
flowNodeData = await resolveVariables(
|
||||||
appServer.AppDataSource,
|
appServer.AppDataSource,
|
||||||
flowNodeData,
|
flowNodeData,
|
||||||
|
|||||||
@@ -388,7 +388,12 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
|
|||||||
|
|
||||||
// Only override the config if its status is true
|
// Only override the config if its status is true
|
||||||
if (incomingInput.overrideConfig && apiOverrideStatus) {
|
if (incomingInput.overrideConfig && apiOverrideStatus) {
|
||||||
nodeToExecute.data = replaceInputsWithConfig(nodeToExecute.data, incomingInput.overrideConfig, nodeOverrides)
|
nodeToExecute.data = replaceInputsWithConfig(
|
||||||
|
nodeToExecute.data,
|
||||||
|
incomingInput.overrideConfig,
|
||||||
|
nodeOverrides,
|
||||||
|
variableOverrides
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const flowData: ICommonObject = {
|
const flowData: ICommonObject = {
|
||||||
|
|||||||
@@ -519,7 +519,7 @@ export const buildFlow = async ({
|
|||||||
|
|
||||||
// Only override the config if its status is true
|
// Only override the config if its status is true
|
||||||
if (overrideConfig && apiOverrideStatus) {
|
if (overrideConfig && apiOverrideStatus) {
|
||||||
flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides)
|
flowNodeData = replaceInputsWithConfig(flowNodeData, overrideConfig, nodeOverrides, variableOverrides)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isUpsert) upsertHistory['flowData'] = saveUpsertFlowData(flowNodeData, upsertHistory)
|
if (isUpsert) upsertHistory['flowData'] = saveUpsertFlowData(flowNodeData, upsertHistory)
|
||||||
@@ -1001,9 +1001,15 @@ export const resolveVariables = async (
|
|||||||
* @param {INodeData} flowNodeData
|
* @param {INodeData} flowNodeData
|
||||||
* @param {ICommonObject} overrideConfig
|
* @param {ICommonObject} overrideConfig
|
||||||
* @param {ICommonObject} nodeOverrides
|
* @param {ICommonObject} nodeOverrides
|
||||||
|
* @param {ICommonObject[]} variableOverrides
|
||||||
* @returns {INodeData}
|
* @returns {INodeData}
|
||||||
*/
|
*/
|
||||||
export const replaceInputsWithConfig = (flowNodeData: INodeData, overrideConfig: ICommonObject, nodeOverrides: ICommonObject) => {
|
export const replaceInputsWithConfig = (
|
||||||
|
flowNodeData: INodeData,
|
||||||
|
overrideConfig: ICommonObject,
|
||||||
|
nodeOverrides: ICommonObject,
|
||||||
|
variableOverrides: ICommonObject[]
|
||||||
|
) => {
|
||||||
const types = 'inputs'
|
const types = 'inputs'
|
||||||
|
|
||||||
const isParameterEnabled = (nodeType: string, paramName: string): boolean => {
|
const isParameterEnabled = (nodeType: string, paramName: string): boolean => {
|
||||||
@@ -1014,28 +1020,54 @@ export const replaceInputsWithConfig = (flowNodeData: INodeData, overrideConfig:
|
|||||||
|
|
||||||
const getParamValues = (inputsObj: ICommonObject) => {
|
const getParamValues = (inputsObj: ICommonObject) => {
|
||||||
for (const config in overrideConfig) {
|
for (const config in overrideConfig) {
|
||||||
// Always allow analytics config: https://docs.flowiseai.com/using-flowise/analytic#api
|
/**
|
||||||
if (config !== 'analytics') {
|
* Several conditions:
|
||||||
// If overrideConfig[key] is object
|
* 1. If config is 'analytics', always allow it
|
||||||
if (overrideConfig[config] && typeof overrideConfig[config] === 'object') {
|
* 2. If config is 'vars', check its object and filter out the variables that are not enabled for override
|
||||||
const nodeIds = Object.keys(overrideConfig[config])
|
* 3. If typeof config is an object, check if the node id is in the overrideConfig object and if the parameter (systemMessagePrompt) is enabled
|
||||||
if (nodeIds.includes(flowNodeData.id)) {
|
* Example:
|
||||||
// Check if this parameter is enabled for this node type
|
* "systemMessagePrompt": {
|
||||||
if (isParameterEnabled(flowNodeData.label, config)) {
|
* "chatPromptTemplate_0": "You are an assistant"
|
||||||
inputsObj[config] = overrideConfig[config][flowNodeData.id]
|
* }
|
||||||
}
|
* 4. If typeof config is a string, check if the parameter is enabled
|
||||||
continue
|
* Example:
|
||||||
} else if (nodeIds.some((nodeId) => nodeId.includes(flowNodeData.name))) {
|
* "systemMessagePrompt": "You are an assistant"
|
||||||
/*
|
*/
|
||||||
* "systemMessagePrompt": {
|
|
||||||
* "chatPromptTemplate_0": "You are an assistant" <---- continue for loop if current node is chatPromptTemplate_1
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only proceed if the parameter is enabled for this node type
|
if (config === 'analytics') {
|
||||||
|
// pass
|
||||||
|
} else if (config === 'vars') {
|
||||||
|
if (typeof overrideConfig[config] === 'object') {
|
||||||
|
const filteredVars: ICommonObject = {}
|
||||||
|
|
||||||
|
const vars = overrideConfig[config]
|
||||||
|
for (const variable in vars) {
|
||||||
|
const override = variableOverrides.find((v) => v.name === variable)
|
||||||
|
if (!override?.enabled) {
|
||||||
|
continue // Skip this variable if it's not enabled for override
|
||||||
|
}
|
||||||
|
filteredVars[variable] = vars[variable]
|
||||||
|
}
|
||||||
|
overrideConfig[config] = filteredVars
|
||||||
|
}
|
||||||
|
} else if (overrideConfig[config] && typeof overrideConfig[config] === 'object') {
|
||||||
|
const nodeIds = Object.keys(overrideConfig[config])
|
||||||
|
if (nodeIds.includes(flowNodeData.id)) {
|
||||||
|
// Check if this parameter is enabled
|
||||||
|
if (isParameterEnabled(flowNodeData.label, config)) {
|
||||||
|
inputsObj[config] = overrideConfig[config][flowNodeData.id]
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
} else if (nodeIds.some((nodeId) => nodeId.includes(flowNodeData.name))) {
|
||||||
|
/*
|
||||||
|
* "systemMessagePrompt": {
|
||||||
|
* "chatPromptTemplate_0": "You are an assistant" <---- continue for loop if current node is chatPromptTemplate_1
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Only proceed if the parameter is enabled
|
||||||
if (!isParameterEnabled(flowNodeData.label, config)) {
|
if (!isParameterEnabled(flowNodeData.label, config)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user