n8n/packages/@n8n/nodes-langchain/utils/helpers.ts
2024-02-05 16:09:23 +01:00

24 lines
859 B
TypeScript

import type { IExecuteFunctions } from 'n8n-workflow';
import { BaseChatModel } from 'langchain/chat_models/base';
import { BaseChatModel as BaseChatModelCore } from '@langchain/core/language_models/chat_models';
export function getMetadataFiltersValues(
ctx: IExecuteFunctions,
itemIndex: number,
): Record<string, never> | undefined {
const metadata = ctx.getNodeParameter('options.metadata.metadataValues', itemIndex, []) as Array<{
name: string;
value: string;
}>;
if (metadata.length > 0) {
return metadata.reduce((acc, { name, value }) => ({ ...acc, [name]: value }), {});
}
return undefined;
}
// TODO: Remove this function once langchain package is updated to 0.1.x
export function isChatInstance(model: any): model is BaseChatModel | BaseChatModelCore {
return model instanceof BaseChatModel || model instanceof BaseChatModelCore;
}