mirror of
https://github.com/open-webui/open-webui.git
synced 2026-04-30 09:18:50 -05:00
fix: inject full context knowledge into system message for KV prefix caching (#20317)
* Update middleware.py * Update middleware.py * env var * address * upd
This commit is contained in:
@@ -356,6 +356,10 @@ ENABLE_REALTIME_CHAT_SAVE = (
|
|||||||
|
|
||||||
ENABLE_QUERIES_CACHE = os.environ.get("ENABLE_QUERIES_CACHE", "False").lower() == "true"
|
ENABLE_QUERIES_CACHE = os.environ.get("ENABLE_QUERIES_CACHE", "False").lower() == "true"
|
||||||
|
|
||||||
|
RAG_SYSTEM_CONTEXT = (
|
||||||
|
os.environ.get("RAG_SYSTEM_CONTEXT", "False").lower() == "true"
|
||||||
|
)
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# REDIS
|
# REDIS
|
||||||
####################################
|
####################################
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ from open_webui.env import (
|
|||||||
BYPASS_MODEL_ACCESS_CONTROL,
|
BYPASS_MODEL_ACCESS_CONTROL,
|
||||||
ENABLE_REALTIME_CHAT_SAVE,
|
ENABLE_REALTIME_CHAT_SAVE,
|
||||||
ENABLE_QUERIES_CACHE,
|
ENABLE_QUERIES_CACHE,
|
||||||
|
RAG_SYSTEM_CONTEXT,
|
||||||
)
|
)
|
||||||
from open_webui.constants import TASKS
|
from open_webui.constants import TASKS
|
||||||
|
|
||||||
@@ -1622,15 +1623,28 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
|||||||
raise Exception("No user message found")
|
raise Exception("No user message found")
|
||||||
|
|
||||||
if context_string != "":
|
if context_string != "":
|
||||||
form_data["messages"] = add_or_update_user_message(
|
if RAG_SYSTEM_CONTEXT:
|
||||||
rag_template(
|
# Inject into system message for KV prefix caching
|
||||||
request.app.state.config.RAG_TEMPLATE,
|
form_data["messages"] = add_or_update_system_message(
|
||||||
context_string,
|
rag_template(
|
||||||
prompt,
|
request.app.state.config.RAG_TEMPLATE,
|
||||||
),
|
context_string,
|
||||||
form_data["messages"],
|
prompt,
|
||||||
append=False,
|
),
|
||||||
)
|
form_data["messages"],
|
||||||
|
append=True,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# Inject into user message
|
||||||
|
form_data["messages"] = add_or_update_user_message(
|
||||||
|
rag_template(
|
||||||
|
request.app.state.config.RAG_TEMPLATE,
|
||||||
|
context_string,
|
||||||
|
prompt,
|
||||||
|
),
|
||||||
|
form_data["messages"],
|
||||||
|
append=False,
|
||||||
|
)
|
||||||
|
|
||||||
# If there are citations, add them to the data_items
|
# If there are citations, add them to the data_items
|
||||||
sources = [
|
sources = [
|
||||||
|
|||||||
Reference in New Issue
Block a user