From adf26789b8c1c9c256f22aef98f64449d8f684a5 Mon Sep 17 00:00:00 2001 From: thiswillbeyourgithub <26625900+thiswillbeyourgithub@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:19:24 +0200 Subject: [PATCH] logs: crash if rag_template would be wrong --- backend/open_webui/apps/rag/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/open_webui/apps/rag/utils.py b/backend/open_webui/apps/rag/utils.py index dd4cdd007..5bddf0a96 100644 --- a/backend/open_webui/apps/rag/utils.py +++ b/backend/open_webui/apps/rag/utils.py @@ -192,6 +192,11 @@ def query_collection_with_hybrid_search( def rag_template(template: str, context: str, query: str): + count = template.count("[context]") + assert count == 1, ( + f"RAG template contains an unexpected number of '[context]' : {count}" + ) + assert "[context]" in template, "RAG template does not contain '[context]'" template = template.replace("[context]", context) template = template.replace("[query]", query) return template