LLM Cache - Addition of Momento Cache
This commit is contained in:
parent
18702e4c47
commit
4efec94dc8
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||||
|
|
||||||
|
class MomentoCacheApi implements INodeCredential {
|
||||||
|
label: string
|
||||||
|
name: string
|
||||||
|
version: number
|
||||||
|
description: string
|
||||||
|
inputs: INodeParams[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.label = 'Momento Cache API'
|
||||||
|
this.name = 'momentoCacheApi'
|
||||||
|
this.version = 1.0
|
||||||
|
this.description =
|
||||||
|
'Refer to <a target="_blank" href="https://docs.momentohq.com/cache/develop/authentication/api-keys">official guide</a> on how to get API key on Momento'
|
||||||
|
this.inputs = [
|
||||||
|
{
|
||||||
|
label: 'Cache',
|
||||||
|
name: 'momentoCache',
|
||||||
|
type: 'string'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'API Key',
|
||||||
|
name: 'momentoApiKey',
|
||||||
|
type: 'password'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Endpoint',
|
||||||
|
name: 'momentoEndpoint',
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { credClass: MomentoCacheApi }
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
import {
|
||||||
|
getBaseClasses,
|
||||||
|
getCredentialData,
|
||||||
|
getCredentialParam,
|
||||||
|
ICommonObject,
|
||||||
|
INode,
|
||||||
|
INodeData,
|
||||||
|
INodeOutputsValue,
|
||||||
|
INodeParams
|
||||||
|
} from '../../../src'
|
||||||
|
import { MomentoCache } from 'langchain/cache/momento'
|
||||||
|
import { CacheClient, Configurations, CredentialProvider } from '@gomomento/sdk'
|
||||||
|
|
||||||
|
class LLMMomentoCache 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 = 'Momento Cache'
|
||||||
|
this.name = 'momentoCache'
|
||||||
|
this.version = 1.0
|
||||||
|
this.type = 'LLMCache'
|
||||||
|
this.icon = 'momento.png'
|
||||||
|
this.category = 'LLM Cache'
|
||||||
|
this.baseClasses = [this.type, 'LLMCacheBase']
|
||||||
|
this.credential = {
|
||||||
|
label: 'Connect Credential',
|
||||||
|
name: 'credential',
|
||||||
|
type: 'credential',
|
||||||
|
optional: true,
|
||||||
|
credentialNames: ['momentoCacheApi']
|
||||||
|
}
|
||||||
|
this.inputs = []
|
||||||
|
this.outputs = [
|
||||||
|
{
|
||||||
|
label: 'LLM Cache',
|
||||||
|
name: 'cache',
|
||||||
|
baseClasses: [this.type, ...getBaseClasses(MomentoCache)]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||||
|
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||||
|
const apiKey = getCredentialParam('momentoApiKey', credentialData, nodeData)
|
||||||
|
const cacheName = getCredentialParam('momentoCache', credentialData, nodeData)
|
||||||
|
const endPoint = getCredentialParam('momentoEndpoint', credentialData, nodeData)
|
||||||
|
|
||||||
|
// See https://github.com/momentohq/client-sdk-javascript for connection options
|
||||||
|
const client = new CacheClient({
|
||||||
|
configuration: Configurations.Laptop.v1(),
|
||||||
|
credentialProvider: CredentialProvider.fromString({
|
||||||
|
apiKey: apiKey
|
||||||
|
}),
|
||||||
|
defaultTtlSeconds: 60 * 60 * 24
|
||||||
|
})
|
||||||
|
|
||||||
|
let momentoCache = await MomentoCache.fromProps({
|
||||||
|
client,
|
||||||
|
cacheName: cacheName
|
||||||
|
})
|
||||||
|
return momentoCache
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { nodeClass: LLMMomentoCache }
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
|
|
@ -19,6 +19,7 @@
|
||||||
"@aws-sdk/client-dynamodb": "^3.360.0",
|
"@aws-sdk/client-dynamodb": "^3.360.0",
|
||||||
"@dqbd/tiktoken": "^1.0.7",
|
"@dqbd/tiktoken": "^1.0.7",
|
||||||
"@getzep/zep-js": "^0.6.3",
|
"@getzep/zep-js": "^0.6.3",
|
||||||
|
"@gomomento/sdk": "^1.40.2",
|
||||||
"@google-ai/generativelanguage": "^0.2.1",
|
"@google-ai/generativelanguage": "^0.2.1",
|
||||||
"@huggingface/inference": "^2.6.1",
|
"@huggingface/inference": "^2.6.1",
|
||||||
"@notionhq/client": "^2.2.8",
|
"@notionhq/client": "^2.2.8",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue