From a570893a161b8972286ee3c2fa55a6f0a958f466 Mon Sep 17 00:00:00 2001 From: ivalkshfoeif Date: Thu, 6 Jul 2023 16:20:21 -0700 Subject: [PATCH 1/2] add motorhead memory --- .../memory/MotorheadMemory/MotorheadMemory.ts | 96 +++++++++++++++++++ .../nodes/memory/MotorheadMemory/memory.svg | 8 ++ 2 files changed, 104 insertions(+) create mode 100644 packages/components/nodes/memory/MotorheadMemory/MotorheadMemory.ts create mode 100644 packages/components/nodes/memory/MotorheadMemory/memory.svg 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 From f306b89484c1fe72f7d333ef01335d03abfeb47e Mon Sep 17 00:00:00 2001 From: ivalkshfoeif Date: Mon, 10 Jul 2023 00:36:52 -0700 Subject: [PATCH 2/2] fix lint error and update apikey and clientid attributes --- .../nodes/memory/MotorheadMemory/MotorheadMemory.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/memory/MotorheadMemory/MotorheadMemory.ts b/packages/components/nodes/memory/MotorheadMemory/MotorheadMemory.ts index 383ad613..d50b7064 100644 --- a/packages/components/nodes/memory/MotorheadMemory/MotorheadMemory.ts +++ b/packages/components/nodes/memory/MotorheadMemory/MotorheadMemory.ts @@ -48,12 +48,16 @@ class MotorMemory_Memory implements INode { label: 'API Key', name: 'apiKey', type: 'string', + description: 'Only needed when using hosted solution - https://getmetal.io', + additionalParams: true, optional: true }, { label: 'Client ID', name: 'clientId', type: 'string', + description: 'Only needed when using hosted solution - https://getmetal.io', + additionalParams: true, optional: true } ] @@ -68,8 +72,6 @@ class MotorMemory_Memory implements INode { const chatId = options?.chatId as string - console.log(chatId) - let obj: MotorheadMemoryInput = { returnMessages: true, sessionId: sessionId ? sessionId : chatId,