Skip to content

Commit c222308

Browse files
committed
support multiple suggestions in next node prediction
1 parent 6f94ed0 commit c222308

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/assistant.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const { getLongestUpstreamPath } = require('./flowGraph')
66
const { hasProperty } = require('./utils')
77
const semver = require('semver')
88

9-
const PREDICTION_SEQUENCE_LENGTH = 5 // The length of the input sequence for the TensorFlow model
109
const FF_ASSISTANT_USER_AGENT = 'FlowFuse Assistant Plugin/' + require('../package.json').version
1110

1211
/**
@@ -334,16 +333,16 @@ class Assistant {
334333
},
335334
/** @type {import('@modelcontextprotocol/sdk/server/mcp.js').ToolCallback} */
336335
async ({ flow, sourceNode, sourcePort }) => {
337-
sourceNode = sourceNode || {}
336+
const attachToNode = sourceNode || {}
338337
/** @type {Array<{type: string}>} */
339338
let suggestedNodes = []
340339
/** @type {Array<{type: string}>} */
341340
const upstreamNodes = []
342-
if (flow && flow.length && sourceNode.id) {
343-
upstreamNodes.push(...getLongestUpstreamPath(flow, sourceNode.id))
341+
if (flow && flow.length && attachToNode.id) {
342+
upstreamNodes.push(...getLongestUpstreamPath(flow, attachToNode.id))
344343
}
345344
if (this.completionsReady) {
346-
const allNodes = [...upstreamNodes, sourceNode].slice(-PREDICTION_SEQUENCE_LENGTH) // Include the last node in the input
345+
const allNodes = [...upstreamNodes, attachToNode] // Include the last node in the input
347346
const typeNames = allNodes.map(node => node.type) // Extract the type names from the nodes
348347
const vectorizedText = this.labeller.encode_sequence(typeNames)
349348

@@ -352,7 +351,8 @@ class Assistant {
352351
}
353352

354353
const results = await this._completionsSession.run(feeds)
355-
const predictions = this.labeller.decode_predictions(results.probabilities.cpuData)
354+
// Get top 3 + 5 additional predictions (only 3 will be used since there are 5 permanent suggestions in the typeSearch, we need enough to fill the suggestions array)
355+
const predictions = this.labeller.decode_predictions(results.probabilities.cpuData, 3 + 5)
356356

357357
suggestedNodes = predictions.map(prediction => ({ type: prediction.className })) // Create new nodes with the predicted types
358358
}

0 commit comments

Comments
 (0)