2023-11-29 03:13:55 -08:00
|
|
|
import type { IExecuteFunctions } from 'n8n-workflow';
|
2024-02-05 07:09:23 -08:00
|
|
|
import { BaseChatModel } from 'langchain/chat_models/base';
|
|
|
|
import { BaseChatModel as BaseChatModelCore } from '@langchain/core/language_models/chat_models';
|
2023-11-29 03:13:55 -08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-02-05 07:09:23 -08:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|