Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/plugins/compat-oai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ export function toOpenAIRequestBody(
version: modelVersion,
tools: toolsFromConfig,
apiKey,
visualDetailLevel,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While destructuring visualDetailLevel here correctly prevents it from leaking into the OpenAI request body, visualDetailLevel is currently missing from ChatCompletionCommonConfigSchema (defined on line 79). As a result, users do not get autocompletion, type safety, or schema validation for this option. Additionally, VisualDetailLevelSchema (defined on line 70) remains unused dead code.\n\nTo resolve this, consider adding visualDetailLevel to ChatCompletionCommonConfigSchema in js/plugins/compat-oai/src/model.ts:\n\ntypescript\nexport const ChatCompletionCommonConfigSchema =\n GenerationCommonConfigSchema.extend({\n temperature: z.number().min(0).max(2).optional(),\n frequencyPenalty: z.number().min(-2).max(2).optional(),\n logProbs: z.boolean().optional(),\n presencePenalty: z.number().min(-2).max(2).optional(),\n topLogProbs: z.number().int().min(0).max(20).optional(),\n visualDetailLevel: VisualDetailLevelSchema,\n });\n

...restOfConfig
} = request.config ?? {};

Expand Down
41 changes: 41 additions & 0 deletions js/plugins/compat-oai/tests/compat_oai_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading