mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 21:00:58 +03:00
Review changes
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||||
|
|
||||||
|
class UpstashRedisMemoryApi implements INodeCredential {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
description: string
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'Upstash Redis Memory API'
|
||||||
|
this.name = 'upstashRedisMemoryApi'
|
||||||
|
this.version = 1.0
|
||||||
|
this.description =
|
||||||
|
'Refer to <a target="_blank" href="https://upstash.com/docs/redis/overall/getstarted">official guide</a> on how to create redis instance and get password on upstash'
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Upstash Redis Password',
|
||||||
|
name: 'upstashRedisPassword',
|
||||||
|
type: 'password'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { credClass: UpstashRedisMemoryApi }
|
||||||
+17
-13
@@ -1,8 +1,8 @@
|
|||||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
import { getBaseClasses } from '../../../src/utils'
|
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||||
import { ICommonObject } from '../../../src'
|
import { ICommonObject } from '../../../src'
|
||||||
import { BufferMemory, BufferMemoryInput } from 'langchain/memory'
|
import { BufferMemory, BufferMemoryInput } from 'langchain/memory'
|
||||||
import { UpstashRedisChatMessageHistory, UpstashRedisChatMessageHistoryInput } from "langchain/stores/message/upstash_redis"
|
import { UpstashRedisChatMessageHistory, UpstashRedisChatMessageHistoryInput } from 'langchain/stores/message/upstash_redis'
|
||||||
import { Redis, RedisConfigNodejs } from '@upstash/redis'
|
import { Redis, RedisConfigNodejs } from '@upstash/redis'
|
||||||
|
|
||||||
class UpstashRedisBackedChatMemory_Memory implements INode {
|
class UpstashRedisBackedChatMemory_Memory implements INode {
|
||||||
@@ -14,6 +14,7 @@ class UpstashRedisBackedChatMemory_Memory implements INode {
|
|||||||
icon: string
|
icon: string
|
||||||
category: string
|
category: string
|
||||||
baseClasses: string[]
|
baseClasses: string[]
|
||||||
|
credential: INodeParams
|
||||||
inputs: INodeParams[]
|
inputs: INodeParams[]
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -25,18 +26,19 @@ class UpstashRedisBackedChatMemory_Memory implements INode {
|
|||||||
this.category = 'Memory'
|
this.category = 'Memory'
|
||||||
this.description = 'Summarizes the conversation and stores the memory in upstash Redis server'
|
this.description = 'Summarizes the conversation and stores the memory in upstash Redis server'
|
||||||
this.baseClasses = [this.type, ...getBaseClasses(BufferMemory)]
|
this.baseClasses = [this.type, ...getBaseClasses(BufferMemory)]
|
||||||
|
this.credential = {
|
||||||
|
label: 'Connect Credential',
|
||||||
|
name: 'credential',
|
||||||
|
type: 'credential',
|
||||||
|
description: 'Configure password authentication on your upstash redis instance',
|
||||||
|
credentialNames: ['upstashRedisMemoryApi']
|
||||||
|
}
|
||||||
this.inputs = [
|
this.inputs = [
|
||||||
{
|
{
|
||||||
label: 'Base URL',
|
label: 'Base URL',
|
||||||
name: 'baseURL',
|
name: 'baseURL',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'redis://localhost:6379'
|
default: 'https://<your-url>.upstash.io'
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Token',
|
|
||||||
name: 'token',
|
|
||||||
type: 'string',
|
|
||||||
default: '********'
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Session Id',
|
label: 'Session Id',
|
||||||
@@ -70,7 +72,7 @@ class UpstashRedisBackedChatMemory_Memory implements INode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
async clearSessionMemory(nodeData: INodeData, options: ICommonObject): Promise<void> {
|
||||||
const redis = initalizeUpstashRedis(nodeData, options)
|
const redis = await initalizeUpstashRedis(nodeData, options)
|
||||||
const sessionId = nodeData.inputs?.sessionId as string
|
const sessionId = nodeData.inputs?.sessionId as string
|
||||||
const chatId = options?.chatId as string
|
const chatId = options?.chatId as string
|
||||||
options.logger.info(`Clearing Upstash Redis memory session ${sessionId ? sessionId : chatId}`)
|
options.logger.info(`Clearing Upstash Redis memory session ${sessionId ? sessionId : chatId}`)
|
||||||
@@ -79,18 +81,20 @@ class UpstashRedisBackedChatMemory_Memory implements INode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const initalizeUpstashRedis = (nodeData: INodeData, options: ICommonObject): BufferMemory => {
|
const initalizeUpstashRedis = async (nodeData: INodeData, options: ICommonObject): Promise<BufferMemory> => {
|
||||||
const baseURL = nodeData.inputs?.baseURL as string
|
const baseURL = nodeData.inputs?.baseURL as string
|
||||||
const sessionId = nodeData.inputs?.sessionId as string
|
const sessionId = nodeData.inputs?.sessionId as string
|
||||||
const sessionTTL = nodeData.inputs?.sessionTTL as number
|
const sessionTTL = nodeData.inputs?.sessionTTL as number
|
||||||
const memoryKey = nodeData.inputs?.memoryKey as string
|
const memoryKey = nodeData.inputs?.memoryKey as string
|
||||||
const chatId = options?.chatId as string
|
const chatId = options?.chatId as string
|
||||||
const token = nodeData.inputs?.token as string
|
|
||||||
|
|
||||||
let isSessionIdUsingChatMessageId = false
|
let isSessionIdUsingChatMessageId = false
|
||||||
if (!sessionId && chatId) isSessionIdUsingChatMessageId = true
|
if (!sessionId && chatId) isSessionIdUsingChatMessageId = true
|
||||||
|
|
||||||
const upstashRedisConfig = ({ url: baseURL, token }) as RedisConfigNodejs
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
const upstashRedisPassword = getCredentialParam('upstashRedisPassword', credentialData, nodeData)
|
||||||
|
|
||||||
|
const upstashRedisConfig = { url: baseURL, token: upstashRedisPassword } as RedisConfigNodejs
|
||||||
const redisClient = new Redis(upstashRedisConfig)
|
const redisClient = new Redis(upstashRedisConfig)
|
||||||
let obj: UpstashRedisChatMessageHistoryInput = {
|
let obj: UpstashRedisChatMessageHistoryInput = {
|
||||||
sessionId: sessionId ? sessionId : chatId,
|
sessionId: sessionId ? sessionId : chatId,
|
||||||
|
|||||||
Reference in New Issue
Block a user