Sfoglia il codice sorgente

fix: add check that the context for RAG is not empty if the threshold is 0

thiswillbeyourgithub 7 mesi fa
parent
commit
b4ad64586a
1 ha cambiato i file con 5 aggiunte e 0 eliminazioni
  1. 5 0
      backend/open_webui/main.py

+ 5 - 0
backend/open_webui/main.py

@@ -588,6 +588,11 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
             prompt = get_last_user_message(body["messages"])
             prompt = get_last_user_message(body["messages"])
             if prompt is None:
             if prompt is None:
                 raise Exception("No user message found")
                 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
             # Workaround for Ollama 2.0+ system prompt issue
             # TODO: replace with add_or_update_system_message
             # TODO: replace with add_or_update_system_message
             if model["owned_by"] == "ollama":
             if model["owned_by"] == "ollama":