diff --git a/packages/components/nodes/memory/MotorheadMemory/MotorheadMemory.ts b/packages/components/nodes/memory/MotorheadMemory/MotorheadMemory.ts new file mode 100644 index 00000000..383ad613 --- /dev/null +++ b/packages/components/nodes/memory/MotorheadMemory/MotorheadMemory.ts @@ -0,0 +1,96 @@ +import { INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses } from '../../../src/utils' +import { ICommonObject } from '../../../src' +import { MotorheadMemory, MotorheadMemoryInput } from 'langchain/memory' + +class MotorMemory_Memory implements INode { + label: string + name: string + description: string + type: string + icon: string + category: string + baseClasses: string[] + inputs: INodeParams[] + + constructor() { + this.label = 'Motorhead Memory' + this.name = 'motorheadMemory' + this.type = 'MotorheadMemory' + this.icon = 'memory.svg' + this.category = 'Memory' + this.description = 'Remembers previous conversational back and forths directly' + this.baseClasses = [this.type, ...getBaseClasses(MotorheadMemory)] + this.inputs = [ + { + label: 'Base URL', + name: 'baseURL', + type: 'string', + optional: true, + description: 'To use the online version, leave the URL blank. More details at https://getmetal.io.' + }, + { + label: 'Memory Key', + name: 'memoryKey', + type: 'string', + default: 'chat_history' + }, + { + label: 'Session Id', + name: 'sessionId', + type: 'string', + description: 'if empty, chatId will be used automatically', + default: '', + additionalParams: true, + optional: true + }, + { + label: 'API Key', + name: 'apiKey', + type: 'string', + optional: true + }, + { + label: 'Client ID', + name: 'clientId', + type: 'string', + optional: true + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const memoryKey = nodeData.inputs?.memoryKey as string + const baseURL = nodeData.inputs?.baseURL as string + const sessionId = nodeData.inputs?.sessionId as string + const apiKey = nodeData.inputs?.apiKey as string + const clientId = nodeData.inputs?.clientId as string + + const chatId = options?.chatId as string + + console.log(chatId) + + let obj: MotorheadMemoryInput = { + returnMessages: true, + sessionId: sessionId ? sessionId : chatId, + memoryKey + } + + if (baseURL) { + obj = { + ...obj, + url: baseURL + } + } else { + obj = { + ...obj, + apiKey, + clientId + } + } + + return new MotorheadMemory(obj) + } +} + +module.exports = { nodeClass: MotorMemory_Memory } diff --git a/packages/components/nodes/memory/MotorheadMemory/memory.svg b/packages/components/nodes/memory/MotorheadMemory/memory.svg new file mode 100644 index 00000000..ca8e17da --- /dev/null +++ b/packages/components/nodes/memory/MotorheadMemory/memory.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file