Feature - Add option to start a new session with each interaction with the Chatflow tool (#2633)
* Feature - Add option to start a new session with each interaction with the Chatflow tool * ChatflowTool - Create random chatId when startNewSession is set
This commit is contained in:
parent
842bfc66fe
commit
d4f80394d3
|
|
@ -6,6 +6,7 @@ import { CallbackManagerForToolRun, Callbacks, CallbackManager, parseCallbackCon
|
||||||
import { StructuredTool } from '@langchain/core/tools'
|
import { StructuredTool } from '@langchain/core/tools'
|
||||||
import { ICommonObject, IDatabaseEntity, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface'
|
import { ICommonObject, IDatabaseEntity, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface'
|
||||||
import { availableDependencies, defaultAllowBuiltInDep, getCredentialData, getCredentialParam } from '../../../src/utils'
|
import { availableDependencies, defaultAllowBuiltInDep, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
|
import { v4 as uuidv4 } from 'uuid'
|
||||||
|
|
||||||
class ChatflowTool_Tools implements INode {
|
class ChatflowTool_Tools implements INode {
|
||||||
label: string
|
label: string
|
||||||
|
|
@ -22,7 +23,7 @@ class ChatflowTool_Tools implements INode {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.label = 'Chatflow Tool'
|
this.label = 'Chatflow Tool'
|
||||||
this.name = 'ChatflowTool'
|
this.name = 'ChatflowTool'
|
||||||
this.version = 2.0
|
this.version = 3.0
|
||||||
this.type = 'ChatflowTool'
|
this.type = 'ChatflowTool'
|
||||||
this.icon = 'chatflowTool.svg'
|
this.icon = 'chatflowTool.svg'
|
||||||
this.category = 'Tools'
|
this.category = 'Tools'
|
||||||
|
|
@ -66,6 +67,16 @@ class ChatflowTool_Tools implements INode {
|
||||||
optional: true,
|
optional: true,
|
||||||
additionalParams: true
|
additionalParams: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Start new session per message',
|
||||||
|
name: 'startNewSession',
|
||||||
|
type: 'boolean',
|
||||||
|
description:
|
||||||
|
'Whether to continue the session with the Chatflow tool or start a new one with each interaction. Useful for Chatflows with memory if you want to avoid it.',
|
||||||
|
default: false,
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Use Question from Chat',
|
label: 'Use Question from Chat',
|
||||||
name: 'useQuestionFromChat',
|
name: 'useQuestionFromChat',
|
||||||
|
|
@ -117,6 +128,8 @@ class ChatflowTool_Tools implements INode {
|
||||||
const useQuestionFromChat = nodeData.inputs?.useQuestionFromChat as boolean
|
const useQuestionFromChat = nodeData.inputs?.useQuestionFromChat as boolean
|
||||||
const customInput = nodeData.inputs?.customInput as string
|
const customInput = nodeData.inputs?.customInput as string
|
||||||
|
|
||||||
|
const startNewSession = nodeData.inputs?.startNewSession as boolean
|
||||||
|
|
||||||
const baseURL = (nodeData.inputs?.baseURL as string) || (options.baseURL as string)
|
const baseURL = (nodeData.inputs?.baseURL as string) || (options.baseURL as string)
|
||||||
|
|
||||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
|
@ -136,7 +149,7 @@ class ChatflowTool_Tools implements INode {
|
||||||
|
|
||||||
let name = _name || 'chatflow_tool'
|
let name = _name || 'chatflow_tool'
|
||||||
|
|
||||||
return new ChatflowTool({ name, baseURL, description, chatflowid: selectedChatflowId, headers, input: toolInput })
|
return new ChatflowTool({ name, baseURL, description, chatflowid: selectedChatflowId, startNewSession, headers, input: toolInput })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,6 +166,8 @@ class ChatflowTool extends StructuredTool {
|
||||||
|
|
||||||
chatflowid = ''
|
chatflowid = ''
|
||||||
|
|
||||||
|
startNewSession = false
|
||||||
|
|
||||||
baseURL = 'http://localhost:3000'
|
baseURL = 'http://localhost:3000'
|
||||||
|
|
||||||
headers = {}
|
headers = {}
|
||||||
|
|
@ -166,6 +181,7 @@ class ChatflowTool extends StructuredTool {
|
||||||
description,
|
description,
|
||||||
input,
|
input,
|
||||||
chatflowid,
|
chatflowid,
|
||||||
|
startNewSession,
|
||||||
baseURL,
|
baseURL,
|
||||||
headers
|
headers
|
||||||
}: {
|
}: {
|
||||||
|
|
@ -173,6 +189,7 @@ class ChatflowTool extends StructuredTool {
|
||||||
description: string
|
description: string
|
||||||
input: string
|
input: string
|
||||||
chatflowid: string
|
chatflowid: string
|
||||||
|
startNewSession: boolean
|
||||||
baseURL: string
|
baseURL: string
|
||||||
headers: ICommonObject
|
headers: ICommonObject
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -181,6 +198,7 @@ class ChatflowTool extends StructuredTool {
|
||||||
this.description = description
|
this.description = description
|
||||||
this.input = input
|
this.input = input
|
||||||
this.baseURL = baseURL
|
this.baseURL = baseURL
|
||||||
|
this.startNewSession = startNewSession
|
||||||
this.headers = headers
|
this.headers = headers
|
||||||
this.chatflowid = chatflowid
|
this.chatflowid = chatflowid
|
||||||
}
|
}
|
||||||
|
|
@ -240,9 +258,9 @@ class ChatflowTool extends StructuredTool {
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
question: inputQuestion,
|
question: inputQuestion,
|
||||||
chatId: flowConfig?.chatId,
|
chatId: this.startNewSession ? uuidv4() : flowConfig?.chatId,
|
||||||
overrideConfig: {
|
overrideConfig: {
|
||||||
sessionId: flowConfig?.sessionId
|
sessionId: this.startNewSession ? uuidv4() : flowConfig?.sessionId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue