Merge branch 'main' into FEATURE/Vision

This commit is contained in:
Henry Heng
2024-02-26 15:59:51 +08:00
committed by GitHub
6 changed files with 54 additions and 27 deletions
@@ -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 { BufferMemory, BufferMemoryInput } from 'langchain/memory'
import { UpstashRedisChatMessageHistory } from '@langchain/community/stores/message/upstash_redis' import { UpstashRedisChatMessageHistory } from '@langchain/community/stores/message/upstash_redis'
import { mapStoredMessageToChatMessage, AIMessage, HumanMessage, StoredMessage, BaseMessage } from '@langchain/core/messages' 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 { convertBaseMessagetoIMessage, getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { ICommonObject } from '../../../src/Interface' 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 { class UpstashRedisBackedChatMemory_Memory implements INode {
label: string label: string
name: string name: string
@@ -75,7 +94,7 @@ const initalizeUpstashRedis = async (nodeData: INodeData, options: ICommonObject
const credentialData = await getCredentialData(nodeData.credential ?? '', options) const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const upstashRestToken = getCredentialParam('upstashRestToken', credentialData, nodeData) const upstashRestToken = getCredentialParam('upstashRestToken', credentialData, nodeData)
const client = new Redis({ const client = getRedisClientbyOption({
url: baseURL, url: baseURL,
token: upstashRestToken token: upstashRestToken
}) })
+1 -1
View File
@@ -65,7 +65,7 @@
"langchain": "^0.1.20", "langchain": "^0.1.20",
"langfuse": "3.1.0", "langfuse": "3.1.0",
"langfuse-langchain": "^3.1.0", "langfuse-langchain": "^3.1.0",
"langsmith": "0.0.63", "langsmith": "0.1.6",
"linkifyjs": "^4.1.1", "linkifyjs": "^4.1.1",
"llamaindex": "^0.0.48", "llamaindex": "^0.0.48",
"lunary": "^0.6.16", "lunary": "^0.6.16",
+28 -23
View File
@@ -4,6 +4,7 @@ import { Dirent } from 'fs'
import { getNodeModulesPackagePath } from './utils' import { getNodeModulesPackagePath } from './utils'
import { promises } from 'fs' import { promises } from 'fs'
import { ICommonObject } from 'flowise-components' import { ICommonObject } from 'flowise-components'
import logger from './utils/logger'
export class NodesPool { export class NodesPool {
componentNodes: IComponentNodes = {} componentNodes: IComponentNodes = {}
@@ -28,36 +29,40 @@ export class NodesPool {
return Promise.all( return Promise.all(
nodeFiles.map(async (file) => { nodeFiles.map(async (file) => {
if (file.endsWith('.js')) { if (file.endsWith('.js')) {
const nodeModule = await require(file) try {
const nodeModule = await require(file)
if (nodeModule.nodeClass) { if (nodeModule.nodeClass) {
const newNodeInstance = new nodeModule.nodeClass() const newNodeInstance = new nodeModule.nodeClass()
newNodeInstance.filePath = file newNodeInstance.filePath = file
// Replace file icon with absolute path // Replace file icon with absolute path
if ( if (
newNodeInstance.icon && newNodeInstance.icon &&
(newNodeInstance.icon.endsWith('.svg') || (newNodeInstance.icon.endsWith('.svg') ||
newNodeInstance.icon.endsWith('.png') || newNodeInstance.icon.endsWith('.png') ||
newNodeInstance.icon.endsWith('.jpg')) newNodeInstance.icon.endsWith('.jpg'))
) { ) {
const filePath = file.replace(/\\/g, '/').split('/') const filePath = file.replace(/\\/g, '/').split('/')
filePath.pop() filePath.pop()
const nodeIconAbsolutePath = `${filePath.join('/')}/${newNodeInstance.icon}` const nodeIconAbsolutePath = `${filePath.join('/')}/${newNodeInstance.icon}`
newNodeInstance.icon = nodeIconAbsolutePath newNodeInstance.icon = nodeIconAbsolutePath
// Store icon path for componentCredentials // Store icon path for componentCredentials
if (newNodeInstance.credential) { if (newNodeInstance.credential) {
for (const credName of newNodeInstance.credential.credentialNames) { for (const credName of newNodeInstance.credential.credentialNames) {
this.credentialIconPath[credName] = nodeIconAbsolutePath this.credentialIconPath[credName] = nodeIconAbsolutePath
}
} }
} }
}
const skipCategories = ['Analytic', 'SpeechToText'] const skipCategories = ['Analytic', 'SpeechToText']
if (!skipCategories.includes(newNodeInstance.category)) { if (!skipCategories.includes(newNodeInstance.category)) {
this.componentNodes[newNodeInstance.name] = newNodeInstance this.componentNodes[newNodeInstance.name] = newNodeInstance
}
} }
} catch (err) {
logger.error(`❌ [server]: Error during initDatabase with file ${file}:`, err)
} }
} }
}) })
+2 -1
View File
@@ -99,7 +99,7 @@ export class App {
// Initialize database // Initialize database
this.AppDataSource.initialize() this.AppDataSource.initialize()
.then(async () => { .then(async () => {
logger.info('📦 [server]: Data Source has been initialized!') logger.info('📦 [server]: Data Source is being initialized!')
// Run Migrations Scripts // Run Migrations Scripts
await this.AppDataSource.runMigrations({ transaction: 'each' }) await this.AppDataSource.runMigrations({ transaction: 'each' })
@@ -126,6 +126,7 @@ export class App {
// Initialize telemetry // Initialize telemetry
this.telemetry = new Telemetry() this.telemetry = new Telemetry()
logger.info('📦 [server]: Data Source has been initialized!')
}) })
.catch((err) => { .catch((err) => {
logger.error('❌ [server]: Error during Data Source initialization:', err) logger.error('❌ [server]: Error during Data Source initialization:', err)
+1
View File
@@ -47,6 +47,7 @@ const Chatflows = () => {
const [view, setView] = React.useState(localStorage.getItem('flowDisplayStyle') || 'card') const [view, setView] = React.useState(localStorage.getItem('flowDisplayStyle') || 'card')
const handleChange = (event, nextView) => { const handleChange = (event, nextView) => {
if (nextView === null) return
localStorage.setItem('flowDisplayStyle', nextView) localStorage.setItem('flowDisplayStyle', nextView)
setView(nextView) setView(nextView)
} }
@@ -131,6 +131,7 @@ const Marketplace = () => {
} }
const handleViewChange = (event, nextView) => { const handleViewChange = (event, nextView) => {
if (nextView === null) return
localStorage.setItem('mpDisplayStyle', nextView) localStorage.setItem('mpDisplayStyle', nextView)
setView(nextView) setView(nextView)
} }