fix: Fix execution error when using AI chain nodes with non-chat model (#8724)

Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
oleg
2024-02-23 10:27:39 +01:00
committed by GitHub
parent d03d9276f9
commit 0882dc0ce9
3 changed files with 50 additions and 59 deletions

View File

@@ -1,4 +1,5 @@
import { NodeConnectionType, type IExecuteFunctions, NodeOperationError } from 'n8n-workflow';
import { NodeConnectionType, NodeOperationError, jsonStringify } from 'n8n-workflow';
import type { EventNamesAiNodesType, IDataObject, IExecuteFunctions } from 'n8n-workflow';
import { BaseChatModel } from 'langchain/chat_models/base';
import { BaseChatModel as BaseChatModelCore } from '@langchain/core/language_models/chat_models';
import type { BaseOutputParser } from '@langchain/core/output_parsers';
@@ -64,3 +65,15 @@ export function getPromptInputByType(options: {
return input;
}
export async function logAiEvent(
executeFunctions: IExecuteFunctions,
event: EventNamesAiNodesType,
data?: IDataObject,
) {
try {
await executeFunctions.logAiEvent(event, data ? jsonStringify(data) : undefined);
} catch (error) {
executeFunctions.logger.debug(`Error logging AI event: ${event}`);
}
}