diff --git a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts index 18757721c7..f8d1ce2c2a 100644 --- a/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts +++ b/packages/@n8n/nodes-langchain/nodes/vendors/OpenAi/actions/text/message.operation.ts @@ -224,13 +224,17 @@ export async function execute(this: IExecuteFunctions, i: number): Promise { }, }); }); + + it('message => json output, o1 models should not receive system prompt', async () => { + (transport.apiRequest as jest.Mock).mockResolvedValueOnce({ + choices: [{ message: { tool_calls: undefined } }], + }); + + await text.message.execute.call( + createExecuteFunctionsMock({ + modelId: 'o1-mini', + messages: { + values: [{ role: 'user', content: 'message' }], + }, + + jsonOutput: true, + + options: {}, + }), + 0, + ); + + expect(transport.apiRequest).toHaveBeenCalledWith('POST', '/chat/completions', { + body: { + messages: [{ content: 'message', role: 'user' }], + model: 'o1-mini', + response_format: { + type: 'json_object', + }, + tools: undefined, + }, + }); + }); + + it('message => json output, older models should receive system prompt', async () => { + (transport.apiRequest as jest.Mock).mockResolvedValueOnce({ + choices: [{ message: { tool_calls: undefined } }], + }); + + await text.message.execute.call( + createExecuteFunctionsMock({ + modelId: 'gpt-model', + messages: { + values: [{ role: 'user', content: 'message' }], + }, + + jsonOutput: true, + + options: {}, + }), + 0, + ); + + expect(transport.apiRequest).toHaveBeenCalledWith('POST', '/chat/completions', { + body: { + messages: [ + { + role: 'system', + content: 'You are a helpful assistant designed to output JSON.', + }, + { content: 'message', role: 'user' }, + ], + model: 'gpt-model', + response_format: { + type: 'json_object', + }, + tools: undefined, + }, + }); + }); });