From b4ad64586aceeae45dd5cc4178f43b4b6c00fb77 Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub <26625900+thiswillbeyourgithub@users.noreply.github.com> Date: Thu, 12 Sep 2024 16:36:37 +0200 Subject: [PATCH] fix: add check that the context for RAG is not empty if the threshold is 0 --- backend/open_webui/main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 8914cb491..bf586e56d 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -588,6 +588,11 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): prompt = get_last_user_message(body["messages"]) if prompt is None: raise Exception("No user message found") + if rag_app.state.config.RELEVANCE_THRESHOLD == 0: + assert context_string.strip(), ( + "With a 0 relevancy threshold for RAG, the context cannot " + "be empty" + ) # Workaround for Ollama 2.0+ system prompt issue # TODO: replace with add_or_update_system_message if model["owned_by"] == "ollama":