mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(AI Agent Node): Prevent adding empty binary message (#14871)
This commit is contained in:
@@ -365,7 +365,11 @@ export async function prepareMessages(
|
|||||||
const hasBinaryData = ctx.getInputData()?.[itemIndex]?.binary !== undefined;
|
const hasBinaryData = ctx.getInputData()?.[itemIndex]?.binary !== undefined;
|
||||||
if (hasBinaryData && options.passthroughBinaryImages) {
|
if (hasBinaryData && options.passthroughBinaryImages) {
|
||||||
const binaryMessage = await extractBinaryMessages(ctx, itemIndex);
|
const binaryMessage = await extractBinaryMessages(ctx, itemIndex);
|
||||||
messages.push(binaryMessage);
|
if (binaryMessage.content.length !== 0) {
|
||||||
|
messages.push(binaryMessage);
|
||||||
|
} else {
|
||||||
|
ctx.logger.debug('Not attaching binary message, since its content was empty');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We add the agent scratchpad last, so that the agent will not run in loops
|
// We add the agent scratchpad last, so that the agent will not run in loops
|
||||||
|
|||||||
@@ -233,6 +233,33 @@ describe('prepareMessages', () => {
|
|||||||
expect(hasHumanMessage).toBe(false);
|
expect(hasHumanMessage).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not include a binary message if no image data is present', async () => {
|
||||||
|
const fakeItem = {
|
||||||
|
json: {},
|
||||||
|
binary: {
|
||||||
|
img1: {
|
||||||
|
mimeType: 'application/pdf',
|
||||||
|
data: 'data:application/pdf;base64,sampledata',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
mockContext.getInputData.mockReturnValue([fakeItem]);
|
||||||
|
mockContext.logger = {
|
||||||
|
debug: jest.fn(),
|
||||||
|
info: jest.fn(),
|
||||||
|
warn: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const messages = await prepareMessages(mockContext, 0, {
|
||||||
|
systemMessage: 'Test system',
|
||||||
|
passthroughBinaryImages: true,
|
||||||
|
});
|
||||||
|
const hasHumanMessage = messages.some((m) => m instanceof HumanMessage);
|
||||||
|
expect(hasHumanMessage).toBe(false);
|
||||||
|
expect(mockContext.logger.debug).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('should not include system_message in prompt templates if not provided after version 1.9', async () => {
|
it('should not include system_message in prompt templates if not provided after version 1.9', async () => {
|
||||||
const fakeItem = { json: {} };
|
const fakeItem = { json: {} };
|
||||||
const mockNode = mock<INode>();
|
const mockNode = mock<INode>();
|
||||||
|
|||||||
Reference in New Issue
Block a user