mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 20:37:48 +00:00
fix:variable not update in nested workflow runs (#2830)
This commit is contained in:
@@ -25,7 +25,8 @@ export enum DispatchNodeResponseKeyEnum {
|
||||
rewriteHistories = 'rewriteHistories', // If have the response, workflow histories will be rewrite
|
||||
|
||||
interactive = 'INTERACTIVE', // is interactive
|
||||
runTimes = 'runTimes' // run times
|
||||
runTimes = 'runTimes', // run times
|
||||
newVariables = 'newVariables' // new variables
|
||||
}
|
||||
|
||||
export const needReplaceReferenceInputTypeList = [
|
||||
|
@@ -196,6 +196,7 @@ export type DispatchNodeResultType<T = {}> = {
|
||||
[DispatchNodeResponseKeyEnum.assistantResponses]?: AIChatItemValueItemType[]; // Assistant response(Store to db)
|
||||
[DispatchNodeResponseKeyEnum.rewriteHistories]?: ChatItemType[];
|
||||
[DispatchNodeResponseKeyEnum.runTimes]?: number;
|
||||
[DispatchNodeResponseKeyEnum.newVariables]?: Record<string, any>;
|
||||
} & T;
|
||||
|
||||
/* Single node props */
|
||||
|
@@ -184,6 +184,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
|
||||
|
||||
// flat child tool response
|
||||
const childToolResponse = dispatchFlowResponse.map((item) => item.flowResponses).flat();
|
||||
const newVariables = dispatchFlowResponse[dispatchFlowResponse.length - 1]?.newVariables;
|
||||
|
||||
// concat tool usage
|
||||
const totalPointsUsage =
|
||||
@@ -219,6 +220,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
|
||||
tokens: totalTokens
|
||||
},
|
||||
...flatUsages
|
||||
]
|
||||
],
|
||||
[DispatchNodeResponseKeyEnum.newVariables]: newVariables
|
||||
};
|
||||
};
|
||||
|
@@ -555,6 +555,14 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
|
||||
dispatchRes[item.key] = valueTypeFormat(item.defaultValue, item.valueType);
|
||||
});
|
||||
|
||||
// Update new variables
|
||||
if (dispatchRes[DispatchNodeResponseKeyEnum.newVariables]) {
|
||||
variables = {
|
||||
...variables,
|
||||
...dispatchRes[DispatchNodeResponseKeyEnum.newVariables]
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
node,
|
||||
runStatus: 'run',
|
||||
|
@@ -38,6 +38,7 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
|
||||
const loopDetail: ChatHistoryItemResType[] = [];
|
||||
let assistantResponses: AIChatItemValueItemType[] = [];
|
||||
let totalPoints = 0;
|
||||
let newVariables: Record<string, any> = {};
|
||||
|
||||
for await (const item of loopInputArray) {
|
||||
const response = await dispatchWorkFlow({
|
||||
@@ -72,6 +73,10 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
|
||||
assistantResponses.push(...response.assistantResponses);
|
||||
|
||||
totalPoints = response.flowUsages.reduce((acc, usage) => acc + usage.totalPoints, 0);
|
||||
newVariables = {
|
||||
...newVariables,
|
||||
...response.newVariables
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -88,6 +93,7 @@ export const dispatchLoop = async (props: Props): Promise<Response> => {
|
||||
moduleName: name
|
||||
}
|
||||
],
|
||||
[NodeOutputKeyEnum.loopArray]: outputValueArr
|
||||
[NodeOutputKeyEnum.loopArray]: outputValueArr,
|
||||
[DispatchNodeResponseKeyEnum.newVariables]: newVariables
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user