mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
enh: query caching
Co-Authored-By: Jacob Leksan <63938553+jmleksan@users.noreply.github.com>
This commit is contained in:
parent
e4b6855984
commit
31485835a7
3 changed files with 10 additions and 0 deletions
|
|
@ -362,6 +362,8 @@ ENABLE_REALTIME_CHAT_SAVE = (
|
||||||
os.environ.get("ENABLE_REALTIME_CHAT_SAVE", "False").lower() == "true"
|
os.environ.get("ENABLE_REALTIME_CHAT_SAVE", "False").lower() == "true"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ENABLE_QUERIES_CACHE = os.environ.get("ENABLE_QUERIES_CACHE", "False").lower() == "true"
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# REDIS
|
# REDIS
|
||||||
####################################
|
####################################
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,10 @@ async def generate_queries(
|
||||||
detail=f"Query generation is disabled",
|
detail=f"Query generation is disabled",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if getattr(request.state, "cached_queries", None):
|
||||||
|
log.info(f"Reusing cached queries: {request.state.cached_queries}")
|
||||||
|
return request.state.cached_queries
|
||||||
|
|
||||||
if getattr(request.state, "direct", False) and hasattr(request.state, "model"):
|
if getattr(request.state, "direct", False) and hasattr(request.state, "model"):
|
||||||
models = {
|
models = {
|
||||||
request.state.model["id"]: request.state.model,
|
request.state.model["id"]: request.state.model,
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,7 @@ from open_webui.env import (
|
||||||
CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES,
|
CHAT_RESPONSE_MAX_TOOL_CALL_RETRIES,
|
||||||
BYPASS_MODEL_ACCESS_CONTROL,
|
BYPASS_MODEL_ACCESS_CONTROL,
|
||||||
ENABLE_REALTIME_CHAT_SAVE,
|
ENABLE_REALTIME_CHAT_SAVE,
|
||||||
|
ENABLE_QUERIES_CACHE,
|
||||||
)
|
)
|
||||||
from open_webui.constants import TASKS
|
from open_webui.constants import TASKS
|
||||||
|
|
||||||
|
|
@ -391,6 +392,9 @@ async def chat_web_search_handler(
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
queries = [response]
|
queries = [response]
|
||||||
|
|
||||||
|
if ENABLE_QUERIES_CACHE:
|
||||||
|
request.state.cached_queries = queries
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
queries = [user_message]
|
queries = [user_message]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue