From 68a51a6cd9df392f81e6b8cf51a54465a04d346e Mon Sep 17 00:00:00 2001 From: JP van Oosten Date: Mon, 5 Aug 2024 17:03:57 +0200 Subject: [PATCH] Use simple object instead of function; use correct version in redis node --- .../MemoryBufferWindow.node.ts | 2 +- .../MemoryPostgresChat.node.ts | 5 ++++- .../MemoryRedisChat/MemoryRedisChat.node.ts | 9 ++++++--- .../nodes/memory/MemoryXata/MemoryXata.node.ts | 5 ++++- .../nodes/memory/descriptions.ts | 17 +++++++---------- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts index 58495353de169..b8eea7a5e2c82 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts @@ -130,7 +130,7 @@ export class MemoryBufferWindow implements INodeType { }, }, sessionKeyProperty, - contextWindowLengthProperty(), + contextWindowLengthProperty, ], }; diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts index 9f3626e392cd1..b1a9cd7aeaec5 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts @@ -60,7 +60,10 @@ export class MemoryPostgresChat implements INodeType { description: 'The table name to store the chat history in. If table does not exist, it will be created.', }, - contextWindowLengthProperty({ hide: { '@version': [{ _cnd: { lt: 1.1 } }] } }), + { + ...contextWindowLengthProperty, + displayOptions: { hide: { '@version': [{ _cnd: { lt: 1.1 } }] } }, + }, ], }; diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts index e4a435cf08729..da57ede1d2315 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts @@ -95,7 +95,10 @@ export class MemoryRedisChat implements INodeType { description: 'For how long the session should be stored in seconds. If set to 0 it will not expire.', }, - contextWindowLengthProperty({ hide: { '@version': [{ _cnd: { lt: 1.3 } }] } }), + { + ...contextWindowLengthProperty, + displayOptions: { hide: { '@version': [{ _cnd: { lt: 1.3 } }] } }, + }, ], }; @@ -144,9 +147,9 @@ export class MemoryRedisChat implements INodeType { } const redisChatHistory = new RedisChatMessageHistory(redisChatConfig); - const memClass = this.getNode().typeVersion < 1.1 ? BufferMemory : BufferWindowMemory; + const memClass = this.getNode().typeVersion < 1.3 ? BufferMemory : BufferWindowMemory; const kOptions = - this.getNode().typeVersion < 1.1 + this.getNode().typeVersion < 1.3 ? {} : { k: this.getNodeParameter('contextWindowLength', itemIndex) }; diff --git a/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts b/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts index dc8702854c645..f0177d9e75e8b 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/MemoryXata/MemoryXata.node.ts @@ -81,7 +81,10 @@ export class MemoryXata implements INodeType { }, }, sessionKeyProperty, - contextWindowLengthProperty({ hide: { '@version': [{ _cnd: { lt: 1.3 } }] } }), + { + ...contextWindowLengthProperty, + displayOptions: { hide: { '@version': [{ _cnd: { lt: 1.3 } }] } }, + }, ], }; diff --git a/packages/@n8n/nodes-langchain/nodes/memory/descriptions.ts b/packages/@n8n/nodes-langchain/nodes/memory/descriptions.ts index 28f7296006f13..6a5f7268511fa 100644 --- a/packages/@n8n/nodes-langchain/nodes/memory/descriptions.ts +++ b/packages/@n8n/nodes-langchain/nodes/memory/descriptions.ts @@ -34,13 +34,10 @@ export const sessionKeyProperty: INodeProperties = { }, }; -export function contextWindowLengthProperty(displayOptions?: IDisplayOptions): INodeProperties { - return { - displayName: 'Context Window Length', - name: 'contextWindowLength', - type: 'number', - default: 5, - hint: 'How many past interactions the model receives as context', - displayOptions: displayOptions ?? {}, - }; -} +export const contextWindowLengthProperty: INodeProperties = { + displayName: 'Context Window Length', + name: 'contextWindowLength', + type: 'number', + default: 5, + hint: 'How many past interactions the model receives as context', +};