diff --git a/src/media-understanding/image-input-normalize.ts b/src/media-understanding/image-input-normalize.ts index 956aaf384b1..45c2046afd6 100644 --- a/src/media-understanding/image-input-normalize.ts +++ b/src/media-understanding/image-input-normalize.ts @@ -1,11 +1,11 @@ -import { extractImageContentFromSource } from "../media/input-files.js"; +import { extractImageContentFromSource, normalizeMimeType } from "../media/input-files.js"; import { DEFAULT_MAX_BYTES } from "./defaults.constants.js"; const HEIC_MIME_RE = /^image\/hei[cf]$/i; const HEIC_EXT_RE = /\.(heic|heif)$/i; function isHeicInput(params: { mime?: string; fileName?: string }): boolean { - const mime = params.mime?.trim(); + const mime = normalizeMimeType(params.mime); if (mime && HEIC_MIME_RE.test(mime)) { return true; } @@ -22,7 +22,7 @@ export async function normalizeImageDescriptionInput(params: { if (!isHeicInput(params)) { return { buffer: params.buffer, mime: params.mime }; } - const sourceMime = params.mime?.trim() || "image/heic"; + const sourceMime = normalizeMimeType(params.mime) ?? "image/heic"; const image = await extractImageContentFromSource( { type: "base64", diff --git a/src/media-understanding/runtime.test.ts b/src/media-understanding/runtime.test.ts index e8d274531ed..fe84e683542 100644 --- a/src/media-understanding/runtime.test.ts +++ b/src/media-understanding/runtime.test.ts @@ -476,8 +476,8 @@ describe("media-understanding runtime", () => { mocks.readLocalFileSafely.mockResolvedValue({ buffer: Buffer.from("heic-source") }); await describeImageFileWithModel({ - filePath: "/tmp/sample.heic", - mime: "image/heic", + filePath: "/tmp/sample.bin", + mime: "image/heic; charset=binary", provider: "zai", model: "glm-4.6v", prompt: "Describe it", @@ -489,7 +489,7 @@ describe("media-understanding runtime", () => { expect(mocks.describeImageWithModel).toHaveBeenCalledWith( expect.objectContaining({ buffer: Buffer.from("jpeg-normalized"), - fileName: "sample.heic", + fileName: "sample.bin", mime: "image/jpeg", }), );