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 { 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
})
+1 -1
View File
@@ -65,7 +65,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",