mirror of
https://github.com/open-webui/open-webui
synced 2025-01-29 13:58:09 +00:00
fix: handle case where [query] happens in the RAG context
This commit is contained in:
parent
adf26789b8
commit
9661fee554
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
from typing import Optional, Union
|
||||
|
||||
import requests
|
||||
@ -197,8 +198,15 @@ def rag_template(template: str, context: str, query: str):
|
||||
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)
|
||||
|
||||
if "[query]" in context:
|
||||
query_placeholder = str(uuid.uuid4())
|
||||
template = template.replace("[QUERY]", query_placeholder)
|
||||
template = template.replace("[context]", context)
|
||||
template = template.replace(query_placeholder, query)
|
||||
else:
|
||||
template = template.replace("[context]", context)
|
||||
template = template.replace("[query]", query)
|
||||
return template
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user