diff --git a/js/plugins/compat-oai/src/model.ts b/js/plugins/compat-oai/src/model.ts index c5c7df7a96..1c5070e140 100644 --- a/js/plugins/compat-oai/src/model.ts +++ b/js/plugins/compat-oai/src/model.ts @@ -578,6 +578,7 @@ export function toOpenAIRequestBody( version: modelVersion, tools: toolsFromConfig, apiKey, + visualDetailLevel, ...restOfConfig } = request.config ?? {}; diff --git a/js/plugins/compat-oai/tests/compat_oai_test.ts b/js/plugins/compat-oai/tests/compat_oai_test.ts index 47ba29c5de..a9209c769f 100644 --- a/js/plugins/compat-oai/tests/compat_oai_test.ts +++ b/js/plugins/compat-oai/tests/compat_oai_test.ts @@ -1500,6 +1500,47 @@ describe('toOpenAiRequestBody', () => { }, }); }); + + it('applies visualDetailLevel to image URLs without leaking it into the request body', () => { + const request = { + messages: [ + { + role: 'user', + content: [ + { text: 'describe this image' }, + { + media: { + contentType: 'image/jpeg', + url: 'https://example.com/image.jpg', + }, + }, + ], + }, + ], + config: { + visualDetailLevel: 'high', + }, + } as GenerateRequest; + + const actualOutput = toOpenAIRequestBody('gpt-4o', request); + + expect(actualOutput).not.toHaveProperty('visualDetailLevel'); + expect(actualOutput.messages).toStrictEqual([ + { + role: 'user', + content: [ + { type: 'text', text: 'describe this image' }, + { + type: 'image_url', + image_url: { + url: 'https://example.com/image.jpg', + detail: 'high', + }, + }, + ], + }, + ]); + }); }); describe('openAIModelRunner', () => {