mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 09:01:09 +03:00
Bugfix/stream custom tool return direct (#3003)
stream custom tool return direct
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { flatten } from 'lodash'
|
||||
import { Tool } from '@langchain/core/tools'
|
||||
import { BaseMessage } from '@langchain/core/messages'
|
||||
import { ChainValues } from '@langchain/core/utils/types'
|
||||
import { RunnableSequence } from '@langchain/core/runnables'
|
||||
@@ -125,6 +126,17 @@ class ToolAgent_Agents implements INode {
|
||||
options.socketIO.to(options.socketIOClientId).emit('usedTools', res.usedTools)
|
||||
usedTools = res.usedTools
|
||||
}
|
||||
// If the tool is set to returnDirect, stream the output to the client
|
||||
if (res.usedTools && res.usedTools.length) {
|
||||
let inputTools = nodeData.inputs?.tools
|
||||
inputTools = flatten(inputTools)
|
||||
for (const tool of res.usedTools) {
|
||||
const inputTool = inputTools.find((inputTool: Tool) => inputTool.name === tool.tool)
|
||||
if (inputTool && inputTool.returnDirect) {
|
||||
options.socketIO.to(options.socketIOClientId).emit('token', tool.toolOutput)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = await executor.invoke({ input }, { callbacks: [loggerHandler, ...callbacks] })
|
||||
if (res.sourceDocuments) {
|
||||
|
||||
Reference in New Issue
Block a user