mirror of https://github.com/FlowiseAI/Flowise.git
Addition of Redis LLM Cache
parent
4efec94dc8
commit
29be2d2608
|
|
@ -0,0 +1,43 @@
|
||||||
|
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||||
|
|
||||||
|
class RedisCacheApi implements INodeCredential {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
description: string
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'Redis Cache API'
|
||||||
|
this.name = 'redisCacheApi'
|
||||||
|
this.version = 1.0
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Redis Host',
|
||||||
|
name: 'redisCacheHost',
|
||||||
|
type: 'string',
|
||||||
|
default: '127.0.0.1'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Port',
|
||||||
|
name: 'redisCachePort',
|
||||||
|
type: 'number',
|
||||||
|
default: '6789'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'User',
|
||||||
|
name: 'redisCacheUser',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: '<REDIS_USERNAME>'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Password',
|
||||||
|
name: 'redisCachePwd',
|
||||||
|
type: 'password',
|
||||||
|
placeholder: '<REDIS_PASSWORD>'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { credClass: RedisCacheApi }
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
import {
|
||||||
|
getBaseClasses,
|
||||||
|
getCredentialData,
|
||||||
|
getCredentialParam,
|
||||||
|
ICommonObject,
|
||||||
|
INode,
|
||||||
|
INodeData,
|
||||||
|
INodeOutputsValue,
|
||||||
|
INodeParams
|
||||||
|
} from '../../../src'
|
||||||
|
import { RedisCache } from 'langchain/cache/ioredis'
|
||||||
|
import { Redis } from 'ioredis'
|
||||||
|
|
||||||
|
class LLMRedisCache implements INode {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
description: string
|
||||||
|
type: string
|
||||||
|
icon: string
|
||||||
|
category: string
|
||||||
|
baseClasses: string[]
|
||||||
|
inputs: INodeParams[]
|
||||||
|
outputs: INodeOutputsValue[]
|
||||||
|
credential: INodeParams
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'Redis LLM Cache'
|
||||||
|
this.name = 'redisCache'
|
||||||
|
this.version = 1.0
|
||||||
|
this.type = 'LLMCache'
|
||||||
|
this.icon = 'redis.svg'
|
||||||
|
this.category = 'LLM Cache'
|
||||||
|
this.baseClasses = [this.type, 'LLMCacheBase']
|
||||||
|
this.credential = {
|
||||||
|
label: 'Connect Credential',
|
||||||
|
name: 'credential',
|
||||||
|
type: 'credential',
|
||||||
|
optional: true,
|
||||||
|
credentialNames: ['redisCacheApi']
|
||||||
|
}
|
||||||
|
this.inputs = []
|
||||||
|
this.outputs = [
|
||||||
|
{
|
||||||
|
label: 'LLM Cache',
|
||||||
|
name: 'cache',
|
||||||
|
baseClasses: [this.type, ...getBaseClasses(RedisCache)]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
const username = getCredentialParam('redisCacheUser', credentialData, nodeData)
|
||||||
|
const password = getCredentialParam('redisCachePwd', credentialData, nodeData)
|
||||||
|
const portStr = getCredentialParam('redisCachePort', credentialData, nodeData)
|
||||||
|
const host = getCredentialParam('redisCacheHost', credentialData, nodeData)
|
||||||
|
let port = 6379
|
||||||
|
try {
|
||||||
|
port = portStr ? parseInt(portStr) : 6379
|
||||||
|
} catch (e) {
|
||||||
|
port = 6379
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new Redis({
|
||||||
|
port: port, // Redis port
|
||||||
|
host: host,
|
||||||
|
username: username,
|
||||||
|
password: password
|
||||||
|
})
|
||||||
|
return new RedisCache(client)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { nodeClass: LLMRedisCache }
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" id="redis"><path fill="#A41E11" d="M121.8 93.1c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.9-11.5 3.8-17.3 1s-42.7-17.6-49.4-20.8c-3.3-1.6-5-2.9-5-4.2v-12.7s48-10.5 55.8-13.2c7.8-2.8 10.4-2.9 17-.5s46.1 9.5 52.6 11.9v12.5c0 1.3-1.5 2.7-4.9 4.4z"></path><path fill="#D82C20" d="M121.8 80.5c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.9-11.5 3.8-17.3 1-5.8-2.8-42.7-17.7-49.4-20.9-6.6-3.2-6.8-5.4-.3-7.9 6.5-2.6 43.2-17 51-19.7 7.8-2.8 10.4-2.9 17-.5s41.1 16.1 47.6 18.5c6.7 2.4 6.9 4.4.2 7.9z"></path><path fill="#A41E11" d="M121.8 72.5c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.8-11.5 3.8-17.3 1-5.8-2.8-42.7-17.7-49.4-20.9-3.3-1.6-5-2.9-5-4.2v-12.7s48-10.5 55.8-13.2c7.8-2.8 10.4-2.9 17-.5s46.1 9.5 52.6 11.9v12.5c0 1.3-1.5 2.7-4.9 4.5z"></path><path fill="#D82C20" d="M121.8 59.8c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.8-11.5 3.8-17.3 1-5.8-2.8-42.7-17.7-49.4-20.9s-6.8-5.4-.3-7.9c6.5-2.6 43.2-17 51-19.7 7.8-2.8 10.4-2.9 17-.5s41.1 16.1 47.6 18.5c6.7 2.4 6.9 4.4.2 7.9z"></path><path fill="#A41E11" d="M121.8 51c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.8-11.5 3.8-17.3 1-5.8-2.7-42.7-17.6-49.4-20.8-3.3-1.6-5.1-2.9-5.1-4.2v-12.7s48-10.5 55.8-13.2c7.8-2.8 10.4-2.9 17-.5s46.1 9.5 52.6 11.9v12.5c.1 1.3-1.4 2.6-4.8 4.4z"></path><path fill="#D82C20" d="M121.8 38.3c-6.7 3.5-41.4 17.7-48.8 21.6-7.4 3.8-11.5 3.8-17.3 1s-42.7-17.6-49.4-20.8-6.8-5.4-.3-7.9c6.5-2.6 43.2-17 51-19.7 7.8-2.8 10.4-2.9 17-.5s41.1 16.1 47.6 18.5c6.7 2.4 6.9 4.4.2 7.8z"></path><path fill="#fff" d="M80.4 26.1l-10.8 1.2-2.5 5.8-3.9-6.5-12.5-1.1 9.3-3.4-2.8-5.2 8.8 3.4 8.2-2.7-2.2 5.4zM66.5 54.5l-20.3-8.4 29.1-4.4z"></path><ellipse cx="38.4" cy="35.4" fill="#fff" rx="15.5" ry="6"></ellipse><path fill="#7A0C00" d="M93.3 27.7l17.2 6.8-17.2 6.8z"></path><path fill="#AD2115" d="M74.3 35.3l19-7.6v13.6l-1.9.8z"></path></svg>
|
||||||
|
After Width: | Height: | Size: 1.8 KiB |
|
|
@ -43,6 +43,7 @@
|
||||||
"google-auth-library": "^9.0.0",
|
"google-auth-library": "^9.0.0",
|
||||||
"graphql": "^16.6.0",
|
"graphql": "^16.6.0",
|
||||||
"html-to-text": "^9.0.5",
|
"html-to-text": "^9.0.5",
|
||||||
|
"ioredis": "^5.3.2",
|
||||||
"langchain": "^0.0.154",
|
"langchain": "^0.0.154",
|
||||||
"langfuse-langchain": "^1.0.14-alpha.0",
|
"langfuse-langchain": "^1.0.14-alpha.0",
|
||||||
"langsmith": "^0.0.32",
|
"langsmith": "^0.0.32",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue