Skip to content

Commit

Permalink
Feature/add ability to show variable output (#3580)
Browse files Browse the repository at this point in the history
add ability to show variable output
  • Loading branch information
HenryHengZJ authored Nov 26, 2024
1 parent af5e6b0 commit 76ae921
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/components/nodes/utilities/SetVariable/SetVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SetVariable_Utilities implements INode {
constructor() {
this.label = 'Set Variable'
this.name = 'setVariable'
this.version = 2.0
this.version = 2.1
this.type = 'SetVariable'
this.icon = 'setvar.svg'
this.category = 'Utilities'
Expand All @@ -36,6 +36,14 @@ class SetVariable_Utilities implements INode {
name: 'variableName',
type: 'string',
placeholder: 'var1'
},
{
label: 'Show Output',
name: 'showOutput',
description: 'Show the output result in the Prediction API response',
type: 'boolean',
optional: true,
additionalParams: true
}
]
this.outputs = [
Expand Down
15 changes: 15 additions & 0 deletions packages/server/src/utils/buildChatflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
// Get prepend messages
const prependMessages = incomingInput.history

const flowVariables = {} as Record<string, unknown>

/* Reuse the flow without having to rebuild (to avoid duplicated upsert, recomputation, reinitialization of memory) when all these conditions met:
* - Reuse of flows is not disabled
* - Node Data already exists in pool
Expand Down Expand Up @@ -378,6 +380,18 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
baseURL
})

// Show output of setVariable nodes in the response
for (const node of reactFlowNodes) {
if (
node.data.name === 'setVariable' &&
(node.data.inputs?.showOutput === true || node.data.inputs?.showOutput === 'true')
) {
const outputResult = node.data.instance
const variableKey = node.data.inputs?.variableName
flowVariables[variableKey] = outputResult
}
}

const nodeToExecute =
endingNodeIds.length === 1
? reactFlowNodes.find((node: IReactFlowNode) => endingNodeIds[0] === node.id)
Expand Down Expand Up @@ -525,6 +539,7 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals

if (sessionId) result.sessionId = sessionId
if (memoryType) result.memoryType = memoryType
if (Object.keys(flowVariables).length) result.flowVariables = flowVariables

return result
} catch (e) {
Expand Down

0 comments on commit 76ae921

Please sign in to comment.