Skip to content
Merged
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
4 changes: 3 additions & 1 deletion js/plugins/compat-oai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ export function toOpenAITextAndMedia(
}

// Check if this is an image type
if (isImageContentType(contentType)) {
// If no contentType is provided, preserve legacy behavior by treating the media
// as an image URL (e.g. signed URLs or remote images without metadata)
if (!contentType || isImageContentType(contentType)) {
return {
type: 'image_url',
image_url: {
Expand Down
15 changes: 15 additions & 0 deletions js/plugins/compat-oai/tests/compat_oai_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ describe('toOpenAiTextAndMedia', () => {
});
});

it('should transform image from signed URLs', () => {
const part: Part = {
media: {
url: 'https://storage.googleapis.com/bucket/image.png?X-Goog-Signature=fake',
},
};
expect(toOpenAITextAndMedia(part, 'low')).toStrictEqual({
type: 'image_url',
image_url: {
url: 'https://storage.googleapis.com/bucket/image.png?X-Goog-Signature=fake',
detail: 'low',
},
});
});

it('should throw error for file URLs (non-base64 PDFs)', () => {
const part: Part = {
media: {
Expand Down