From cddc68c187d6e430e1dce85497c8ff254caeb0a2 Mon Sep 17 00:00:00 2001 From: vinodkiran Date: Fri, 6 Oct 2023 13:17:56 +0530 Subject: [PATCH] LLM Cache - Addition of Upstash Redis --- .../credentials/UpstashRedisApi.credential.ts | 28 ++++++++ .../LLMUpstashRedisCache.ts | 66 ++++++++++++++++++ .../llmcache/LLMUpstashRedisCache/upstash.png | Bin 0 -> 2698 bytes packages/components/package.json | 3 +- 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 packages/components/credentials/UpstashRedisApi.credential.ts create mode 100644 packages/components/nodes/llmcache/LLMUpstashRedisCache/LLMUpstashRedisCache.ts create mode 100644 packages/components/nodes/llmcache/LLMUpstashRedisCache/upstash.png diff --git a/packages/components/credentials/UpstashRedisApi.credential.ts b/packages/components/credentials/UpstashRedisApi.credential.ts new file mode 100644 index 00000000..b6e62ff3 --- /dev/null +++ b/packages/components/credentials/UpstashRedisApi.credential.ts @@ -0,0 +1,28 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class UpstashRedisApi implements INodeCredential { + label: string + name: string + version: number + inputs: INodeParams[] + + constructor() { + this.label = 'Upstash Redis API' + this.name = 'upstashRedisApi' + this.version = 1.0 + this.inputs = [ + { + label: 'Upstash Redis REST URL', + name: 'upstashConnectionUrl', + type: 'string' + }, + { + label: 'Token', + name: 'upstashConnectionToken', + type: 'password' + } + ] + } +} + +module.exports = { credClass: UpstashRedisApi } diff --git a/packages/components/nodes/llmcache/LLMUpstashRedisCache/LLMUpstashRedisCache.ts b/packages/components/nodes/llmcache/LLMUpstashRedisCache/LLMUpstashRedisCache.ts new file mode 100644 index 00000000..b16d6e13 --- /dev/null +++ b/packages/components/nodes/llmcache/LLMUpstashRedisCache/LLMUpstashRedisCache.ts @@ -0,0 +1,66 @@ +import { + getBaseClasses, + getCredentialData, + getCredentialParam, + ICommonObject, + INode, + INodeData, + INodeOutputsValue, + INodeParams +} from '../../../src' +import { UpstashRedisCache } from 'langchain/cache/upstash_redis' + +class LLMUpstashRedisCache 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 = 'Upstash Redis LLM Cache' + this.name = 'upstashRedisCache' + this.version = 1.0 + this.type = 'LLMCache' + this.icon = 'upstash.png' + this.category = 'LLM Cache' + this.baseClasses = [this.type, 'LLMCacheBase'] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + optional: true, + credentialNames: ['upstashRedisApi'] + } + this.inputs = [] + this.outputs = [ + { + label: 'LLM Cache', + name: 'cache', + baseClasses: [this.type, ...getBaseClasses(UpstashRedisCache)] + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const upstashConnectionUrl = getCredentialParam('upstashConnectionUrl', credentialData, nodeData) + const upstashToken = getCredentialParam('upstashConnectionToken', credentialData, nodeData) + + const cache = new UpstashRedisCache({ + config: { + url: upstashConnectionUrl, + token: upstashToken + } + }) + return cache + } +} + +module.exports = { nodeClass: LLMUpstashRedisCache } diff --git a/packages/components/nodes/llmcache/LLMUpstashRedisCache/upstash.png b/packages/components/nodes/llmcache/LLMUpstashRedisCache/upstash.png new file mode 100644 index 0000000000000000000000000000000000000000..e27e02f4a3ba635cf04a33dbcfaa1a8e973ee2cc GIT binary patch literal 2698 zcmV;53U&2~P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!~g&e!~vBn4jTXf3Li;CK~z{rwODCv zRM#0jGhW6X+he@o1>0b-OTb{u1PC;ViGm<$NE4*0qHWrS0!gY?irP|KO4>->)$*rJ zgj#~s$`MLYnkFhK6bK=TB1l>j63k}sg24;M9`E+-i+jHN-psriKgT9Yj`cjA``)|v z+;2JGcWs#@@EM@fH-<}|K@0{xa0a{>341XX^1~YrBCJ1?3=1-oQjyJTPI4NGlkF%- zv7^>LSB=kvPfgYx4B+r+JKmq@MT>6)nbs7f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z@Cwgu7w|C~6tKCDCrWQon#R`drl$HQo}wO#DIBn*xWwBVM1SZg*oiCUaxS7p1%lZ?p`M7kwzEDq95@&1L{XV^EGmt)JB z-)Qd}&vd?V)R*3mz2)oG*J;T{aFA8#NeVoqp-~z-O>!hcre$*kO50jTIZiEmLiMj^ z*vOE1d$?6A9udgqT~16s_yD#@&U>hNibN5NKo@$Z}b$F z`z8;4&$1`|Jn=C%`8ZwQ%|055|FvOxuX8NGd)4f96A&fa(BFh@SJ>gu!zFAwUgWO6 zl6RMS=(B>0WqBj5`2o8yMbemvLc>3bhq5bh!i1>6((iXo)-i#u@mv&jhr}K;F(bu} z?@*%tz--Jg>farrfwBG<_Op#F6kw>RcsD}goT^h_whnt)wx@$-d+U+OzjeOL!dx(Q z5|uEND0W{-T;vIs)^eWn*E{B;iV`HvhY`}>Ho5!p(fBRAKi-LREYVHsoFz)aXA?`Z z%ulyxQf1E7Y{%khDq93947z+{c(nPSxHv-jP&+q~7@0Uio+n$db<;W|Q3GCbPsoS| znC zg%Fg@G1DvPou8K0;i znH(~K9E0*%YRh=sDQ2cu+vcFq=D<3}dDSeA<}(BMKR;-3TtO!==>Px#07*qoM6N<$ Ef=GE79{>OV literal 0 HcmV?d00001 diff --git a/packages/components/package.json b/packages/components/package.json index 5e993f86..e3c4380a 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -29,6 +29,7 @@ "@supabase/supabase-js": "^2.29.0", "@types/js-yaml": "^4.0.5", "@types/jsdom": "^21.1.1", + "@upstash/redis": "^1.22.1", "@zilliz/milvus2-sdk-node": "^2.2.24", "apify-client": "^2.7.1", "axios": "^0.27.2", @@ -44,7 +45,7 @@ "graphql": "^16.6.0", "html-to-text": "^9.0.5", "ioredis": "^5.3.2", - "langchain": "^0.0.154", + "langchain": "^0.0.157", "langfuse-langchain": "^1.0.14-alpha.0", "langsmith": "^0.0.32", "linkifyjs": "^4.1.1",