mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
feat(Postgres Chat Memory, Redis Chat Memory, Xata): Add support for context window length (#10203)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable n8n-nodes-base/node-dirname-against-convention */
|
||||
import type { IExecuteFunctions, INodeType, INodeTypeDescription, SupplyData } from 'n8n-workflow';
|
||||
import { NodeConnectionType } from 'n8n-workflow';
|
||||
import { BufferMemory } from 'langchain/memory';
|
||||
import { BufferMemory, BufferWindowMemory } from 'langchain/memory';
|
||||
import { PostgresChatMessageHistory } from '@langchain/community/stores/message/postgres';
|
||||
import type pg from 'pg';
|
||||
import { configurePostgres } from 'n8n-nodes-base/dist/nodes/Postgres/v2/transport';
|
||||
@@ -9,7 +9,7 @@ import type { PostgresNodeCredentials } from 'n8n-nodes-base/dist/nodes/Postgres
|
||||
import { postgresConnectionTest } from 'n8n-nodes-base/dist/nodes/Postgres/v2/methods/credentialTest';
|
||||
import { logWrapper } from '../../../utils/logWrapper';
|
||||
import { getConnectionHintNoticeField } from '../../../utils/sharedFields';
|
||||
import { sessionIdOption, sessionKeyProperty } from '../descriptions';
|
||||
import { sessionIdOption, sessionKeyProperty, contextWindowLengthProperty } from '../descriptions';
|
||||
import { getSessionId } from '../../../utils/helpers';
|
||||
|
||||
export class MemoryPostgresChat implements INodeType {
|
||||
@@ -18,7 +18,7 @@ export class MemoryPostgresChat implements INodeType {
|
||||
name: 'memoryPostgresChat',
|
||||
icon: 'file:postgres.svg',
|
||||
group: ['transform'],
|
||||
version: [1],
|
||||
version: [1, 1.1],
|
||||
description: 'Stores the chat history in Postgres table.',
|
||||
defaults: {
|
||||
name: 'Postgres Chat Memory',
|
||||
@@ -60,6 +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,
|
||||
displayOptions: { hide: { '@version': [{ _cnd: { lt: 1.1 } }] } },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -83,12 +87,19 @@ export class MemoryPostgresChat implements INodeType {
|
||||
tableName,
|
||||
});
|
||||
|
||||
const memory = new BufferMemory({
|
||||
const memClass = this.getNode().typeVersion < 1.1 ? BufferMemory : BufferWindowMemory;
|
||||
const kOptions =
|
||||
this.getNode().typeVersion < 1.1
|
||||
? {}
|
||||
: { k: this.getNodeParameter('contextWindowLength', itemIndex) };
|
||||
|
||||
const memory = new memClass({
|
||||
memoryKey: 'chat_history',
|
||||
chatHistory: pgChatHistory,
|
||||
returnMessages: true,
|
||||
inputKey: 'input',
|
||||
outputKey: 'output',
|
||||
...kOptions,
|
||||
});
|
||||
|
||||
async function closeFunction() {
|
||||
|
||||
Reference in New Issue
Block a user