[PR #19930] [CLOSED] fix: make image generation/edit context visible to LLM and harden missing chat_id handling #41026

Closed
opened 2026-04-25 13:21:15 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/19930
Author: @belugaming
Created: 12/13/2025
Status: Closed

Base: devHead: main


📝 Commits (10+)

  • fe6783c Merge pull request #19030 from open-webui/dev
  • fc05e0a Merge pull request #19405 from open-webui/dev
  • e3faec6 Merge pull request #19416 from open-webui/dev
  • 9899293 Merge pull request #19448 from open-webui/dev
  • 140605e Merge pull request #19462 from open-webui/dev
  • 6f1486f Merge pull request #19466 from open-webui/dev
  • 0397d2d Refactor chat_image_generation_handler to handle missing chat_id gracefully and improve event emission logic. Ensure proper status updates for image generation and error handling, while enhancing system message content for clarity.
  • d633fe6 docs: add PR description template
  • 837c6f2 docs: update PR testing notes
  • 3ea5309 delete PR.MD

📊 Changes

1 file changed (+99 additions, -71 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+99 -71)

📄 Description

Pull Request Checklist

Note to first-time contributors

If required, a Discussion was opened to describe the bug/fix and gather feedback before submitting this PR.

Before submitting, make sure you've checked the following:

  • Target branch: This pull request targets the dev branch.
  • Description: Provided below.
  • Changelog: Added below (Keep a Changelog format).
  • Documentation: N/A (no new environment variables or docs changes required).
  • Dependencies: No new dependencies.
  • Testing: Manual tests performed (steps listed below).
  • Agentic AI Code: Parts were created with AI assistance; I performed additional human review and manual testing.
  • Code review: Performed a self-review; aligned with existing coding patterns.
  • Title Prefix: Uses fix:.

Description

Fix server-side image generation/edit flow so the LLM reliably knows an image operation happened (even for text-only models), and harden the handler against missing chat_id and missing websocket emitter in error paths.

Related issue: open-webui/open-webui#19702


Changelog Entry

Description

Improve chat_image_generation_handler robustness and make the final prompt used for image generation/edit visible to the LLM via system context injection.

Fixed

  • Prevent AttributeError when chat_id is missing (avoid chat_id.startswith(...) on None).
  • Guard websocket event emission (including error paths) when no emitter exists.
  • Prevent "None" from being sent as an image generation prompt when prompt is None.
  • Inject the final image generation/edit prompt used into system <context> so text-only models can acknowledge image operations consistently.

Additional Information

  • Scope limited to: backend/open_webui/utils/middleware.py (chat_image_generation_handler).

Testing (Manual)

  • Enabled Settings → Tools → Image generation.
  • Requested an image (e.g., “Draw a cat” / “生成一只小猫”).
  • Verified:
    • Image is generated and shown in the chat UI.
    • Model response acknowledges the image operation and does not contradict it (e.g., no “I can’t generate images” after generation).
  • Tested with:
    • Model profile: deepseek-v3.1:671b-cloud
    • Prompt: “生成一只小猫”
    • Observed UI status: “Image created”
    • Observed model response: acknowledged the image and provided a design explanation (no “cannot generate images” contradiction).
  • Tested error paths:
    • Triggered an image generation failure and confirmed no crash when chat_id is missing (no websocket emitter available).

Screenshots or Videos

  • (Optional) Add screenshots of: generated/edited image + model response acknowledging the operation.

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/19930 **Author:** [@belugaming](https://github.com/belugaming) **Created:** 12/13/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `main` --- ### 📝 Commits (10+) - [`fe6783c`](https://github.com/open-webui/open-webui/commit/fe6783c16699911c7be17392596d579333fb110c) Merge pull request #19030 from open-webui/dev - [`fc05e0a`](https://github.com/open-webui/open-webui/commit/fc05e0a6c5d39da60b603b4d520f800d6e36f748) Merge pull request #19405 from open-webui/dev - [`e3faec6`](https://github.com/open-webui/open-webui/commit/e3faec62c58e3a83d89aa3df539feacefa125e0c) Merge pull request #19416 from open-webui/dev - [`9899293`](https://github.com/open-webui/open-webui/commit/9899293f050ad50ae12024cbebee7e018acd851e) Merge pull request #19448 from open-webui/dev - [`140605e`](https://github.com/open-webui/open-webui/commit/140605e660b8186a7d5c79fb3be6ffb147a2f498) Merge pull request #19462 from open-webui/dev - [`6f1486f`](https://github.com/open-webui/open-webui/commit/6f1486ffd0cb288d0e21f41845361924e0d742b3) Merge pull request #19466 from open-webui/dev - [`0397d2d`](https://github.com/open-webui/open-webui/commit/0397d2d628b1612c8040a1a5fdf1b3bd6f198331) Refactor chat_image_generation_handler to handle missing chat_id gracefully and improve event emission logic. Ensure proper status updates for image generation and error handling, while enhancing system message content for clarity. - [`d633fe6`](https://github.com/open-webui/open-webui/commit/d633fe6c57e57089c1c00be59240d91679fc61d2) docs: add PR description template - [`837c6f2`](https://github.com/open-webui/open-webui/commit/837c6f2cc8fbdc5c1a6e9c2007194b8464400f95) docs: update PR testing notes - [`3ea5309`](https://github.com/open-webui/open-webui/commit/3ea53093d1da1713049fbb7a7942067edad7db0f) delete PR.MD ### 📊 Changes **1 file changed** (+99 additions, -71 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+99 -71) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors If required, a Discussion was opened to describe the bug/fix and gather feedback before submitting this PR. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** This pull request targets the `dev` branch. - [x] **Description:** Provided below. - [x] **Changelog:** Added below (Keep a Changelog format). - [ ] **Documentation:** N/A (no new environment variables or docs changes required). - [x] **Dependencies:** No new dependencies. - [x] **Testing:** Manual tests performed (steps listed below). - [x] **Agentic AI Code:** Parts were created with AI assistance; I performed additional human review and manual testing. - [x] **Code review:** Performed a self-review; aligned with existing coding patterns. - [x] **Title Prefix:** Uses `fix:`. --- ## Description Fix server-side image generation/edit flow so the LLM reliably knows an image operation happened (even for text-only models), and harden the handler against missing `chat_id` and missing websocket emitter in error paths. Related issue: [open-webui/open-webui#19702](https://github.com/open-webui/open-webui/issues/19702#issuecomment-3605279895) --- # Changelog Entry ### Description Improve `chat_image_generation_handler` robustness and make the final prompt used for image generation/edit visible to the LLM via system context injection. ### Fixed - Prevent `AttributeError` when `chat_id` is missing (avoid `chat_id.startswith(...)` on `None`). - Guard websocket event emission (including error paths) when no emitter exists. - Prevent `"None"` from being sent as an image generation prompt when `prompt` is `None`. - Inject the final image generation/edit prompt used into system `<context>` so text-only models can acknowledge image operations consistently. --- ### Additional Information - Scope limited to: `backend/open_webui/utils/middleware.py` (`chat_image_generation_handler`). ### Testing (Manual) - Enabled **Settings → Tools → Image generation**. - Requested an image (e.g., “Draw a cat” / “生成一只小猫”). - Verified: - Image is generated and shown in the chat UI. - Model response acknowledges the image operation and does not contradict it (e.g., no “I can’t generate images” after generation). - Tested with: - Model profile: `deepseek-v3.1:671b-cloud` - Prompt: “生成一只小猫” - Observed UI status: “Image created” - Observed model response: acknowledged the image and provided a design explanation (no “cannot generate images” contradiction). - Tested error paths: - Triggered an image generation failure and confirmed no crash when `chat_id` is missing (no websocket emitter available). ### Screenshots or Videos - (Optional) Add screenshots of: generated/edited image + model response acknowledging the operation. ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-25 13:21:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#41026