mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
fix memory nodes
This commit is contained in:
@@ -8,7 +8,7 @@ class RedisCacheApi implements INodeCredential {
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Redis Cache API'
|
||||
this.label = 'Redis API'
|
||||
this.name = 'redisCacheApi'
|
||||
this.version = 1.0
|
||||
this.inputs = [
|
||||
|
||||
@@ -8,7 +8,7 @@ class RedisCacheUrlApi implements INodeCredential {
|
||||
inputs: INodeParams[]
|
||||
|
||||
constructor() {
|
||||
this.label = 'Redis Cache URL'
|
||||
this.label = 'Redis URL'
|
||||
this.name = 'redisCacheUrlApi'
|
||||
this.version = 1.0
|
||||
this.inputs = [
|
||||
@@ -16,7 +16,7 @@ class RedisCacheUrlApi implements INodeCredential {
|
||||
label: 'Redis URL',
|
||||
name: 'redisUrl',
|
||||
type: 'string',
|
||||
default: '127.0.0.1'
|
||||
default: 'redis://localhost:6379'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { initializeAgentExecutorWithOptions, AgentExecutor, InitializeAgentExecu
|
||||
import { Tool } from 'langchain/tools'
|
||||
import { BaseChatMemory } from 'langchain/memory'
|
||||
import { getBaseClasses, mapChatHistory } from '../../../src/utils'
|
||||
import { BaseLanguageModel } from 'langchain/base_language'
|
||||
import { BaseChatModel } from 'langchain/chat_models/base'
|
||||
import { flatten } from 'lodash'
|
||||
import { additionalCallbacks } from '../../../src/handler'
|
||||
|
||||
@@ -29,7 +29,7 @@ class ConversationalAgent_Agents implements INode {
|
||||
constructor() {
|
||||
this.label = 'Conversational Agent'
|
||||
this.name = 'conversationalAgent'
|
||||
this.version = 1.0
|
||||
this.version = 2.0
|
||||
this.type = 'AgentExecutor'
|
||||
this.category = 'Agents'
|
||||
this.icon = 'agent.svg'
|
||||
@@ -45,7 +45,7 @@ class ConversationalAgent_Agents implements INode {
|
||||
{
|
||||
label: 'Language Model',
|
||||
name: 'model',
|
||||
type: 'BaseLanguageModel'
|
||||
type: 'BaseChatModel'
|
||||
},
|
||||
{
|
||||
label: 'Memory',
|
||||
@@ -65,7 +65,7 @@ class ConversationalAgent_Agents implements INode {
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
const model = nodeData.inputs?.model as BaseLanguageModel
|
||||
const model = nodeData.inputs?.model as BaseChatModel
|
||||
let tools = nodeData.inputs?.tools as Tool[]
|
||||
tools = flatten(tools)
|
||||
const memory = nodeData.inputs?.memory as BaseChatMemory
|
||||
@@ -92,8 +92,6 @@ class ConversationalAgent_Agents implements INode {
|
||||
const executor = nodeData.instance as AgentExecutor
|
||||
const memory = nodeData.inputs?.memory as BaseChatMemory
|
||||
|
||||
const callbacks = await additionalCallbacks(nodeData, options)
|
||||
|
||||
if (options && options.chatHistory) {
|
||||
const chatHistoryClassName = memory.chatHistory.constructor.name
|
||||
// Only replace when its In-Memory
|
||||
@@ -103,6 +101,10 @@ class ConversationalAgent_Agents implements INode {
|
||||
}
|
||||
}
|
||||
|
||||
;(executor.memory as any).returnMessages = true // Return true for BaseChatModel
|
||||
|
||||
const callbacks = await additionalCallbacks(nodeData, options)
|
||||
|
||||
const result = await executor.call({ input }, [...callbacks])
|
||||
return result?.output
|
||||
}
|
||||
|
||||
+2
@@ -82,6 +82,8 @@ class ConversationalRetrievalAgent_Agents implements INode {
|
||||
if (executor.memory) {
|
||||
;(executor.memory as any).memoryKey = 'chat_history'
|
||||
;(executor.memory as any).outputKey = 'output'
|
||||
;(executor.memory as any).returnMessages = true
|
||||
|
||||
const chatHistoryClassName = (executor.memory as any).chatHistory.constructor.name
|
||||
// Only replace when its In-Memory
|
||||
if (chatHistoryClassName && chatHistoryClassName === 'ChatMessageHistory') {
|
||||
|
||||
@@ -87,6 +87,8 @@ class OpenAIFunctionAgent_Agents implements INode {
|
||||
}
|
||||
}
|
||||
|
||||
;(executor.memory as any).returnMessages = true // Return true for BaseChatModel
|
||||
|
||||
const loggerHandler = new ConsoleCallbackHandler(options.logger)
|
||||
const callbacks = await additionalCallbacks(nodeData, options)
|
||||
|
||||
|
||||
@@ -106,16 +106,18 @@ class ConversationChain_Chains implements INode {
|
||||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
||||
const chain = nodeData.instance as ConversationChain
|
||||
const memory = nodeData.inputs?.memory as BufferMemory
|
||||
memory.returnMessages = true // Return true for BaseChatModel
|
||||
|
||||
if (options && options.chatHistory) {
|
||||
const chatHistoryClassName = memory.chatHistory.constructor.name
|
||||
// Only replace when its In-Memory
|
||||
if (chatHistoryClassName && chatHistoryClassName === 'ChatMessageHistory') {
|
||||
memory.chatHistory = mapChatHistory(options)
|
||||
chain.memory = memory
|
||||
}
|
||||
}
|
||||
|
||||
chain.memory = memory
|
||||
|
||||
const loggerHandler = new ConsoleCallbackHandler(options.logger)
|
||||
const callbacks = await additionalCallbacks(nodeData, options)
|
||||
|
||||
|
||||
@@ -109,9 +109,8 @@ const initalizeDynamoDB = async (nodeData: INodeData, options: ICommonObject): P
|
||||
})
|
||||
|
||||
const memory = new BufferMemoryExtended({
|
||||
memoryKey,
|
||||
memoryKey: memoryKey ?? 'chat_history',
|
||||
chatHistory: dynamoDb,
|
||||
returnMessages: true,
|
||||
isSessionIdUsingChatMessageId
|
||||
})
|
||||
return memory
|
||||
|
||||
@@ -123,9 +123,8 @@ const initializeMongoDB = async (nodeData: INodeData, options: ICommonObject): P
|
||||
}
|
||||
|
||||
return new BufferMemoryExtended({
|
||||
memoryKey,
|
||||
memoryKey: memoryKey ?? 'chat_history',
|
||||
chatHistory: mongoDBChatMessageHistory,
|
||||
returnMessages: true,
|
||||
isSessionIdUsingChatMessageId
|
||||
})
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ const initalizeRedis = async (nodeData: INodeData, options: ICommonObject): Prom
|
||||
}
|
||||
|
||||
const memory = new BufferMemoryExtended({
|
||||
memoryKey,
|
||||
memoryKey: memoryKey ?? 'chat_history',
|
||||
chatHistory: redisChatMessageHistory,
|
||||
isSessionIdUsingChatMessageId
|
||||
})
|
||||
|
||||
+1
@@ -95,6 +95,7 @@ const initalizeUpstashRedis = async (nodeData: INodeData, options: ICommonObject
|
||||
})
|
||||
|
||||
const memory = new BufferMemoryExtended({
|
||||
memoryKey: 'chat_history',
|
||||
chatHistory: redisChatMessageHistory,
|
||||
isSessionIdUsingChatMessageId
|
||||
})
|
||||
|
||||
@@ -20,7 +20,7 @@ class OpenAIModeration implements INode {
|
||||
this.name = 'inputModerationOpenAI'
|
||||
this.version = 1.0
|
||||
this.type = 'Moderation'
|
||||
this.icon = 'openai-moderation.png'
|
||||
this.icon = 'openai.png'
|
||||
this.category = 'Moderation'
|
||||
this.description = 'Check whether content complies with OpenAI usage policies.'
|
||||
this.baseClasses = [this.type, ...getBaseClasses(Moderation)]
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 47 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flowise-components",
|
||||
"version": "1.4.3",
|
||||
"version": "1.4.4",
|
||||
"description": "Flowiseai Components",
|
||||
"main": "dist/src/index",
|
||||
"types": "dist/src/index.d.ts",
|
||||
|
||||
Reference in New Issue
Block a user