mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #19099] [CLOSED] fix: duplicated prompt when RAG template is used #63945
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/19099
Author: @matiboux
Created: 11/11/2025
Status: ❌ Closed
Base:
dev← Head:fix/rag-template-duplicated-prompt📝 Commits (4)
0117faaAdd replace_message_content function to misc.pydd7b2b5Add replace_user_message function to misc.py9c2fbb9Replace prompt with RAG template in middleware.py1ec24f5Remove replace_message_content function📊 Changes
2 files changed (+40 additions, -8 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+21 -8)📝
backend/open_webui/utils/misc.py(+19 -0)📄 Description
Pull Request Checklist
Before submitting, make sure you've checked the following:
devbranch. Not targeting thedevbranch will lead to immediate closure of the PR.Changelog Entry
Description
Added
replace_user_messagefunction inbackend/open_webui/utils/misc.pyto replace the existing last user message or add a new one.Changed
process_chat_payloadinbackend/open_webui/utils/middleware.pyto use eitheradd_or_update_user_messageor the newreplace_user_messagedepending on whether the RAG template contains the prompt. This ensures the correct user message is set based on the template's structure, avoiding prompt duplication.Deprecated
None.
Removed
None.
Fixed
process_chat_payloadinbackend/open_webui/utils/middleware.py.Security
None.
Breaking Changes
None.
Additional Information
This PR addresses & fixes #19098.
Updated prompts were manually tested and verified using a proxy OpenAI-compatible proxy API to inspect system & user messages.
LLM Chat Query prompt with changes from this PR:
This PR specifically addresses the code that prepends the RAG template formatted text to the user message:
e0d5de1697/backend/open_webui/utils/middleware.py (L1493-L1502)It does not modify the other code block referenced in the issue, which appends the tool result context to the user message:
e0d5de1697/backend/open_webui/utils/middleware.py (L484-L488)Screenshots or Videos
None.
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.