This commit is contained in:
Cedric Ziel 2025-03-05 17:11:55 +01:00 committed by GitHub
commit a48715c475
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 79 additions and 7 deletions

View file

@ -224,6 +224,9 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
let response_format;
if (jsonOutput) {
response_format = { type: 'json_object' };
// o1 family doesn't support system prompt
if (!model?.toString().toLocaleLowerCase().startsWith('o1')) {
messages = [
{
role: 'system',
@ -232,6 +235,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
...messages,
];
}
}
const hideTools = this.getNodeParameter('hideTools', i, '') as string;

View file

@ -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,
},
});
});
});