mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(Postgres Chat Memory Node): Implement Postgres Chat Memory node (#10071)
This commit is contained in:
@@ -10,6 +10,18 @@ import type { BaseOutputParser } from '@langchain/core/output_parsers';
|
||||
import type { BaseMessage } from '@langchain/core/messages';
|
||||
import { DynamicTool, type Tool } from '@langchain/core/tools';
|
||||
import type { BaseLLM } from '@langchain/core/language_models/llms';
|
||||
import type { BaseChatMemory } from 'langchain/memory';
|
||||
import type { BaseChatMessageHistory } from '@langchain/core/chat_history';
|
||||
|
||||
function hasMethods<T>(obj: unknown, ...methodNames: Array<string | symbol>): obj is T {
|
||||
return methodNames.every(
|
||||
(methodName) =>
|
||||
typeof obj === 'object' &&
|
||||
obj !== null &&
|
||||
methodName in obj &&
|
||||
typeof (obj as Record<string | symbol, unknown>)[methodName] === 'function',
|
||||
);
|
||||
}
|
||||
|
||||
export function getMetadataFiltersValues(
|
||||
ctx: IExecuteFunctions,
|
||||
@@ -38,8 +50,16 @@ export function getMetadataFiltersValues(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function isBaseChatMemory(obj: unknown) {
|
||||
return hasMethods<BaseChatMemory>(obj, 'loadMemoryVariables', 'saveContext');
|
||||
}
|
||||
|
||||
export function isBaseChatMessageHistory(obj: unknown) {
|
||||
return hasMethods<BaseChatMessageHistory>(obj, 'getMessages', 'addMessage');
|
||||
}
|
||||
|
||||
export function isChatInstance(model: unknown): model is BaseChatModel {
|
||||
const namespace = (model as BaseLLM | BaseChatModel)?.lc_namespace ?? [];
|
||||
const namespace = (model as BaseLLM)?.lc_namespace ?? [];
|
||||
|
||||
return namespace.includes('chat_models');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user