Skip to content

Commit 76ae921

Browse files
authored
Feature/add ability to show variable output (#3580)
add ability to show variable output
1 parent af5e6b0 commit 76ae921

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

packages/components/nodes/utilities/SetVariable/SetVariable.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SetVariable_Utilities implements INode {
1616
constructor() {
1717
this.label = 'Set Variable'
1818
this.name = 'setVariable'
19-
this.version = 2.0
19+
this.version = 2.1
2020
this.type = 'SetVariable'
2121
this.icon = 'setvar.svg'
2222
this.category = 'Utilities'
@@ -36,6 +36,14 @@ class SetVariable_Utilities implements INode {
3636
name: 'variableName',
3737
type: 'string',
3838
placeholder: 'var1'
39+
},
40+
{
41+
label: 'Show Output',
42+
name: 'showOutput',
43+
description: 'Show the output result in the Prediction API response',
44+
type: 'boolean',
45+
optional: true,
46+
additionalParams: true
3947
}
4048
]
4149
this.outputs = [

packages/server/src/utils/buildChatflow.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
249249
// Get prepend messages
250250
const prependMessages = incomingInput.history
251251

252+
const flowVariables = {} as Record<string, unknown>
253+
252254
/* Reuse the flow without having to rebuild (to avoid duplicated upsert, recomputation, reinitialization of memory) when all these conditions met:
253255
* - Reuse of flows is not disabled
254256
* - Node Data already exists in pool
@@ -378,6 +380,18 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
378380
baseURL
379381
})
380382

383+
// Show output of setVariable nodes in the response
384+
for (const node of reactFlowNodes) {
385+
if (
386+
node.data.name === 'setVariable' &&
387+
(node.data.inputs?.showOutput === true || node.data.inputs?.showOutput === 'true')
388+
) {
389+
const outputResult = node.data.instance
390+
const variableKey = node.data.inputs?.variableName
391+
flowVariables[variableKey] = outputResult
392+
}
393+
}
394+
381395
const nodeToExecute =
382396
endingNodeIds.length === 1
383397
? reactFlowNodes.find((node: IReactFlowNode) => endingNodeIds[0] === node.id)
@@ -525,6 +539,7 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
525539

526540
if (sessionId) result.sessionId = sessionId
527541
if (memoryType) result.memoryType = memoryType
542+
if (Object.keys(flowVariables).length) result.flowVariables = flowVariables
528543

529544
return result
530545
} catch (e) {

0 commit comments

Comments
 (0)