UNPKG

@n8n/n8n-nodes-langchain

Version:

![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)

101 lines 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MemoryPostgresChat = void 0; const postgres_1 = require("@langchain/community/stores/message/postgres"); const memory_1 = require("@langchain/classic/memory"); const index_1 = require("n8n-nodes-base/dist/nodes/Postgres/transport/index"); const credentialTest_1 = require("n8n-nodes-base/dist/nodes/Postgres/v2/methods/credentialTest"); const n8n_workflow_1 = require("n8n-workflow"); const helpers_1 = require("../../../utils/helpers"); const ai_utilities_1 = require("@n8n/ai-utilities"); const descriptions_1 = require("../descriptions"); class MemoryPostgresChat { constructor() { this.description = { displayName: 'Postgres Chat Memory', name: 'memoryPostgresChat', icon: 'file:postgres.svg', group: ['transform'], version: [1, 1.1, 1.2, 1.3], description: 'Stores the chat history in Postgres table.', defaults: { name: 'Postgres Chat Memory', }, credentials: [ { name: 'postgres', required: true, testedBy: 'postgresConnectionTest', }, ], codex: { categories: ['AI'], subcategories: { AI: ['Memory'], Memory: ['Other memories'], }, resources: { primaryDocumentation: [ { url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorypostgreschat/', }, ], }, }, inputs: [], outputs: [n8n_workflow_1.NodeConnectionTypes.AiMemory], outputNames: ['Memory'], properties: [ (0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiAgent]), descriptions_1.sessionIdOption, (0, descriptions_1.expressionSessionKeyProperty)(1.2), descriptions_1.sessionKeyProperty, { displayName: 'Table Name', name: 'tableName', type: 'string', default: 'n8n_chat_histories', description: 'The table name to store the chat history in. If table does not exist, it will be created.', }, { ...descriptions_1.contextWindowLengthProperty, displayOptions: { hide: { '@version': [{ _cnd: { lt: 1.1 } }] } }, }, ], }; this.methods = { credentialTest: { postgresConnectionTest: credentialTest_1.postgresConnectionTest, }, }; } async supplyData(itemIndex) { const credentials = await this.getCredentials('postgres'); const tableName = this.getNodeParameter('tableName', itemIndex, 'n8n_chat_histories'); const sessionId = (0, helpers_1.getSessionId)(this, itemIndex); const pgConf = await index_1.configurePostgres.call(this, credentials); const pool = pgConf.db.$pool; const pgChatHistory = new postgres_1.PostgresChatMessageHistory({ pool, sessionId, tableName, }); const memClass = this.getNode().typeVersion < 1.1 ? memory_1.BufferMemory : memory_1.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, }); return { response: (0, ai_utilities_1.logWrapper)(memory, this), }; } } exports.MemoryPostgresChat = MemoryPostgresChat; //# sourceMappingURL=MemoryPostgresChat.node.js.map