From f58eb0d26640c144c84a4fe1f72abcd819e035f2 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 6 May 2024 17:29:16 -0700 Subject: [PATCH] feat: browser search engine support --- backend/config.py | 3 +++ backend/main.py | 18 +++++++++++++++++- src/app.html | 6 ++++++ src/routes/(app)/+page.svelte | 8 ++++++++ static/opensearch.xml | 8 ++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 static/opensearch.xml diff --git a/backend/config.py b/backend/config.py index fe8260a50..cdc10ec45 100644 --- a/backend/config.py +++ b/backend/config.py @@ -76,8 +76,11 @@ WEBUI_NAME = os.environ.get("WEBUI_NAME", "Open WebUI") if WEBUI_NAME != "Open WebUI": WEBUI_NAME += " (Open WebUI)" +WEBUI_URL = os.environ.get("WEBUI_URL", "http://localhost:3000") + WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png" + #################################### # ENV (dev,test,prod) #################################### diff --git a/backend/main.py b/backend/main.py index dc2175ad5..330644191 100644 --- a/backend/main.py +++ b/backend/main.py @@ -15,7 +15,7 @@ from fastapi.middleware.wsgi import WSGIMiddleware from fastapi.middleware.cors import CORSMiddleware from starlette.exceptions import HTTPException as StarletteHTTPException from starlette.middleware.base import BaseHTTPMiddleware -from starlette.responses import StreamingResponse +from starlette.responses import StreamingResponse, Response from apps.ollama.main import app as ollama_app from apps.openai.main import app as openai_app @@ -43,6 +43,7 @@ from apps.rag.utils import rag_messages from config import ( CONFIG_DATA, WEBUI_NAME, + WEBUI_URL, ENV, VERSION, CHANGELOG, @@ -350,6 +351,21 @@ async def get_manifest_json(): } +@app.get("/opensearch.xml") +async def get_opensearch_xml(): + xml_content = rf""" + + {WEBUI_NAME} + Search {WEBUI_NAME} + UTF-8 + {WEBUI_URL}/favicon.png + + {WEBUI_URL} + + """ + return Response(content=xml_content, media_type="application/xml") + + app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static") app.mount("/cache", StaticFiles(directory=CACHE_DIR), name="cache") diff --git a/src/app.html b/src/app.html index 1aa01e8b6..1616cc668 100644 --- a/src/app.html +++ b/src/app.html @@ -6,6 +6,12 @@ +