LocalAI/core/http/endpoints/openai
Attila Györffy 5a67b5d73c
Fix image upload processing and img2img pipeline in diffusers backend (#8879)
* fix: add missing bufio.Flush in processImageFile

The processImageFile function writes decoded image data (from base64
or URL download) through a bufio.NewWriter but never calls Flush()
before closing the underlying file. Since bufio's default buffer is
4096 bytes, small images produce 0-byte files and large images are
truncated — causing PIL to fail with "cannot identify image file".

This breaks all image input paths: file, files, and ref_images
parameters in /v1/images/generations, making img2img, inpainting,
and reference image features non-functional.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* fix: merge options into kwargs in diffusers GenerateImage

The GenerateImage method builds a local `options` dict containing the
source image (PIL), negative_prompt, and num_inference_steps, but
never merges it into `kwargs` before calling self.pipe(**kwargs).
This causes img2img to fail with "Input is in incorrect format"
because the pipeline never receives the image parameter.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* test: add unit test for processImageFile base64 decoding

Verifies that a base64-encoded PNG survives the write path
(encode → decode → bufio.Write → Flush → file on disk) with
byte-for-byte fidelity. The test image is small enough to fit
entirely in bufio's 4096-byte buffer, which is the exact scenario
where the missing Flush() produced a 0-byte file.

Also tests that invalid base64 input is handled gracefully.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* test: verify GenerateImage merges options into pipeline kwargs

Mocks the diffusers pipeline and calls GenerateImage with a source
image and negative prompt. Asserts that the pipeline receives the
image, negative_prompt, and num_inference_steps via kwargs — the
exact parameters that were silently dropped before the fix.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* fix: move kwargs.update(options) earlier in GenerateImage

Move the options merge right after self.options merge (L742) so that
image, negative_prompt, and num_inference_steps are available to all
downstream code paths including img2vid and txt2vid.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

* test: convert processImageFile tests to ginkgo

Replace standard testing with ginkgo/gomega to be consistent with
the rest of the test suites in the project.

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>

---------

Signed-off-by: Attila Györffy <attila+git@attilagyorffy.com>
Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
2026-03-11 08:05:50 +01:00
..
types fix(realtime): Send proper image data to backend (#8547) 2026-02-13 18:01:07 +01:00
chat.go feat(ui): MCP Apps, mcp streaming and client-side support (#8947) 2026-03-11 07:30:49 +01:00
completion.go feat(functions): add peg-based parsing and allow backends to return tool calls directly (#8838) 2026-03-08 22:21:57 +01:00
constants.go fix(api): SSE streaming format to comply with specification (#7182) 2025-11-09 22:00:27 +01:00
edit.go feat(functions): add peg-based parsing and allow backends to return tool calls directly (#8838) 2026-03-08 22:21:57 +01:00
embeddings.go chore(refactor): move logging to common package based on slog (#7668) 2025-12-21 19:33:13 +01:00
image.go Fix image upload processing and img2img pipeline in diffusers backend (#8879) 2026-03-11 08:05:50 +01:00
image_test.go Fix image upload processing and img2img pipeline in diffusers backend (#8879) 2026-03-11 08:05:50 +01:00
inference.go feat(functions): add peg-based parsing and allow backends to return tool calls directly (#8838) 2026-03-08 22:21:57 +01:00
inpainting.go feat(UI): image generation improvements (#7804) 2025-12-31 21:59:46 +01:00
inpainting_test.go feat(UI): image generation improvements (#7804) 2025-12-31 21:59:46 +01:00
list.go feat: migrate to echo and enable cancellation of non-streaming requests (#7270) 2025-11-14 22:57:53 +01:00
openai_suite_test.go Fix image upload processing and img2img pipeline in diffusers backend (#8879) 2026-03-11 08:05:50 +01:00
realtime.go fix(realtime): Add functions to conversation history (#8616) 2026-02-21 19:03:49 +01:00
realtime_model.go feat: pass-by metadata to predict options (#8795) 2026-03-05 22:50:10 +01:00
transcription.go feat(api): Add transcribe response format request parameter & adjust STT backends (#8318) 2026-02-01 17:33:17 +01:00