Update LLMRedisCache.ts

code cleanup
This commit is contained in:
Henry Heng 2023-10-06 23:34:56 +01:00 committed by GitHub
parent 2785e3b685
commit 52ccb89949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 29 deletions

View File

@ -1,13 +1,4 @@
import {
getBaseClasses,
getCredentialData,
getCredentialParam,
ICommonObject,
INode,
INodeData,
INodeOutputsValue,
INodeParams
} from '../../../src'
import { getBaseClasses, getCredentialData, getCredentialParam, ICommonObject, INode, INodeData, INodeParams } from '../../../src'
import { RedisCache } from 'langchain/cache/ioredis'
import { Redis } from 'ioredis'
@ -21,7 +12,6 @@ class LLMRedisCache implements INode {
category: string
baseClasses: string[]
inputs: INodeParams[]
outputs: INodeOutputsValue[]
credential: INodeParams
constructor() {
@ -31,7 +21,7 @@ class LLMRedisCache implements INode {
this.type = 'LLMCache'
this.icon = 'redis.svg'
this.category = 'LLM Cache'
this.baseClasses = [this.type, 'LLMCacheBase']
this.baseClasses = [this.type, ...getBaseClasses(RedisCache)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
@ -40,13 +30,6 @@ class LLMRedisCache implements INode {
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> {
@ -55,18 +38,12 @@ class LLMRedisCache implements INode {
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
port: portStr ? parseInt(portStr) : 6379,
host,
username,
password
})
return new RedisCache(client)
}