mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
⚠️ refactor: Use Error Content Part Instead Of Throwing Error for Agents (#6262)
This commit is contained in:
parent
3e3dfe5bad
commit
d6ab769b80
4 changed files with 45 additions and 2 deletions
|
@ -325,4 +325,37 @@ describe('formatAgentMessages', () => {
|
||||||
);
|
);
|
||||||
expect(result[0].content).not.toContain('Analyzing the problem...');
|
expect(result[0].content).not.toContain('Analyzing the problem...');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should exclude ERROR type content parts', () => {
|
||||||
|
const payload = [
|
||||||
|
{
|
||||||
|
role: 'assistant',
|
||||||
|
content: [
|
||||||
|
{ type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Hello there' },
|
||||||
|
{
|
||||||
|
type: ContentTypes.ERROR,
|
||||||
|
[ContentTypes.ERROR]:
|
||||||
|
'An error occurred while processing the request: Something went wrong',
|
||||||
|
},
|
||||||
|
{ type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Final answer' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = formatAgentMessages(payload);
|
||||||
|
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0]).toBeInstanceOf(AIMessage);
|
||||||
|
expect(result[0].content).toEqual([
|
||||||
|
{ type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Hello there' },
|
||||||
|
{ type: ContentTypes.TEXT, [ContentTypes.TEXT]: 'Final answer' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Make sure no error content exists in the result
|
||||||
|
const hasErrorContent = result[0].content.some(
|
||||||
|
(item) =>
|
||||||
|
item.type === ContentTypes.ERROR || JSON.stringify(item).includes('An error occurred'),
|
||||||
|
);
|
||||||
|
expect(hasErrorContent).toBe(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -211,6 +211,8 @@ const formatAgentMessages = (payload) => {
|
||||||
} else if (part.type === ContentTypes.THINK) {
|
} else if (part.type === ContentTypes.THINK) {
|
||||||
hasReasoning = true;
|
hasReasoning = true;
|
||||||
continue;
|
continue;
|
||||||
|
} else if (part.type === ContentTypes.ERROR) {
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
currentContent.push(part);
|
currentContent.push(part);
|
||||||
}
|
}
|
||||||
|
|
|
@ -812,7 +812,10 @@ class AgentClient extends BaseClient {
|
||||||
'[api/server/controllers/agents/client.js #sendCompletion] Unhandled error type',
|
'[api/server/controllers/agents/client.js #sendCompletion] Unhandled error type',
|
||||||
err,
|
err,
|
||||||
);
|
);
|
||||||
throw err;
|
this.contentParts.push({
|
||||||
|
type: ContentTypes.ERROR,
|
||||||
|
[ContentTypes.ERROR]: `An error occurred while processing the request${err?.message ? `: ${err.message}` : ''}`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,12 @@ const Part = memo(({ part, isSubmitting, attachments, showCursor, isCreatedByUse
|
||||||
}
|
}
|
||||||
|
|
||||||
if (part.type === ContentTypes.ERROR) {
|
if (part.type === ContentTypes.ERROR) {
|
||||||
return <ErrorMessage text={part[ContentTypes.TEXT].value} className="my-2" />;
|
return (
|
||||||
|
<ErrorMessage
|
||||||
|
text={part[ContentTypes.ERROR] ?? part[ContentTypes.TEXT]?.value}
|
||||||
|
className="my-2"
|
||||||
|
/>
|
||||||
|
);
|
||||||
} else if (part.type === ContentTypes.TEXT) {
|
} else if (part.type === ContentTypes.TEXT) {
|
||||||
const text = typeof part.text === 'string' ? part.text : part.text.value;
|
const text = typeof part.text === 'string' ? part.text : part.text.value;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue