From 23f7e7802f6a28092ee5f9361f70c30870b5f888 Mon Sep 17 00:00:00 2001 From: Jaredude Date: Wed, 21 Feb 2024 21:19:38 -0600 Subject: [PATCH 1/5] handles scenario where NodesPool require call fails Currently, the following file results in an error: Flowise/packages/components/dist/nodes/documentloaders/Subtitles/Subtitles.js:3:15 The result is that initializeNodes fails on all nodes, and all other code in initDatabase fails to load --- packages/server/src/NodesPool.ts | 51 ++++++++++++++++++-------------- packages/server/src/index.ts | 3 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/packages/server/src/NodesPool.ts b/packages/server/src/NodesPool.ts index f4681d4a..86736d45 100644 --- a/packages/server/src/NodesPool.ts +++ b/packages/server/src/NodesPool.ts @@ -4,6 +4,7 @@ import { Dirent } from 'fs' import { getNodeModulesPackagePath } from './utils' import { promises } from 'fs' import { ICommonObject } from 'flowise-components' +import logger from './utils/logger' export class NodesPool { componentNodes: IComponentNodes = {} @@ -28,36 +29,40 @@ export class NodesPool { return Promise.all( nodeFiles.map(async (file) => { if (file.endsWith('.js')) { - const nodeModule = await require(file) + try { + const nodeModule = await require(file) - if (nodeModule.nodeClass) { - const newNodeInstance = new nodeModule.nodeClass() - newNodeInstance.filePath = file + if (nodeModule.nodeClass) { + const newNodeInstance = new nodeModule.nodeClass() + newNodeInstance.filePath = file - // Replace file icon with absolute path - if ( - newNodeInstance.icon && - (newNodeInstance.icon.endsWith('.svg') || - newNodeInstance.icon.endsWith('.png') || - newNodeInstance.icon.endsWith('.jpg')) - ) { - const filePath = file.replace(/\\/g, '/').split('/') - filePath.pop() - const nodeIconAbsolutePath = `${filePath.join('/')}/${newNodeInstance.icon}` - newNodeInstance.icon = nodeIconAbsolutePath + // Replace file icon with absolute path + if ( + newNodeInstance.icon && + (newNodeInstance.icon.endsWith('.svg') || + newNodeInstance.icon.endsWith('.png') || + newNodeInstance.icon.endsWith('.jpg')) + ) { + const filePath = file.replace(/\\/g, '/').split('/') + filePath.pop() + const nodeIconAbsolutePath = `${filePath.join('/')}/${newNodeInstance.icon}` + newNodeInstance.icon = nodeIconAbsolutePath - // Store icon path for componentCredentials - if (newNodeInstance.credential) { - for (const credName of newNodeInstance.credential.credentialNames) { - this.credentialIconPath[credName] = nodeIconAbsolutePath + // Store icon path for componentCredentials + if (newNodeInstance.credential) { + for (const credName of newNodeInstance.credential.credentialNames) { + this.credentialIconPath[credName] = nodeIconAbsolutePath + } } } - } - const skipCategories = ['Analytic'] - if (!skipCategories.includes(newNodeInstance.category)) { - this.componentNodes[newNodeInstance.name] = newNodeInstance + const skipCategories = ['Analytic'] + if (!skipCategories.includes(newNodeInstance.category)) { + this.componentNodes[newNodeInstance.name] = newNodeInstance + } } + } catch (err) { + logger.error(`❌ [server]: Error during initDatabase with file ${file}:`, err) } } }) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 20102a42..aef8494a 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -85,7 +85,7 @@ export class App { // Initialize database this.AppDataSource.initialize() .then(async () => { - logger.info('📦 [server]: Data Source has been initialized!') + logger.info('📦 [server]: Data Source is being initialized!') // Run Migrations Scripts await this.AppDataSource.runMigrations({ transaction: 'each' }) @@ -112,6 +112,7 @@ export class App { // Initialize telemetry this.telemetry = new Telemetry() + logger.info('📦 [server]: Data Source has been initialized!') }) .catch((err) => { logger.error('❌ [server]: Error during Data Source initialization:', err) From 2f4134a2915d69712775e0c32af8f756dc79e325 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 22 Feb 2024 23:09:58 +0800 Subject: [PATCH 2/5] upstash singleton --- .../UpstashRedisBackedChatMemory.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/memory/UpstashRedisBackedChatMemory/UpstashRedisBackedChatMemory.ts b/packages/components/nodes/memory/UpstashRedisBackedChatMemory/UpstashRedisBackedChatMemory.ts index 0f26fa33..52da0f37 100644 --- a/packages/components/nodes/memory/UpstashRedisBackedChatMemory/UpstashRedisBackedChatMemory.ts +++ b/packages/components/nodes/memory/UpstashRedisBackedChatMemory/UpstashRedisBackedChatMemory.ts @@ -1,4 +1,5 @@ -import { Redis } from '@upstash/redis' +import { Redis, RedisConfigNodejs } from '@upstash/redis' +import { isEqual } from 'lodash' import { BufferMemory, BufferMemoryInput } from 'langchain/memory' import { UpstashRedisChatMessageHistory } from '@langchain/community/stores/message/upstash_redis' import { mapStoredMessageToChatMessage, AIMessage, HumanMessage, StoredMessage, BaseMessage } from '@langchain/core/messages' @@ -6,6 +7,24 @@ import { FlowiseMemory, IMessage, INode, INodeData, INodeParams, MemoryMethods, import { convertBaseMessagetoIMessage, getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' import { ICommonObject } from '../../../src/Interface' +let redisClientSingleton: Redis +let redisClientOption: RedisConfigNodejs + +const getRedisClientbyOption = (option: RedisConfigNodejs) => { + if (!redisClientSingleton) { + // if client doesn't exists + redisClientSingleton = new Redis(option) + redisClientOption = option + return redisClientSingleton + } else if (redisClientSingleton && !isEqual(option, redisClientOption)) { + // if client exists but option changed + redisClientSingleton = new Redis(option) + redisClientOption = option + return redisClientSingleton + } + return redisClientSingleton +} + class UpstashRedisBackedChatMemory_Memory implements INode { label: string name: string @@ -75,7 +94,7 @@ const initalizeUpstashRedis = async (nodeData: INodeData, options: ICommonObject const credentialData = await getCredentialData(nodeData.credential ?? '', options) const upstashRestToken = getCredentialParam('upstashRestToken', credentialData, nodeData) - const client = new Redis({ + const client = getRedisClientbyOption({ url: baseURL, token: upstashRestToken }) From 0a5195d1abbaf563c6de1a5f0cb95a13b164c3ed Mon Sep 17 00:00:00 2001 From: vinodkiran Date: Fri, 23 Feb 2024 07:07:46 +0530 Subject: [PATCH 3/5] Bugfix: View Toggle loses state when button is clicked twice. --- packages/ui/src/views/chatflows/index.js | 2 ++ packages/ui/src/views/marketplaces/index.js | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/ui/src/views/chatflows/index.js b/packages/ui/src/views/chatflows/index.js index c87ad306..c1e9ade4 100644 --- a/packages/ui/src/views/chatflows/index.js +++ b/packages/ui/src/views/chatflows/index.js @@ -47,6 +47,8 @@ const Chatflows = () => { const [view, setView] = React.useState(localStorage.getItem('flowDisplayStyle') || 'card') const handleChange = (event, nextView) => { + if (nextView === null) return + console.log('nextView == ' + nextView) localStorage.setItem('flowDisplayStyle', nextView) setView(nextView) } diff --git a/packages/ui/src/views/marketplaces/index.js b/packages/ui/src/views/marketplaces/index.js index e5a65cb9..a6d29e43 100644 --- a/packages/ui/src/views/marketplaces/index.js +++ b/packages/ui/src/views/marketplaces/index.js @@ -131,6 +131,7 @@ const Marketplace = () => { } const handleViewChange = (event, nextView) => { + if (nextView === null) return localStorage.setItem('mpDisplayStyle', nextView) setView(nextView) } From f690943316f175f80f9ee0fdf602ba27c64e3c1b Mon Sep 17 00:00:00 2001 From: vinodkiran Date: Fri, 23 Feb 2024 07:19:26 +0530 Subject: [PATCH 4/5] Bugfix: lint fixes (no-console) --- packages/ui/src/views/chatflows/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/ui/src/views/chatflows/index.js b/packages/ui/src/views/chatflows/index.js index c1e9ade4..6426cdd6 100644 --- a/packages/ui/src/views/chatflows/index.js +++ b/packages/ui/src/views/chatflows/index.js @@ -48,7 +48,6 @@ const Chatflows = () => { const handleChange = (event, nextView) => { if (nextView === null) return - console.log('nextView == ' + nextView) localStorage.setItem('flowDisplayStyle', nextView) setView(nextView) } From 46c32693ad1059747041f31c9999923d06a1337e Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 24 Feb 2024 02:25:07 +0800 Subject: [PATCH 5/5] update langsmith version --- packages/components/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/package.json b/packages/components/package.json index b0d40ff7..1a2b060c 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -64,7 +64,7 @@ "langchain": "^0.1.20", "langfuse": "3.1.0", "langfuse-langchain": "^3.1.0", - "langsmith": "0.0.63", + "langsmith": "0.1.6", "linkifyjs": "^4.1.1", "llamaindex": "^0.0.48", "lunary": "^0.6.16",