mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Merge 353a16b2ad
into d2dd1796a8
This commit is contained in:
commit
a48715c475
|
@ -224,13 +224,17 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
|
||||||
let response_format;
|
let response_format;
|
||||||
if (jsonOutput) {
|
if (jsonOutput) {
|
||||||
response_format = { type: 'json_object' };
|
response_format = { type: 'json_object' };
|
||||||
messages = [
|
|
||||||
{
|
// o1 family doesn't support system prompt
|
||||||
role: 'system',
|
if (!model?.toString().toLocaleLowerCase().startsWith('o1')) {
|
||||||
content: 'You are a helpful assistant designed to output JSON.',
|
messages = [
|
||||||
},
|
{
|
||||||
...messages,
|
role: 'system',
|
||||||
];
|
content: 'You are a helpful assistant designed to output JSON.',
|
||||||
|
},
|
||||||
|
...messages,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hideTools = this.getNodeParameter('hideTools', i, '') as string;
|
const hideTools = this.getNodeParameter('hideTools', i, '') as string;
|
||||||
|
|
|
@ -620,4 +620,72 @@ describe('OpenAi, Text resource', () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue