[PR #14036] [CLOSED] fix: remove inline md images before task execution #38995

Closed
opened 2026-04-25 11:45:20 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/14036
Author: @almajo
Created: 5/19/2025
Status: ❌ Closed

Base: dev ← Head: task/ignore_base64_images_tasks


📝 Commits (1)

  • 83c50d6 Refac and remove inline images

📊 Changes

2 files changed (+0 additions, -0 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+2 -24)
📝 backend/open_webui/utils/task.py (+44 -0)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

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

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests to validate the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

Follow-Up on https://github.com/open-webui/open-webui/issues/13834 to remove inline markdown images (base64, urls, ...) before sending the messages to the task models. This allows title/tag generation even when inline images are present.

Changed

  • Added another regex string for replacement before task execution
  • Put content cleaning in separate method for less complexity in middleware method

Additional Information

Tested the method with the following function

import pytest

def test_filter_message_content_for_tasks():
    # Test case 1: Basic string content
    message_list = [
        {"role": "user", "content": "Hello, what's the task?"},
        {"role": "assistant", "content": "The task is to create a Python script."}
    ]
    filtered = filter_message_content_for_tasks(message_list)
    assert filtered == message_list  # Content should remain unchanged
    
    # Test case 2: Content with details tags
    message_list = [
        {"role": "user", "content": "Please help me with this.<details>Extra info</details>"},
        {"role": "assistant", "content": "<details type=\"reasoning\">Reasoning: I think this is the best approach.</details>My answer is 42."}
    ]
    filtered = filter_message_content_for_tasks(message_list)
    assert filtered[0]["content"] == "Please help me with this."
    assert filtered[1]["content"] == "My answer is 42."
    
    # Test case 3: Content with images
    message_list = [
        {"role": "user", "content": "Here's my diagram: ![diagram](https://example.com/image.png) What do you think?"},
        {"role": "assistant", "content": "![example](image.jpg) This looks good."}
    ]
    filtered = filter_message_content_for_tasks(message_list)
    assert filtered[0]["content"] == "Here's my diagram:  What do you think?", filtered[0]["content"]
    assert filtered[1]["content"] == "This looks good.", filtered[1]["content"]
    
    # Test case 4: Content as list with text items
    message_list = [
        {"role": "user", "content": [{"type": "text", "text": "Here's my question"}]},
        {"role": "assistant", "content": [{"type": "text", "text": "Here's my answer"}]}
    ]
    filtered = filter_message_content_for_tasks(message_list)
    assert filtered[0]["content"] == "Here's my question"
    assert filtered[1]["content"] == "Here's my answer"
    
    # Test case 5: Mixed content
    message_list = [
        {"role": "user", "content": "Query with <details>hidden details</details> and ![image](img.png)"},
        {"role": "assistant", "content": [{"type": "text", "text": "<details>Reasoning</details>Answer"}]}
    ]
    filtered = filter_message_content_for_tasks(message_list)
    assert filtered[0]["content"] == "Query with  and"
    assert filtered[1]["content"] == "Answer"

    # Test case 6: Content with base64 encoded images
    message_list = [
        {"role": "user", "content": "Here's my screenshot: ![image](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==)"},
        {"role": "assistant", "content": "I see your \n![screenshot](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=) and it looks good."}
    ]
    filtered = filter_message_content_for_tasks(message_list)
    assert filtered[0]["content"] == "Here's my screenshot:", filtered[0]["content"]
    assert filtered[1]["content"] == "I see your \n and it looks good.", filtered[1]["content"]

print("Running tests...")
test_filter_message_content_for_tasks()
print("All tests passed!")

Screenshots or Videos

  • [Attach any relevant screenshots or videos demonstrating the changes]

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.


🔄 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/14036 **Author:** [@almajo](https://github.com/almajo) **Created:** 5/19/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `task/ignore_base64_images_tasks` --- ### 📝 Commits (1) - [`83c50d6`](https://github.com/open-webui/open-webui/commit/83c50d6476736157ce76f65fccbf6ff33ed4f9f7) Refac and remove inline images ### 📊 Changes **2 files changed** (+0 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+2 -24) 📝 `backend/open_webui/utils/task.py` (+44 -0) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Have you written and run sufficient tests to validate the changes? - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description Follow-Up on https://github.com/open-webui/open-webui/issues/13834 to remove inline markdown images (base64, urls, ...) before sending the messages to the task models. This allows title/tag generation even when inline images are present. ### Changed - Added another regex string for replacement before task execution - Put content cleaning in separate method for less complexity in middleware method --- ### Additional Information Tested the method with the following function ```python import pytest def test_filter_message_content_for_tasks(): # Test case 1: Basic string content message_list = [ {"role": "user", "content": "Hello, what's the task?"}, {"role": "assistant", "content": "The task is to create a Python script."} ] filtered = filter_message_content_for_tasks(message_list) assert filtered == message_list # Content should remain unchanged # Test case 2: Content with details tags message_list = [ {"role": "user", "content": "Please help me with this.<details>Extra info</details>"}, {"role": "assistant", "content": "<details type=\"reasoning\">Reasoning: I think this is the best approach.</details>My answer is 42."} ] filtered = filter_message_content_for_tasks(message_list) assert filtered[0]["content"] == "Please help me with this." assert filtered[1]["content"] == "My answer is 42." # Test case 3: Content with images message_list = [ {"role": "user", "content": "Here's my diagram: ![diagram](https://example.com/image.png) What do you think?"}, {"role": "assistant", "content": "![example](image.jpg) This looks good."} ] filtered = filter_message_content_for_tasks(message_list) assert filtered[0]["content"] == "Here's my diagram: What do you think?", filtered[0]["content"] assert filtered[1]["content"] == "This looks good.", filtered[1]["content"] # Test case 4: Content as list with text items message_list = [ {"role": "user", "content": [{"type": "text", "text": "Here's my question"}]}, {"role": "assistant", "content": [{"type": "text", "text": "Here's my answer"}]} ] filtered = filter_message_content_for_tasks(message_list) assert filtered[0]["content"] == "Here's my question" assert filtered[1]["content"] == "Here's my answer" # Test case 5: Mixed content message_list = [ {"role": "user", "content": "Query with <details>hidden details</details> and ![image](img.png)"}, {"role": "assistant", "content": [{"type": "text", "text": "<details>Reasoning</details>Answer"}]} ] filtered = filter_message_content_for_tasks(message_list) assert filtered[0]["content"] == "Query with and" assert filtered[1]["content"] == "Answer" # Test case 6: Content with base64 encoded images message_list = [ {"role": "user", "content": "Here's my screenshot: ![image](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==)"}, {"role": "assistant", "content": "I see your \n![screenshot](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=) and it looks good."} ] filtered = filter_message_content_for_tasks(message_list) assert filtered[0]["content"] == "Here's my screenshot:", filtered[0]["content"] assert filtered[1]["content"] == "I see your \n and it looks good.", filtered[1]["content"] print("Running tests...") test_filter_message_content_for_tasks() print("All tests passed!") ``` ### Screenshots or Videos - [Attach any relevant screenshots or videos demonstrating the changes] ### Contributor License Agreement By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <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 11:45:20 -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#38995