mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(OpenAI Node): Throw node operations error in case of openAi client error (#10448)
Co-authored-by: Shireen Missi <shireen@n8n.io>
This commit is contained in:
@@ -4,7 +4,12 @@ import { OpenAIAssistantRunnable } from 'langchain/experimental/openai_assistant
|
||||
import type { OpenAIToolType } from 'langchain/dist/experimental/openai_assistant/schema';
|
||||
import { OpenAI as OpenAIClient } from 'openai';
|
||||
|
||||
import { NodeConnectionType, NodeOperationError, updateDisplayOptions } from 'n8n-workflow';
|
||||
import {
|
||||
ApplicationError,
|
||||
NodeConnectionType,
|
||||
NodeOperationError,
|
||||
updateDisplayOptions,
|
||||
} from 'n8n-workflow';
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
@@ -228,25 +233,36 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
|
||||
}
|
||||
}
|
||||
|
||||
const response = await agentExecutor.withConfig(getTracingConfig(this)).invoke(chainValues);
|
||||
if (memory) {
|
||||
await memory.saveContext({ input }, { output: response.output });
|
||||
let filteredResponse: IDataObject = {};
|
||||
try {
|
||||
const response = await agentExecutor.withConfig(getTracingConfig(this)).invoke(chainValues);
|
||||
if (memory) {
|
||||
await memory.saveContext({ input }, { output: response.output });
|
||||
|
||||
if (response.threadId && response.runId) {
|
||||
const threadRun = await client.beta.threads.runs.retrieve(response.threadId, response.runId);
|
||||
response.usage = threadRun.usage;
|
||||
if (response.threadId && response.runId) {
|
||||
const threadRun = await client.beta.threads.runs.retrieve(
|
||||
response.threadId,
|
||||
response.runId,
|
||||
);
|
||||
response.usage = threadRun.usage;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
options.preserveOriginalTools !== false &&
|
||||
nodeVersion >= 1.3 &&
|
||||
(assistantTools ?? [])?.length
|
||||
) {
|
||||
await client.beta.assistants.update(assistantId, {
|
||||
tools: assistantTools,
|
||||
});
|
||||
}
|
||||
filteredResponse = omit(response, ['signal', 'timeout']) as IDataObject;
|
||||
} catch (error) {
|
||||
if (!(error instanceof ApplicationError)) {
|
||||
throw new NodeOperationError(this.getNode(), error.message, { itemIndex: i });
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
options.preserveOriginalTools !== false &&
|
||||
nodeVersion >= 1.3 &&
|
||||
(assistantTools ?? [])?.length
|
||||
) {
|
||||
await client.beta.assistants.update(assistantId, {
|
||||
tools: assistantTools,
|
||||
});
|
||||
}
|
||||
const filteredResponse = omit(response, ['signal', 'timeout']);
|
||||
return [{ json: filteredResponse, pairedItem: { item: i } }];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user