Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: say when an attached image is over the 20 MB limit (#14538)
Nilay3ba06aa596cd
diff --git a/studio/frontend/src/features/chat/image-normalize.ts b/studio/frontend/src/features/chat/image-normalize.tsindex a8705000245..2bcb5a240f3 100644--- a/studio/frontend/src/features/chat/image-normalize.ts+++ b/studio/frontend/src/features/chat/image-normalize.ts@@ -55,7 +55,17 @@ export function convertedImageType(file: {return kind === null ? null : (CONVERTED_IMAGE_TYPES[kind] ?? null);}-const MAX_CONVERTED_IMAGE_BYTES = 20 * 1024 * 1024;+const MAX_CHAT_IMAGE_BYTES = 20 * 1024 * 1024;++export function getChatImageSizeError(file: {+ name: string;+ size: number;+}): string | null {+ return file.size > MAX_CHAT_IMAGE_BYTES+ ? `${file.name} is over the 20 MB image limit.`+ : null;+}+// iOS Safari, the one browser that decodes HEIC, refuses canvases past 16.7 megapixels.const MAX_CONVERTED_IMAGE_PIXELS = 16_777_216;@@ -99,7 +109,7 @@ export async function normalizeChatImage(file: File): Promise<File> {if (!blob) {throw new Error(`Could not convert ${file.name}.`);}- if (blob.size > MAX_CONVERTED_IMAGE_BYTES) {+ if (blob.size > MAX_CHAT_IMAGE_BYTES) {throw new Error(`${file.name} is over 20 MB once converted.`);}const extension = type === "image/jpeg" ? ".jpg" : ".png";diff --git a/studio/frontend/src/features/chat/runtime-provider.tsx b/studio/frontend/src/features/chat/runtime-provider.tsxindex 21a8760c681..e64872ec871 100644--- a/studio/frontend/src/features/chat/runtime-provider.tsx+++ b/studio/frontend/src/features/chat/runtime-provider.tsx@@ -110,6 +110,7 @@ import {import {CHAT_IMAGE_ACCEPT,convertedImageType,+ getChatImageSizeError,normalizeChatImage,} from "./image-normalize";import { chatModelLoaded } from "./lib/chat-model-loaded";@@ -470,9 +471,10 @@ class VisionImageAdapter implements AttachmentAdapter {throw new Error(reason);}- const maxSize = 20 * 1024 * 1024;- if (picked.size > maxSize) {- throw new Error("Image size exceeds 20MB limit");+ const sizeError = getChatImageSizeError(picked);+ if (sizeError) {+ toast.error(sizeError);+ throw new Error(sizeError);}const attachment = {id: crypto.randomUUID(),diff --git a/studio/frontend/src/features/chat/shared-composer.tsx b/studio/frontend/src/features/chat/shared-composer.tsxindex 7a6e320f1d9..828f8448640 100644--- a/studio/frontend/src/features/chat/shared-composer.tsx+++ b/studio/frontend/src/features/chat/shared-composer.tsx@@ -82,6 +82,7 @@ import { isMultimodalResponse } from "./types/api";import { getImageInputUnavailableReason } from "./utils/image-input-support";import {CHAT_IMAGE_ACCEPT,+ getChatImageSizeError,isChatImageFile,normalizeChatImage,} from "./image-normalize";@@ -283,8 +284,6 @@ export interface CompareHandle {waitForRunEnd: () => Promise<void>;}-const MAX_IMAGE_SIZE = 20 * 1024 * 1024;-// Inlined to avoid a new icon dep. Kept in sync with the main composer.function isNativeComposing(event: Event) {return "isComposing" in event && (event as InputEvent).isComposing === true;@@ -1319,11 +1318,15 @@ export function SharedComposer({continue;}if (!isChatImageFile(file)) continue;- if (file.size > MAX_IMAGE_SIZE) continue;if (attachUnavailableReason) {droppedImageForUnavailable = true;continue;}+ const sizeError = getChatImageSizeError(file);+ if (sizeError) {+ toast.error(sizeError);+ continue;+ }let image: File;setConvertingImages((count) => count + 1);try {@@ -1384,11 +1387,9 @@ export function SharedComposer({// Classify before the check, so a pasted audio-only 3GP is not read// as unsupported on its extension alone.const files = await classifiedAttachmentFiles(pasted);- // Let addFiles report audio size errors.+ // Let addFiles report audio and image size errors.const supported = files.some(- (file) =>- isAudioAttachmentFile(file) ||- (isChatImageFile(file) && file.size <= MAX_IMAGE_SIZE),+ (file) => isAudioAttachmentFile(file) || isChatImageFile(file),);if (!supported) throw new Error("Unsupported compare attachment");await addFilesUntracked(files);diff --git a/studio/frontend/tests/oversized-image-attach-toast.test.ts b/studio/frontend/tests/oversized-image-attach-toast.test.tsnew file mode 100644index 00000000000..e89ba960f09--- /dev/null+++ b/studio/frontend/tests/oversized-image-attach-toast.test.ts@@ -0,0 +1,38 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";++import { getChatImageSizeError } from "../src/features/chat/image-normalize.ts";+import { readSrc } from "./helpers/kit.ts";++const RUNTIME_PROVIDER = readSrc("features/chat/runtime-provider.tsx");+const SHARED_COMPOSER = readSrc("features/chat/shared-composer.tsx");+const MB = 1024 * 1024;++test("an image over 20 MB is named in the refusal", () => {+ assert.equal(getChatImageSizeError({ name: "a.png", size: 20 * MB }), null);+ assert.equal(+ getChatImageSizeError({ name: "big.png", size: 20 * MB + 1 }),+ "big.png is over the 20 MB image limit.",+ );+});++test("the chat composer toasts an oversized image before refusing it", () => {+ assert.match(+ RUNTIME_PROVIDER,+ /class VisionImageAdapter[\s\S]*?const sizeError = getChatImageSizeError\(picked\);\s*if \(sizeError\) \{\s*toast\.error\(sizeError\);\s*throw new Error\(sizeError\);/,+ );+});++test("the compare composer toasts each oversized image, including a pasted one", () => {+ assert.match(+ SHARED_COMPOSER,+ /const sizeError = getChatImageSizeError\(file\);\s*if \(sizeError\) \{\s*toast\.error\(sizeError\);\s*continue;/,+ );+ assert.match(+ SHARED_COMPOSER,+ /const supported = files\.some\(\s*\(file\) => isAudioAttachmentFile\(file\) \|\| isChatImageFile\(file\),\s*\);/,+ );+});