Skip to content

Commit 8a3320a

Browse files
authored
Merge pull request FlowiseAI#1 from use-the-fork/maintenance/vite-pnpm-tsup
Bring PR Current.
2 parents 4e3f219 + 0ad9b9a commit 8a3320a

44 files changed

Lines changed: 26666 additions & 26486 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/components/credentials/RedisCacheApi.credential.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class RedisCacheApi implements INodeCredential {
88
inputs: INodeParams[]
99

1010
constructor() {
11-
this.label = 'Redis Cache API'
11+
this.label = 'Redis API'
1212
this.name = 'redisCacheApi'
1313
this.version = 1.0
1414
this.inputs = [

packages/components/credentials/RedisCacheUrlApi.credential.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ class RedisCacheUrlApi implements INodeCredential {
88
inputs: INodeParams[]
99

1010
constructor() {
11-
this.label = 'Redis Cache URL'
11+
this.label = 'Redis URL'
1212
this.name = 'redisCacheUrlApi'
1313
this.version = 1.0
1414
this.inputs = [
1515
{
1616
label: 'Redis URL',
1717
name: 'redisUrl',
1818
type: 'string',
19-
default: '127.0.0.1'
19+
default: 'redis://localhost:6379'
2020
}
2121
]
2222
}

packages/components/nodes/agents/ConversationalAgent/ConversationalAgent.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { initializeAgentExecutorWithOptions, AgentExecutor, InitializeAgentExecu
33
import { Tool } from 'langchain/tools'
44
import { BaseChatMemory } from 'langchain/memory'
55
import { getBaseClasses, mapChatHistory } from '../../../src/utils'
6-
import { BaseLanguageModel } from 'langchain/base_language'
6+
import { BaseChatModel } from 'langchain/chat_models/base'
77
import { flatten } from 'lodash'
88
import { additionalCallbacks } from '../../../src/handler'
99

@@ -29,7 +29,7 @@ class ConversationalAgent_Agents implements INode {
2929
constructor() {
3030
this.label = 'Conversational Agent'
3131
this.name = 'conversationalAgent'
32-
this.version = 1.0
32+
this.version = 2.0
3333
this.type = 'AgentExecutor'
3434
this.category = 'Agents'
3535
this.icon = 'agent.svg'
@@ -45,7 +45,7 @@ class ConversationalAgent_Agents implements INode {
4545
{
4646
label: 'Language Model',
4747
name: 'model',
48-
type: 'BaseLanguageModel'
48+
type: 'BaseChatModel'
4949
},
5050
{
5151
label: 'Memory',
@@ -65,7 +65,7 @@ class ConversationalAgent_Agents implements INode {
6565
}
6666

6767
async init(nodeData: INodeData): Promise<any> {
68-
const model = nodeData.inputs?.model as BaseLanguageModel
68+
const model = nodeData.inputs?.model as BaseChatModel
6969
let tools = nodeData.inputs?.tools as Tool[]
7070
tools = flatten(tools)
7171
const memory = nodeData.inputs?.memory as BaseChatMemory
@@ -92,8 +92,6 @@ class ConversationalAgent_Agents implements INode {
9292
const executor = nodeData.instance as AgentExecutor
9393
const memory = nodeData.inputs?.memory as BaseChatMemory
9494

95-
const callbacks = await additionalCallbacks(nodeData, options)
96-
9795
if (options && options.chatHistory) {
9896
const chatHistoryClassName = memory.chatHistory.constructor.name
9997
// Only replace when its In-Memory
@@ -103,6 +101,10 @@ class ConversationalAgent_Agents implements INode {
103101
}
104102
}
105103

104+
;(executor.memory as any).returnMessages = true // Return true for BaseChatModel
105+
106+
const callbacks = await additionalCallbacks(nodeData, options)
107+
106108
const result = await executor.call({ input }, [...callbacks])
107109
return result?.output
108110
}

packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ConversationalRetrievalAgent_Agents implements INode {
2121
constructor() {
2222
this.label = 'Conversational Retrieval Agent'
2323
this.name = 'conversationalRetrievalAgent'
24-
this.version = 2.0
24+
this.version = 3.0
2525
this.type = 'AgentExecutor'
2626
this.category = 'Agents'
2727
this.icon = 'agent.svg'
@@ -42,7 +42,7 @@ class ConversationalRetrievalAgent_Agents implements INode {
4242
{
4343
label: 'OpenAI/Azure Chat Model',
4444
name: 'model',
45-
type: 'ChatOpenAI | AzureChatOpenAI'
45+
type: 'BaseChatModel'
4646
},
4747
{
4848
label: 'System Message',
@@ -82,6 +82,8 @@ class ConversationalRetrievalAgent_Agents implements INode {
8282
if (executor.memory) {
8383
;(executor.memory as any).memoryKey = 'chat_history'
8484
;(executor.memory as any).outputKey = 'output'
85+
;(executor.memory as any).returnMessages = true
86+
8587
const chatHistoryClassName = (executor.memory as any).chatHistory.constructor.name
8688
// Only replace when its In-Memory
8789
if (chatHistoryClassName && chatHistoryClassName === 'ChatMessageHistory') {

packages/components/nodes/agents/OpenAIAssistant/OpenAIAssistant.ts

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class OpenAIAssistant_Agents implements INode {
2323
constructor() {
2424
this.label = 'OpenAI Assistant'
2525
this.name = 'openAIAssistant'
26-
this.version = 1.0
26+
this.version = 2.0
2727
this.type = 'OpenAIAssistant'
2828
this.category = 'Agents'
2929
this.icon = 'openai.png'
@@ -41,6 +41,15 @@ class OpenAIAssistant_Agents implements INode {
4141
name: 'tools',
4242
type: 'Tool',
4343
list: true
44+
},
45+
{
46+
label: 'Disable File Download',
47+
name: 'disableFileDownload',
48+
type: 'boolean',
49+
description:
50+
'Messages can contain text, images, or files. In some cases, you may want to prevent others from downloading the files. Learn more from OpenAI File Annotation <a target="_blank" href="https://platform.openai.com/docs/assistants/how-it-works/managing-threads-and-messages">docs</a>',
51+
optional: true,
52+
additionalParams: true
4453
}
4554
]
4655
}
@@ -76,49 +85,54 @@ class OpenAIAssistant_Agents implements INode {
7685
return null
7786
}
7887

79-
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
80-
const selectedAssistantId = nodeData.inputs?.selectedAssistant as string
81-
const appDataSource = options.appDataSource as DataSource
82-
const databaseEntities = options.databaseEntities as IDatabaseEntity
83-
let sessionId = nodeData.inputs?.sessionId as string
88+
//@ts-ignore
89+
memoryMethods = {
90+
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
91+
const selectedAssistantId = nodeData.inputs?.selectedAssistant as string
92+
const appDataSource = options.appDataSource as DataSource
93+
const databaseEntities = options.databaseEntities as IDatabaseEntity
94+
let sessionId = nodeData.inputs?.sessionId as string
8495

85-
const assistant = await appDataSource.getRepository(databaseEntities['Assistant']).findOneBy({
86-
id: selectedAssistantId
87-
})
96+
const assistant = await appDataSource.getRepository(databaseEntities['Assistant']).findOneBy({
97+
id: selectedAssistantId
98+
})
8899

89-
if (!assistant) {
90-
options.logger.error(`Assistant ${selectedAssistantId} not found`)
91-
return
92-
}
100+
if (!assistant) {
101+
options.logger.error(`Assistant ${selectedAssistantId} not found`)
102+
return
103+
}
93104

94-
if (!sessionId && options.chatId) {
95-
const chatmsg = await appDataSource.getRepository(databaseEntities['ChatMessage']).findOneBy({
96-
chatId: options.chatId
97-
})
98-
if (!chatmsg) {
99-
options.logger.error(`Chat Message with Chat Id: ${options.chatId} not found`)
105+
if (!sessionId && options.chatId) {
106+
const chatmsg = await appDataSource.getRepository(databaseEntities['ChatMessage']).findOneBy({
107+
chatId: options.chatId
108+
})
109+
if (!chatmsg) {
110+
options.logger.error(`Chat Message with Chat Id: ${options.chatId} not found`)
111+
return
112+
}
113+
sessionId = chatmsg.sessionId
114+
}
115+
116+
const credentialData = await getCredentialData(assistant.credential ?? '', options)
117+
const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData)
118+
if (!openAIApiKey) {
119+
options.logger.error(`OpenAI ApiKey not found`)
100120
return
101121
}
102-
sessionId = chatmsg.sessionId
103-
}
104122

105-
const credentialData = await getCredentialData(assistant.credential ?? '', options)
106-
const openAIApiKey = getCredentialParam('openAIApiKey', credentialData, nodeData)
107-
if (!openAIApiKey) {
108-
options.logger.error(`OpenAI ApiKey not found`)
109-
return
123+
const openai = new OpenAI({ apiKey: openAIApiKey })
124+
options.logger.info(`Clearing OpenAI Thread ${sessionId}`)
125+
if (sessionId) await openai.beta.threads.del(sessionId)
126+
options.logger.info(`Successfully cleared OpenAI Thread ${sessionId}`)
110127
}
111-
112-
const openai = new OpenAI({ apiKey: openAIApiKey })
113-
options.logger.info(`Clearing OpenAI Thread ${sessionId}`)
114-
if (sessionId) await openai.beta.threads.del(sessionId)
115-
options.logger.info(`Successfully cleared OpenAI Thread ${sessionId}`)
116128
}
117129

118130
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string | object> {
119131
const selectedAssistantId = nodeData.inputs?.selectedAssistant as string
120132
const appDataSource = options.appDataSource as DataSource
121133
const databaseEntities = options.databaseEntities as IDatabaseEntity
134+
const disableFileDownload = nodeData.inputs?.disableFileDownload as boolean
135+
122136
let tools = nodeData.inputs?.tools
123137
tools = flatten(tools)
124138
const formattedTools = tools?.map((tool: any) => formatToOpenAIAssistantTool(tool)) ?? []
@@ -310,7 +324,7 @@ class OpenAIAssistant_Agents implements INode {
310324

311325
const dirPath = path.join(getUserHome(), '.flowise', 'openai-assistant')
312326

313-
// Iterate over the annotations and add footnotes
327+
// Iterate over the annotations
314328
for (let index = 0; index < annotations.length; index++) {
315329
const annotation = annotations[index]
316330
let filePath = ''
@@ -323,34 +337,44 @@ class OpenAIAssistant_Agents implements INode {
323337
// eslint-disable-next-line no-useless-escape
324338
const fileName = cited_file.filename.split(/[\/\\]/).pop() ?? cited_file.filename
325339
filePath = path.join(getUserHome(), '.flowise', 'openai-assistant', fileName)
326-
await downloadFile(cited_file, filePath, dirPath, openAIApiKey)
327-
fileAnnotations.push({
328-
filePath,
329-
fileName
330-
})
340+
if (!disableFileDownload) {
341+
await downloadFile(cited_file, filePath, dirPath, openAIApiKey)
342+
fileAnnotations.push({
343+
filePath,
344+
fileName
345+
})
346+
}
331347
} else {
332348
const file_path = (annotation as OpenAI.Beta.Threads.Messages.MessageContentText.Text.FilePath).file_path
333349
if (file_path) {
334350
const cited_file = await openai.files.retrieve(file_path.file_id)
335351
// eslint-disable-next-line no-useless-escape
336352
const fileName = cited_file.filename.split(/[\/\\]/).pop() ?? cited_file.filename
337353
filePath = path.join(getUserHome(), '.flowise', 'openai-assistant', fileName)
338-
await downloadFile(cited_file, filePath, dirPath, openAIApiKey)
339-
fileAnnotations.push({
340-
filePath,
341-
fileName
342-
})
354+
if (!disableFileDownload) {
355+
await downloadFile(cited_file, filePath, dirPath, openAIApiKey)
356+
fileAnnotations.push({
357+
filePath,
358+
fileName
359+
})
360+
}
343361
}
344362
}
345363

346364
// Replace the text with a footnote
347-
message_content.value = message_content.value.replace(`${annotation.text}`, `${filePath}`)
365+
message_content.value = message_content.value.replace(
366+
`${annotation.text}`,
367+
`${disableFileDownload ? '' : filePath}`
368+
)
348369
}
349370

350371
returnVal += message_content.value
351372
} else {
352373
returnVal += content.text.value
353374
}
375+
376+
const lenticularBracketRegex = /[^]*/g
377+
returnVal = returnVal.replace(lenticularBracketRegex, '')
354378
} else {
355379
const content = assistantMessages[0].content[i] as MessageContentImageFile
356380
const fileId = content.image_file.file_id

packages/components/nodes/agents/OpenAIFunctionAgent/OpenAIFunctionAgent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class OpenAIFunctionAgent_Agents implements INode {
2020
constructor() {
2121
this.label = 'OpenAI Function Agent'
2222
this.name = 'openAIFunctionAgent'
23-
this.version = 2.0
23+
this.version = 3.0
2424
this.type = 'AgentExecutor'
2525
this.category = 'Agents'
2626
this.icon = 'openai.png'
@@ -41,7 +41,7 @@ class OpenAIFunctionAgent_Agents implements INode {
4141
{
4242
label: 'OpenAI/Azure Chat Model',
4343
name: 'model',
44-
type: 'ChatOpenAI | AzureChatOpenAI'
44+
type: 'BaseChatModel'
4545
},
4646
{
4747
label: 'System Message',
@@ -87,6 +87,8 @@ class OpenAIFunctionAgent_Agents implements INode {
8787
}
8888
}
8989

90+
;(executor.memory as any).returnMessages = true // Return true for BaseChatModel
91+
9092
const loggerHandler = new ConsoleCallbackHandler(options.logger)
9193
const callbacks = await additionalCallbacks(nodeData, options)
9294

packages/components/nodes/chains/ConversationChain/ConversationChain.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,18 @@ class ConversationChain_Chains implements INode {
106106
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
107107
const chain = nodeData.instance as ConversationChain
108108
const memory = nodeData.inputs?.memory as BufferMemory
109+
memory.returnMessages = true // Return true for BaseChatModel
109110

110111
if (options && options.chatHistory) {
111112
const chatHistoryClassName = memory.chatHistory.constructor.name
112113
// Only replace when its In-Memory
113114
if (chatHistoryClassName && chatHistoryClassName === 'ChatMessageHistory') {
114115
memory.chatHistory = mapChatHistory(options)
115-
chain.memory = memory
116116
}
117117
}
118118

119+
chain.memory = memory
120+
119121
const loggerHandler = new ConsoleCallbackHandler(options.logger)
120122
const callbacks = await additionalCallbacks(nodeData, options)
121123

packages/components/nodes/memory/DynamoDb/DynamoDb.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { ICommonObject, INode, INodeData, INodeParams, getBaseClasses, getCredentialData, getCredentialParam } from '../../../src'
1+
import {
2+
ICommonObject,
3+
INode,
4+
INodeData,
5+
INodeParams,
6+
getBaseClasses,
7+
getCredentialData,
8+
getCredentialParam,
9+
serializeChatHistory
10+
} from '../../../src'
211
import { DynamoDBChatMessageHistory } from 'langchain/stores/message/dynamodb'
312
import { BufferMemory, BufferMemoryInput } from 'langchain/memory'
413

@@ -70,13 +79,23 @@ class DynamoDb_Memory implements INode {
7079
return initalizeDynamoDB(nodeData, options)
7180
}
7281

73-
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
74-
const dynamodbMemory = await initalizeDynamoDB(nodeData, options)
75-
const sessionId = nodeData.inputs?.sessionId as string
76-
const chatId = options?.chatId as string
77-
options.logger.info(`Clearing DynamoDb memory session ${sessionId ? sessionId : chatId}`)
78-
await dynamodbMemory.clear()
79-
options.logger.info(`Successfully cleared DynamoDb memory session ${sessionId ? sessionId : chatId}`)
82+
//@ts-ignore
83+
memoryMethods = {
84+
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
85+
const dynamodbMemory = await initalizeDynamoDB(nodeData, options)
86+
const sessionId = nodeData.inputs?.sessionId as string
87+
const chatId = options?.chatId as string
88+
options.logger.info(`Clearing DynamoDb memory session ${sessionId ? sessionId : chatId}`)
89+
await dynamodbMemory.clear()
90+
options.logger.info(`Successfully cleared DynamoDb memory session ${sessionId ? sessionId : chatId}`)
91+
},
92+
async getChatMessages(nodeData: INodeData, options: ICommonObject): Promise<string> {
93+
const memoryKey = nodeData.inputs?.memoryKey as string
94+
const dynamodbMemory = await initalizeDynamoDB(nodeData, options)
95+
const key = memoryKey ?? 'chat_history'
96+
const memoryResult = await dynamodbMemory.loadMemoryVariables({})
97+
return serializeChatHistory(memoryResult[key])
98+
}
8099
}
81100
}
82101

@@ -109,9 +128,8 @@ const initalizeDynamoDB = async (nodeData: INodeData, options: ICommonObject): P
109128
})
110129

111130
const memory = new BufferMemoryExtended({
112-
memoryKey,
131+
memoryKey: memoryKey ?? 'chat_history',
113132
chatHistory: dynamoDb,
114-
returnMessages: true,
115133
isSessionIdUsingChatMessageId
116134
})
117135
return memory

0 commit comments

Comments
 (0)