Repository navigation
Studio: the Images pill makes images and videos in chat with the loaded local models - #14110
Conversation
…rompting tips, and /v1/videos takes Unsloth Studio controls - /api/inference/images/generate resolves omitted steps and guidance from the loaded model (diffusers generation_defaults, else the family table for sd.cpp and MLX), per retry attempt, and pins the model it read. /v1/images shares the same helper. - MCP generate_image refuses workflows the engine cannot run (reference or edit or outpaint without init_image, outpaint without mask_image, upscale <= 1) before any upload, takes seeds/prompts batches, and studio_status image carries workflows, generation_defaults, dimension_multiple, max_condition_images and prompt_hint. - Image and video families gain an optional prompt_hint, exposed in every engine's status, shown as the Prompt field's info hint on the Images and Video pages, plus an off-by-default image-prompting bundled skill. - /v1/videos accepts seed, negative_prompt, steps, guidance, num_frames, fps, last_frame, reference_images and reference_audios (data URLs or Unsloth Studio audio ids), keeps the family checks before any model switch, and draws, stores and echoes a seed when none is sent. Plain OpenAI-shaped requests are unchanged apart from the added seed. - MCP generate_video exposes those controls, takes seconds as a number or a string, and echoes the seed on the job and in get_job.
…g a load - MiniMax-H3 writes at a fixed 24 fps, so /v1/videos refuses another fps instead of misreporting the clip length. - last_frame and each reference image take the same 32 MB image input_reference takes. - The MCP generate_video budget matches what one /v1/videos request carries (32 MB of images, body cap checked before the call). - Stored reference audio is sized before it is read; multipart reference lists keep their wire order. - /images/generate with omitted steps or guidance during another client's load retries on the new model's defaults.
With auto-switch on or a managed account, the route reads generation_snapshot(), which carries no family key, so the fixed-fps check read None and let fps through. Read the family off the pinned state instead.
…uploading it /v1/videos takes at most 24 MB per reference audio, but audio_ref uploads up to 200 MB first, so a large local file was read, sent and stored only to be refused.
…ed local models A chat model that calls Unsloth Studio tools can now render with the image or video model already loaded in Unsloth Studio. The Images pill and + menu item show for it, and a turn with the pill on offers generate_image and/or generate_video. - generate_image runs the Images route's local core on the server loop, bound to the chat's account, so the image lands in that account's gallery and goes through the same access checks. Omitted steps and guidance follow the loaded model's defaults. - generate_video goes through the /v1/videos job path with no model named, so nothing loads or switches; the tool polls the job and copies the .mp4 into the chat's files. - Neither tool loads or unloads a model. Busy, stopped, timed-out and other-account cases come back as "Error: ..." results. - One MEDIA_CHAT_TOOLS set (backend and frontend) feeds the sentinel, always-safe, dedupe and fold registries.
…combinations before uploading audio - Each reference audio string now fits a 24 MB clip as a base64 data URL with its header, the size the upload and audio id paths accept. - reference_images and reference_audios say one request body carries about 32 MB of inline media, and that larger or several clips go as Unsloth Studio audio ids. - MCP generate_video refuses seconds with num_frames, last_frame with references and first_frame with reference_images before it uploads any audio.
…econds take fractions - Before an automatic switch, each reference audio is decoded the way the engine would, so an unreadable clip is a 400 on reference_audios instead of a failure after the requested model loaded. - MCP generate_video's seconds accepts a fractional number such as 2.5, as /v1/videos does.
More than 9 reference_images (or 3 reference_audios) in a multipart body were each base64-encoded before the request model refused the count, so ten modest files could grow past 50 MB in memory.
…ng frame is a status
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…n-g1 # Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
UI evidenceBoth sides ran the same steps on one B200 (GPU 2). Unsloth Studio was started fresh from each tree with update checks off. The image model was Z-Image-Turbo GGUF (Q4_K_M), loaded under the default Off. The chat model was Qwen3-4B (UD-Q4_K_XL) on CPU, served by llama-server with 8 threads and added as a Custom provider that uses Unsloth Studio tools. Before is #14078's head ( Thread composer and + menu. Before, there is no Images pill or menu item for this model. After, both show. Compare composer (both panes on the same model): The same request, "Make an image of a lighthouse at dusk, painted in oils.", with the Images pill on in the after run. Before, the model can only describe a painting. After, it calls Video. With Wan2.2-TI2V-5B loaded instead, "Make a 2 second video of waves rolling onto a beach at sunset." calls Design check (report-only, against the Unsloth Studio design rules): no violations. Its nits were fixed in 809dc77: the loading frame is a status, the caption clamps to 4 lines like the hosted card, and a failed image or video says so in the card label. The Download overlay and the shared media sizing match the hosted image card. |
…s while stopping is kept, and media cards name a stop - generate_video no longer cancels a create still in flight after its wait: past begin_generate the job already runs, and the cancel left it with no record on the Video page. Stop during the create stops the job once it exists. - generate_image returns the image when the render finishes inside the stop window. - The image and video cards treat any plain-string result as "not generated" and show its text, so a stopped call no longer reads "Generated ...". - The Images pill's readiness is also re-read on window focus, so an idle unload or a load from another tab or MCP client shows up.
…l handed to the chat
…in frame-count errors [skip ci]
…ads resident reference audio before rendering [skip ci]
… loaded model's grid
…eds reference media [skip ci]
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
# Conflicts: # studio/backend/routes/inference.py
# Conflicts: # studio/MCP.md
# Conflicts: # studio/frontend/scripts/check-bundle-budget.ts
…eset the startup budget to the build (#14168) ## Summary Main is over the startup bundle budget, so `Frontend build + bundle sanity` fails on every PR based on it: ``` over the startup budget: transfer 2005.9 KB > 2003.5 KB, raw 6665.4 KB > 6659.1 KB (main at 2fee36f) ``` This PR takes two steps. It moves #14137's prompt upsampler client out of the startup chunks, which is real growth with a lazy home. It then resets both limits to the measured build. Main has gone over this budget repeatedly, and the root of that is a shortfall in how the limits were raised, which this corrects. ## Cause **#14137 (FLUX.3 prompt upsampling).** The Images page is lazy (`ImagesPage = lazy(...)` in `__root.tsx`), but `features/images/api.ts` is not. Startup modules import it for other calls (`loaded-models-api.ts`, `loaded-models-sources.ts`, `use-media-companion-bytes.ts`). #14137 put the four upsampler calls there, with value imports from `lib/prompt-enhance.ts`, so that module joined the startup chunks. Only `prompt-enhance-panel.tsx`, inside the lazy Images page, calls them. **The limits themselves.** Each raise since #14073 was sized from its own PR's delta and added to the previous limit. That previous limit already sat below the build, starting at #14073: - `475a02ac` measures 2,047,700 B transfer against the 2,047,608 B limit #14073 set. - By `2fee36ff` the gap is 6,500 B raw and 2,409 B transfer. The raises since (#14072, #14075, #14110, #14108, #14113) each added their delta, so the shortfall carried forward. CI agrees with my machine to the byte: the first run of this PR read 1999.7 KB transfer on both. ## Change - **New `features/images/prompt-upsampler-api.ts`:** holds `getPromptUpsamplerStatus`, `startPromptUpsamplerDownload`, `cancelPromptUpsamplerDownload` and `previewEnhancedPrompt`, moved unchanged, with the same `parseJson` error handling. - **`api.ts`:** now imports only the `PromptEnhancement` type from `lib/prompt-enhance` (erased at build). - **`prompt-enhance-panel.tsx`:** imports the calls from the new module. - **No behavior change** in the app. - **`check-bundle-budget.ts`:** both limits are reset to the measured build plus the usual margin (160 B raw, 189 B transfer), with an entry in the BUDGET comment block explaining why the reset is absolute rather than by delta. - `rawBytes`: 6,819,206 (main after #14113) -> 6,825,885. - `transferBytes`: 2,051,727 -> 2,054,261. ## Testing One machine and build, Node 24, exact byte totals from the budget script, 95 chunks throughout: | tree | raw B | transfer B | |---|---|---| | main `2fee36ff` | 6,825,378 | 2,053,999 | | main `2fee36ff` + the move | 6,821,006 | 2,052,708 | | main `78e5eefa4d` (adds #14113) + the move | 6,821,334 | 2,052,857 | | + #14183 | 6,821,410 | 2,052,614 | | + #14172 (one tooltip design) | 6,825,307 | 2,053,990 | | this PR (main `b227654927`, adds #14184, + the move) | 6,825,725 | 2,054,072 | - **The move saves:** 4,372 B raw and 1,291 B transfer. - **#14113 adds:** 328 B raw and 149 B transfer on this build. - **Landed while main was over, with no raise:** #14183 (+76 B raw, -243 B transfer), #14172 (+3,897 B raw, +1,376 B transfer, the shared tooltip is in the eager shell) and #14184 (+418 B raw, +82 B transfer). This is the treadmill the absolute reset stops: while main is red on this check, growth lands unaccounted. - **With the new limits:** `within budget (0.2 KB transfer, 0.2 KB raw to spare)`. - **`npm run typecheck`:** clean. - **`bundle-budget-cli.test.ts`, `bundle-budget-closure.test.ts`, `image-prompt-enhance.test.ts` and `loaded-models-platform-matrix.test.ts`:** 74 passed. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>





Includes #14078 (Studio: image and video generation follow each model's defaults and prompting tips, and /v1/videos takes Unsloth Studio controls); review the last 10 commits (bbee492..HEAD). The own commits are bbee492, 809dc77, c713699, 282a66e and d14fb5b, plus a pre-commit.ci formatting commit (1d466b6); the merges only bring in #14078's latest heads,
main(the one conflict, the bundle budget, keeps both raises) and that formatting commit.Summary
In chat, the Images pill only worked with a hosted provider's built-in
image_generation. A local chat model, or any model that calls Unsloth Studio tools, could not use the image or video model loaded in Unsloth Studio. Now the Images pill and the + menu's Images item show for these models whenever a text-to-image or video model is loaded. With the pill on, a turn offersgenerate_imageand/orgenerate_video, and the result shows inline in chat as an image or a playable video.Neither tool loads, unloads or switches a model. Hosted image models keep their own
image_generationas before.Changes
Backend:
generate_image(core/inference/generate_image_tool.py) runs the Images route's local path on the server loop, bound to the chat's account. So the image lands in that account's gallery and goes through the same access checks asPOST /api/inference/images/generate. The route is split in place:generate_diffusion_imagekeeps its provider branch and then calls_generate_diffusion_image_core(request), with the body unchanged. The tool builds the request only from the arguments the model sent, so omitted steps and guidance follow the loaded model's defaults (Studio: image and video generation follow each model's defaults and prompting tips, and /v1/videos takes Unsloth Studio controls #14078).negative_promptis offered only when the loaded model supports it. The size is snapped to a multiple of 16 between 256 and 2752.generate_video(core/inference/generate_video_tool.py) goes through the/v1/videosjob path (_create_openai_video) with no model named, so the auto-switch returns at once and nothing loads. It polls the job and copies the finished.mp4into the chat's files. Clip lengths and sizes in its description come from the loaded model'sdefaults.prompt_hint(Studio: image and video generation follow each model's defaults and prompting tips, and /v1/videos takes Unsloth Studio controls #14078) to their description. They returnError: ...results for:enabled_toolsand a model the account may use is loaded. The server loop is captured lazily in_select_request_toolsthe first time a request offers them. There is nomain.pyor lifespan change.MEDIA_CHAT_TOOLSset (core/inference/media_chat_tools.py) feeds:_ALWAYS_SAFE_TOOLSand the Anthropic unprompted-safe list (the Anthropic path never selects these tools);llama_cpp.pyandsafetensors_agentic.py. Two identical calls are two images.Frontend:
yours: false) and an edit-only image model don't count.generate_imagecard fetches the PNG from the chat's sandbox. It has Download and no Edit, because Edit needs an OpenAI image-generation call id. The newgenerate_videocard plays the.mp4inline, with Download.MEDIA_CHAT_TOOLSset feedsSANDBOX_FILE_TOOLS,IMAGE_SENTINEL_TOOLS, the tool-fold exemptions and the response-details labels. A test keeps it equal to the backend set.check-bundle-budget.ts.Testing
test_generate_image_tool.py,test_generate_video_tool.py,studio/frontend/tests/chat-images-local-tool.test.tsandtests/studio/test_generate_image_frontend_contract.py. Extended:test_llama_cpp_tool_loop.py,test_nudge_tool_calls_wiring.pyandimage-sentinel-tools.test.ts. They cover:negative_promptper family;require_media_generation_access;GpuBusyForAnotherAccountErrorbecoming anError:string;model=Nonenever switching or loading, the busy 409 mapping, and a timeout leaving the job running;/v1/videoscontrols tests on the merged tree: 106 passed. Frontend:typecheckclean, the targeted node tests pass (30), and an earlier fullnpm testrun had 12,539 passing. The 2 failures there were load timeouts that pass when run alone.bundle:checkis within the new budget. ESLint adds nothing new on the changed files.generate_image. It rendered at 1024x1024 with 8 steps, Z-Image-Turbo's own default, and the image showed inline.generate_videowith no model named, nothing switched or loaded, and a 2 s clip played inline.gpu_layers=0. Media co-residency comes with the multi-model loading PR. The in-process path is covered by the tests above.UI before and after screenshots (both composers, the + menu, and the image and video cards) follow in a comment.
UI before / after
With a local GGUF chat model that uses Studio tools (unsloth/Qwen3-1.7B-GGUF Q4_K_M) and a text-to-image model loaded, the chat composer now shows an "Images" pill next to Tools; before this PR it never appeared for local models. BEFORE is the head of #14078 (this PR's base), AFTER is this PR, two separate installs with the same two models loaded.