| 3 | import { getBaseClasses, getCredentialData, getCredentialParam, ICommonObject, INode, INodeData, INodeParams } from '../../../src' |
| 4 | |
| 5 | class MomentoCache implements INode { |
| 6 | label: string |
| 7 | name: string |
| 8 | version: number |
| 9 | description: string |
| 10 | type: string |
| 11 | icon: string |
| 12 | category: string |
| 13 | baseClasses: string[] |
| 14 | inputs: INodeParams[] |
| 15 | credential: INodeParams |
| 16 | |
| 17 | constructor() { |
| 18 | this.label = 'Momento Cache' |
| 19 | this.name = 'momentoCache' |
| 20 | this.version = 1.0 |
| 21 | this.type = 'MomentoCache' |
| 22 | this.description = 'Cache LLM response using Momento, a distributed, serverless cache' |
| 23 | this.icon = 'Momento.svg' |
| 24 | this.category = 'Cache' |
| 25 | this.baseClasses = [this.type, ...getBaseClasses(LangchainMomentoCache)] |
| 26 | this.credential = { |
| 27 | label: 'Connect Credential', |
| 28 | name: 'credential', |
| 29 | type: 'credential', |
| 30 | optional: true, |
| 31 | credentialNames: ['momentoCacheApi'] |
| 32 | } |
| 33 | this.inputs = [] |
| 34 | } |
| 35 | |
| 36 | async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { |
| 37 | const credentialData = await getCredentialData(nodeData.credential ?? '', options) |
| 38 | const apiKey = getCredentialParam('momentoApiKey', credentialData, nodeData) |
| 39 | const cacheName = getCredentialParam('momentoCache', credentialData, nodeData) |
| 40 | |
| 41 | // See https://github.com/momentohq/client-sdk-javascript for connection options |
| 42 | const client = new CacheClient({ |
| 43 | configuration: Configurations.Laptop.v1(), |
| 44 | credentialProvider: CredentialProvider.fromString({ |
| 45 | apiKey: apiKey |
| 46 | }), |
| 47 | defaultTtlSeconds: 60 * 60 * 24 |
| 48 | }) |
| 49 | |
| 50 | let momentoCache = await LangchainMomentoCache.fromProps({ |
| 51 | client, |
| 52 | cacheName: cacheName |
| 53 | }) |
| 54 | return momentoCache |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | module.exports = { nodeClass: MomentoCache } |
nothing calls this directly
no outgoing calls
no test coverage detected