瀏覽代碼

logs: crash if rag_template would be wrong

thiswillbeyourgithub 7 月之前
父節點
當前提交
adf26789b8
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      backend/open_webui/apps/rag/utils.py

+ 5 - 0
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