fix: Update BaseChatModel import checks for MistralAI compatibility (#8527)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
oleg
2024-02-05 16:09:23 +01:00
committed by GitHub
parent b62c1d7c41
commit c8b8379015
5 changed files with 18 additions and 11 deletions

View File

@@ -1,4 +1,6 @@
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,
@@ -14,3 +16,8 @@ export function getMetadataFiltersValues(
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;
}

View File

@@ -27,6 +27,7 @@ import { BaseOutputParser } from 'langchain/schema/output_parser';
import { isObject } from 'lodash';
import { N8nJsonLoader } from './N8nJsonLoader';
import { N8nBinaryLoader } from './N8nBinaryLoader';
import { isChatInstance } from './helpers';
const errorsMap: { [key: string]: { message: string; description: string } } = {
'You exceeded your current quota, please check your plan and billing details.': {
@@ -225,7 +226,7 @@ export function logWrapper(
}
// ========== BaseChatModel ==========
if (originalInstance instanceof BaseLLM || originalInstance instanceof BaseChatModel) {
if (originalInstance instanceof BaseLLM || isChatInstance(originalInstance)) {
if (prop === '_generate' && '_generate' in target) {
return async (
messages: BaseMessage[] & string[],