diff --git a/backend/apps/rag/search/searchapi.py b/backend/apps/rag/search/searchapi.py deleted file mode 100644 index c776e31a6..000000000 --- a/backend/apps/rag/search/searchapi.py +++ /dev/null @@ -1,49 +0,0 @@ -import logging -from typing import Optional -from urllib.parse import urlencode - -import requests -from apps.rag.search.main import SearchResult, get_filtered_results -from env import SRC_LOG_LEVELS - -log = logging.getLogger(__name__) -log.setLevel(SRC_LOG_LEVELS["RAG"]) - -def search_searchapi( - api_key: str, engine: str, query: str, count: int, filter_list: Optional[list[str]] = None -) -> list[SearchResult]: - """Search using searchapi.io's API and return the results as a list of SearchResult objects. - - Args: - api_key (str): A searchapi.io API key - query (str): The query to search for - """ - url = "https://www.searchapi.io/api/v1/search" - - engine = engine or "google" - - payload = { - "engine": engine, - "q": query, - "api_key": api_key - } - - url = f"{url}?{urlencode(payload)}" - response = requests.request("GET", url) - - json_response = response.json() - log.info(f"results from searchapi search: {json_response}") - - results = sorted( - json_response.get("organic_results", []), key=lambda x: x.get("position", 0) - ) - if filter_list: - results = get_filtered_results(results, filter_list) - return [ - SearchResult( - link=result["link"], - title=result["title"], - snippet=result["snippet"] - ) - for result in results[:count] - ] diff --git a/backend/data/litellm/config.yaml b/backend/data/litellm/config.yaml deleted file mode 100644 index 7d9d2b723..000000000 --- a/backend/data/litellm/config.yaml +++ /dev/null @@ -1,4 +0,0 @@ -general_settings: {} -litellm_settings: {} -model_list: [] -router_settings: {} diff --git a/backend/data/readme.txt b/backend/data/readme.txt index 30c12ace0..af1c39dcd 100644 --- a/backend/data/readme.txt +++ b/backend/data/readme.txt @@ -1 +1 @@ -dir for backend files (db, documents, etc.) \ No newline at end of file +docker dir for backend files (db, documents, etc.) \ No newline at end of file diff --git a/backend/dev.sh b/backend/dev.sh index c66ae4ba9..5449ab777 100755 --- a/backend/dev.sh +++ b/backend/dev.sh @@ -1,2 +1,2 @@ PORT="${PORT:-8080}" -uvicorn main:app --port $PORT --host 0.0.0.0 --forwarded-allow-ips '*' --reload \ No newline at end of file +uvicorn open_webui.main:app --port $PORT --host 0.0.0.0 --forwarded-allow-ips '*' --reload \ No newline at end of file diff --git a/backend/alembic.ini b/backend/open_webui/alembic.ini similarity index 98% rename from backend/alembic.ini rename to backend/open_webui/alembic.ini index 4eff85f0c..bf77571ec 100644 --- a/backend/alembic.ini +++ b/backend/open_webui/alembic.ini @@ -2,7 +2,7 @@ [alembic] # path to migration scripts -script_location = migrations +script_location = open_webui/migrations # template used to generate migration file names; The default value is %%(rev)s_%%(slug)s # Uncomment the line below if you want the files to be prepended with date and time diff --git a/backend/apps/audio/main.py b/backend/open_webui/apps/audio/main.py similarity index 98% rename from backend/apps/audio/main.py rename to backend/open_webui/apps/audio/main.py index 5a928a8b6..1fc44b28f 100644 --- a/backend/apps/audio/main.py +++ b/backend/open_webui/apps/audio/main.py @@ -7,7 +7,7 @@ from functools import lru_cache from pathlib import Path import requests -from config import ( +from open_webui.config import ( AUDIO_STT_ENGINE, AUDIO_STT_MODEL, AUDIO_STT_OPENAI_API_BASE_URL, @@ -27,13 +27,13 @@ from config import ( WHISPER_MODEL_DIR, AppConfig, ) -from constants import ERROR_MESSAGES -from env import SRC_LOG_LEVELS +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import SRC_LOG_LEVELS from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile, status from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import FileResponse from pydantic import BaseModel -from utils.utils import get_admin_user, get_current_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_current_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["AUDIO"]) diff --git a/backend/apps/images/main.py b/backend/open_webui/apps/images/main.py similarity index 98% rename from backend/apps/images/main.py rename to backend/open_webui/apps/images/main.py index 56c9a9a3a..17afd645c 100644 --- a/backend/apps/images/main.py +++ b/backend/open_webui/apps/images/main.py @@ -9,12 +9,12 @@ from pathlib import Path from typing import Optional import requests -from apps.images.utils.comfyui import ( +from open_webui.apps.images.utils.comfyui import ( ComfyUIGenerateImageForm, ComfyUIWorkflow, comfyui_generate_image, ) -from config import ( +from open_webui.config import ( AUTOMATIC1111_API_AUTH, AUTOMATIC1111_BASE_URL, CACHE_DIR, @@ -31,12 +31,12 @@ from config import ( IMAGES_OPENAI_API_KEY, AppConfig, ) -from constants import ERROR_MESSAGES -from env import SRC_LOG_LEVELS +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import SRC_LOG_LEVELS from fastapi import Depends, FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["IMAGES"]) diff --git a/backend/apps/images/utils/comfyui.py b/backend/open_webui/apps/images/utils/comfyui.py similarity index 99% rename from backend/apps/images/utils/comfyui.py rename to backend/open_webui/apps/images/utils/comfyui.py index 00121d99d..0a3e3a1d9 100644 --- a/backend/apps/images/utils/comfyui.py +++ b/backend/open_webui/apps/images/utils/comfyui.py @@ -7,7 +7,7 @@ import urllib.request from typing import Optional import websocket # NOTE: websocket-client (https://github.com/websocket-client/websocket-client) -from env import SRC_LOG_LEVELS +from open_webui.env import SRC_LOG_LEVELS from pydantic import BaseModel log = logging.getLogger(__name__) diff --git a/backend/apps/ollama/main.py b/backend/open_webui/apps/ollama/main.py similarity index 99% rename from backend/apps/ollama/main.py rename to backend/open_webui/apps/ollama/main.py index a887d2981..44b5667d5 100644 --- a/backend/apps/ollama/main.py +++ b/backend/open_webui/apps/ollama/main.py @@ -10,8 +10,8 @@ from urllib.parse import urlparse import aiohttp import requests -from apps.webui.models.models import Models -from config import ( +from open_webui.apps.webui.models.models import Models +from open_webui.config import ( AIOHTTP_CLIENT_TIMEOUT, CORS_ALLOW_ORIGIN, ENABLE_MODEL_FILTER, @@ -21,20 +21,20 @@ from config import ( UPLOAD_DIR, AppConfig, ) -from constants import ERROR_MESSAGES -from env import SRC_LOG_LEVELS +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import SRC_LOG_LEVELS from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import StreamingResponse from pydantic import BaseModel, ConfigDict from starlette.background import BackgroundTask -from utils.misc import ( +from open_webui.utils.misc import ( apply_model_params_to_body_ollama, apply_model_params_to_body_openai, apply_model_system_prompt_to_body, calculate_sha256, ) -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["OLLAMA"]) diff --git a/backend/apps/openai/main.py b/backend/open_webui/apps/openai/main.py similarity index 98% rename from backend/apps/openai/main.py rename to backend/open_webui/apps/openai/main.py index 9ac4ee0ac..53d1f4534 100644 --- a/backend/apps/openai/main.py +++ b/backend/open_webui/apps/openai/main.py @@ -7,8 +7,8 @@ from typing import Literal, Optional, overload import aiohttp import requests -from apps.webui.models.models import Models -from config import ( +from open_webui.apps.webui.models.models import Models +from open_webui.config import ( AIOHTTP_CLIENT_TIMEOUT, CACHE_DIR, CORS_ALLOW_ORIGIN, @@ -19,18 +19,18 @@ from config import ( OPENAI_API_KEYS, AppConfig, ) -from constants import ERROR_MESSAGES -from env import SRC_LOG_LEVELS +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import SRC_LOG_LEVELS from fastapi import Depends, FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import FileResponse, StreamingResponse from pydantic import BaseModel from starlette.background import BackgroundTask -from utils.misc import ( +from open_webui.utils.misc import ( apply_model_params_to_body_openai, apply_model_system_prompt_to_body, ) -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["OPENAI"]) diff --git a/backend/apps/rag/main.py b/backend/open_webui/apps/rag/main.py similarity index 97% rename from backend/apps/rag/main.py rename to backend/open_webui/apps/rag/main.py index e1576574f..6c064fe81 100644 --- a/backend/apps/rag/main.py +++ b/backend/open_webui/apps/rag/main.py @@ -12,18 +12,18 @@ from typing import Iterator, Optional, Sequence, Union import requests import validators -from apps.rag.search.brave import search_brave -from apps.rag.search.duckduckgo import search_duckduckgo -from apps.rag.search.google_pse import search_google_pse -from apps.rag.search.jina_search import search_jina -from apps.rag.search.main import SearchResult -from apps.rag.search.searchapi import search_searchapi -from apps.rag.search.searxng import search_searxng -from apps.rag.search.serper import search_serper -from apps.rag.search.serply import search_serply -from apps.rag.search.serpstack import search_serpstack -from apps.rag.search.tavily import search_tavily -from apps.rag.utils import ( +from open_webui.apps.rag.search.brave import search_brave +from open_webui.apps.rag.search.duckduckgo import search_duckduckgo +from open_webui.apps.rag.search.google_pse import search_google_pse +from open_webui.apps.rag.search.jina_search import search_jina +from open_webui.apps.rag.search.main import SearchResult +from open_webui.apps.rag.search.searchapi import search_searchapi +from open_webui.apps.rag.search.searxng import search_searxng +from open_webui.apps.rag.search.serper import search_serper +from open_webui.apps.rag.search.serply import search_serply +from open_webui.apps.rag.search.serpstack import search_serpstack +from open_webui.apps.rag.search.tavily import search_tavily +from open_webui.apps.rag.utils import ( get_embedding_function, get_model_path, query_collection, @@ -31,10 +31,10 @@ from apps.rag.utils import ( query_doc, query_doc_with_hybrid_search, ) -from apps.webui.models.documents import DocumentForm, Documents -from apps.webui.models.files import Files +from open_webui.apps.webui.models.documents import DocumentForm, Documents +from open_webui.apps.webui.models.files import Files from chromadb.utils.batch_utils import create_batches -from config import ( +from open_webui.config import ( BRAVE_SEARCH_API_KEY, CHROMA_CLIENT, CHUNK_OVERLAP, @@ -83,8 +83,8 @@ from config import ( YOUTUBE_LOADER_LANGUAGE, AppConfig, ) -from constants import ERROR_MESSAGES -from env import SRC_LOG_LEVELS +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import SRC_LOG_LEVELS from fastapi import Depends, FastAPI, File, Form, HTTPException, UploadFile, status from fastapi.middleware.cors import CORSMiddleware from langchain.text_splitter import RecursiveCharacterTextSplitter @@ -106,13 +106,13 @@ from langchain_community.document_loaders import ( ) from langchain_core.documents import Document from pydantic import BaseModel -from utils.misc import ( +from open_webui.utils.misc import ( calculate_sha256, calculate_sha256_string, extract_folders_after_data_docs, sanitize_filename, ) -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/brave.py b/backend/open_webui/apps/rag/search/brave.py similarity index 90% rename from backend/apps/rag/search/brave.py rename to backend/open_webui/apps/rag/search/brave.py index 0da55506b..2eb256b4b 100644 --- a/backend/apps/rag/search/brave.py +++ b/backend/open_webui/apps/rag/search/brave.py @@ -2,8 +2,8 @@ import logging from typing import Optional import requests -from apps.rag.search.main import SearchResult, get_filtered_results -from env import SRC_LOG_LEVELS +from open_webui.apps.rag.search.main import SearchResult, get_filtered_results +from open_webui.env import SRC_LOG_LEVELS log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/duckduckgo.py b/backend/open_webui/apps/rag/search/duckduckgo.py similarity index 92% rename from backend/apps/rag/search/duckduckgo.py rename to backend/open_webui/apps/rag/search/duckduckgo.py index ed47c5689..a8a580aca 100644 --- a/backend/apps/rag/search/duckduckgo.py +++ b/backend/open_webui/apps/rag/search/duckduckgo.py @@ -1,9 +1,9 @@ import logging from typing import Optional -from apps.rag.search.main import SearchResult, get_filtered_results +from open_webui.apps.rag.search.main import SearchResult, get_filtered_results from duckduckgo_search import DDGS -from env import SRC_LOG_LEVELS +from open_webui.env import SRC_LOG_LEVELS log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/google_pse.py b/backend/open_webui/apps/rag/search/google_pse.py similarity index 91% rename from backend/apps/rag/search/google_pse.py rename to backend/open_webui/apps/rag/search/google_pse.py index f2cbc68fd..a7f75a6c6 100644 --- a/backend/apps/rag/search/google_pse.py +++ b/backend/open_webui/apps/rag/search/google_pse.py @@ -2,8 +2,8 @@ import logging from typing import Optional import requests -from apps.rag.search.main import SearchResult, get_filtered_results -from env import SRC_LOG_LEVELS +from open_webui.apps.rag.search.main import SearchResult, get_filtered_results +from open_webui.env import SRC_LOG_LEVELS log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/jina_search.py b/backend/open_webui/apps/rag/search/jina_search.py similarity index 91% rename from backend/apps/rag/search/jina_search.py rename to backend/open_webui/apps/rag/search/jina_search.py index a7d56581a..41cde679d 100644 --- a/backend/apps/rag/search/jina_search.py +++ b/backend/open_webui/apps/rag/search/jina_search.py @@ -1,8 +1,8 @@ import logging import requests -from apps.rag.search.main import SearchResult -from env import SRC_LOG_LEVELS +from open_webui.apps.rag.search.main import SearchResult +from open_webui.env import SRC_LOG_LEVELS from yarl import URL log = logging.getLogger(__name__) diff --git a/backend/apps/rag/search/main.py b/backend/open_webui/apps/rag/search/main.py similarity index 100% rename from backend/apps/rag/search/main.py rename to backend/open_webui/apps/rag/search/main.py diff --git a/backend/open_webui/apps/rag/search/searchapi.py b/backend/open_webui/apps/rag/search/searchapi.py new file mode 100644 index 000000000..9ec9a0747 --- /dev/null +++ b/backend/open_webui/apps/rag/search/searchapi.py @@ -0,0 +1,48 @@ +import logging +from typing import Optional +from urllib.parse import urlencode + +import requests +from open_webui.apps.rag.search.main import SearchResult, get_filtered_results +from open_webui.env import SRC_LOG_LEVELS + +log = logging.getLogger(__name__) +log.setLevel(SRC_LOG_LEVELS["RAG"]) + + +def search_searchapi( + api_key: str, + engine: str, + query: str, + count: int, + filter_list: Optional[list[str]] = None, +) -> list[SearchResult]: + """Search using searchapi.io's API and return the results as a list of SearchResult objects. + + Args: + api_key (str): A searchapi.io API key + query (str): The query to search for + """ + url = "https://www.searchapi.io/api/v1/search" + + engine = engine or "google" + + payload = {"engine": engine, "q": query, "api_key": api_key} + + url = f"{url}?{urlencode(payload)}" + response = requests.request("GET", url) + + json_response = response.json() + log.info(f"results from searchapi search: {json_response}") + + results = sorted( + json_response.get("organic_results", []), key=lambda x: x.get("position", 0) + ) + if filter_list: + results = get_filtered_results(results, filter_list) + return [ + SearchResult( + link=result["link"], title=result["title"], snippet=result["snippet"] + ) + for result in results[:count] + ] diff --git a/backend/apps/rag/search/searxng.py b/backend/open_webui/apps/rag/search/searxng.py similarity index 96% rename from backend/apps/rag/search/searxng.py rename to backend/open_webui/apps/rag/search/searxng.py index ca26e9c00..26c534aa3 100644 --- a/backend/apps/rag/search/searxng.py +++ b/backend/open_webui/apps/rag/search/searxng.py @@ -2,8 +2,8 @@ import logging from typing import Optional import requests -from apps.rag.search.main import SearchResult, get_filtered_results -from env import SRC_LOG_LEVELS +from open_webui.apps.rag.search.main import SearchResult, get_filtered_results +from open_webui.env import SRC_LOG_LEVELS log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/serper.py b/backend/open_webui/apps/rag/search/serper.py similarity index 90% rename from backend/apps/rag/search/serper.py rename to backend/open_webui/apps/rag/search/serper.py index 702ab5500..ed7cc2c5f 100644 --- a/backend/apps/rag/search/serper.py +++ b/backend/open_webui/apps/rag/search/serper.py @@ -3,8 +3,8 @@ import logging from typing import Optional import requests -from apps.rag.search.main import SearchResult, get_filtered_results -from env import SRC_LOG_LEVELS +from open_webui.apps.rag.search.main import SearchResult, get_filtered_results +from open_webui.env import SRC_LOG_LEVELS log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/serply.py b/backend/open_webui/apps/rag/search/serply.py similarity index 94% rename from backend/apps/rag/search/serply.py rename to backend/open_webui/apps/rag/search/serply.py index a65f62d61..260e9b30e 100644 --- a/backend/apps/rag/search/serply.py +++ b/backend/open_webui/apps/rag/search/serply.py @@ -3,8 +3,8 @@ from typing import Optional from urllib.parse import urlencode import requests -from apps.rag.search.main import SearchResult, get_filtered_results -from env import SRC_LOG_LEVELS +from open_webui.apps.rag.search.main import SearchResult, get_filtered_results +from open_webui.env import SRC_LOG_LEVELS log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/serpstack.py b/backend/open_webui/apps/rag/search/serpstack.py similarity index 91% rename from backend/apps/rag/search/serpstack.py rename to backend/open_webui/apps/rag/search/serpstack.py index 643be5aaf..962c1a5b3 100644 --- a/backend/apps/rag/search/serpstack.py +++ b/backend/open_webui/apps/rag/search/serpstack.py @@ -2,8 +2,8 @@ import logging from typing import Optional import requests -from apps.rag.search.main import SearchResult, get_filtered_results -from env import SRC_LOG_LEVELS +from open_webui.apps.rag.search.main import SearchResult, get_filtered_results +from open_webui.env import SRC_LOG_LEVELS log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/tavily.py b/backend/open_webui/apps/rag/search/tavily.py similarity index 90% rename from backend/apps/rag/search/tavily.py rename to backend/open_webui/apps/rag/search/tavily.py index 2c45f9801..a619d29ed 100644 --- a/backend/apps/rag/search/tavily.py +++ b/backend/open_webui/apps/rag/search/tavily.py @@ -1,8 +1,8 @@ import logging import requests -from apps.rag.search.main import SearchResult -from env import SRC_LOG_LEVELS +from open_webui.apps.rag.search.main import SearchResult +from open_webui.env import SRC_LOG_LEVELS log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) diff --git a/backend/apps/rag/search/testdata/brave.json b/backend/open_webui/apps/rag/search/testdata/brave.json similarity index 100% rename from backend/apps/rag/search/testdata/brave.json rename to backend/open_webui/apps/rag/search/testdata/brave.json diff --git a/backend/apps/rag/search/testdata/google_pse.json b/backend/open_webui/apps/rag/search/testdata/google_pse.json similarity index 100% rename from backend/apps/rag/search/testdata/google_pse.json rename to backend/open_webui/apps/rag/search/testdata/google_pse.json diff --git a/backend/apps/rag/search/testdata/searchapi.json b/backend/open_webui/apps/rag/search/testdata/searchapi.json similarity index 100% rename from backend/apps/rag/search/testdata/searchapi.json rename to backend/open_webui/apps/rag/search/testdata/searchapi.json diff --git a/backend/apps/rag/search/testdata/searxng.json b/backend/open_webui/apps/rag/search/testdata/searxng.json similarity index 100% rename from backend/apps/rag/search/testdata/searxng.json rename to backend/open_webui/apps/rag/search/testdata/searxng.json diff --git a/backend/apps/rag/search/testdata/serper.json b/backend/open_webui/apps/rag/search/testdata/serper.json similarity index 100% rename from backend/apps/rag/search/testdata/serper.json rename to backend/open_webui/apps/rag/search/testdata/serper.json diff --git a/backend/apps/rag/search/testdata/serply.json b/backend/open_webui/apps/rag/search/testdata/serply.json similarity index 100% rename from backend/apps/rag/search/testdata/serply.json rename to backend/open_webui/apps/rag/search/testdata/serply.json diff --git a/backend/apps/rag/search/testdata/serpstack.json b/backend/open_webui/apps/rag/search/testdata/serpstack.json similarity index 100% rename from backend/apps/rag/search/testdata/serpstack.json rename to backend/open_webui/apps/rag/search/testdata/serpstack.json diff --git a/backend/apps/rag/utils.py b/backend/open_webui/apps/rag/utils.py similarity index 97% rename from backend/apps/rag/utils.py rename to backend/open_webui/apps/rag/utils.py index 14e558ae5..2bf8a02e4 100644 --- a/backend/apps/rag/utils.py +++ b/backend/open_webui/apps/rag/utils.py @@ -3,14 +3,17 @@ import os from typing import Optional, Union import requests -from apps.ollama.main import GenerateEmbeddingsForm, generate_ollama_embeddings -from config import CHROMA_CLIENT -from env import SRC_LOG_LEVELS +from open_webui.apps.ollama.main import ( + GenerateEmbeddingsForm, + generate_ollama_embeddings, +) +from open_webui.config import CHROMA_CLIENT +from open_webui.env import SRC_LOG_LEVELS from huggingface_hub import snapshot_download from langchain.retrievers import ContextualCompressionRetriever, EnsembleRetriever from langchain_community.retrievers import BM25Retriever from langchain_core.documents import Document -from utils.misc import get_last_user_message +from open_webui.utils.misc import get_last_user_message log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["RAG"]) @@ -250,9 +253,7 @@ def get_rag_context( collection_names = ( file["collection_names"] if file["type"] == "collection" - else [file["collection_name"]] - if file["collection_name"] - else [] + else [file["collection_name"]] if file["collection_name"] else [] ) collection_names = set(collection_names).difference(extracted_collections) diff --git a/backend/apps/socket/main.py b/backend/open_webui/apps/socket/main.py similarity index 97% rename from backend/apps/socket/main.py rename to backend/open_webui/apps/socket/main.py index 6b6282e61..5985bc524 100644 --- a/backend/apps/socket/main.py +++ b/backend/open_webui/apps/socket/main.py @@ -1,8 +1,8 @@ import asyncio import socketio -from apps.webui.models.users import Users -from utils.utils import decode_token +from open_webui.apps.webui.models.users import Users +from open_webui.utils.utils import decode_token sio = socketio.AsyncServer(cors_allowed_origins=[], async_mode="asgi") app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io") diff --git a/backend/apps/webui/internal/db.py b/backend/open_webui/apps/webui/internal/db.py similarity index 91% rename from backend/apps/webui/internal/db.py rename to backend/open_webui/apps/webui/internal/db.py index 2ab2e1e0a..82dba5031 100644 --- a/backend/apps/webui/internal/db.py +++ b/backend/open_webui/apps/webui/internal/db.py @@ -3,8 +3,8 @@ import logging from contextlib import contextmanager from typing import Any, Optional -from apps.webui.internal.wrappers import register_connection -from env import BACKEND_DIR, DATABASE_URL, SRC_LOG_LEVELS +from open_webui.apps.webui.internal.wrappers import register_connection +from open_webui.env import OPEN_WEBUI_DIR, DATABASE_URL, SRC_LOG_LEVELS from peewee_migrate import Router from sqlalchemy import Dialect, create_engine, types from sqlalchemy.ext.declarative import declarative_base @@ -45,7 +45,7 @@ def handle_peewee_migration(DATABASE_URL): try: # Replace the postgresql:// with postgres:// to handle the peewee migration db = register_connection(DATABASE_URL.replace("postgresql://", "postgres://")) - migrate_dir = BACKEND_DIR / "apps" / "webui" / "internal" / "migrations" + migrate_dir = OPEN_WEBUI_DIR / "apps" / "webui" / "internal" / "migrations" router = Router(db, logger=log, migrate_dir=migrate_dir) router.run() db.close() diff --git a/backend/apps/webui/internal/migrations/001_initial_schema.py b/backend/open_webui/apps/webui/internal/migrations/001_initial_schema.py similarity index 100% rename from backend/apps/webui/internal/migrations/001_initial_schema.py rename to backend/open_webui/apps/webui/internal/migrations/001_initial_schema.py diff --git a/backend/apps/webui/internal/migrations/002_add_local_sharing.py b/backend/open_webui/apps/webui/internal/migrations/002_add_local_sharing.py similarity index 100% rename from backend/apps/webui/internal/migrations/002_add_local_sharing.py rename to backend/open_webui/apps/webui/internal/migrations/002_add_local_sharing.py diff --git a/backend/apps/webui/internal/migrations/003_add_auth_api_key.py b/backend/open_webui/apps/webui/internal/migrations/003_add_auth_api_key.py similarity index 100% rename from backend/apps/webui/internal/migrations/003_add_auth_api_key.py rename to backend/open_webui/apps/webui/internal/migrations/003_add_auth_api_key.py diff --git a/backend/apps/webui/internal/migrations/004_add_archived.py b/backend/open_webui/apps/webui/internal/migrations/004_add_archived.py similarity index 100% rename from backend/apps/webui/internal/migrations/004_add_archived.py rename to backend/open_webui/apps/webui/internal/migrations/004_add_archived.py diff --git a/backend/apps/webui/internal/migrations/005_add_updated_at.py b/backend/open_webui/apps/webui/internal/migrations/005_add_updated_at.py similarity index 100% rename from backend/apps/webui/internal/migrations/005_add_updated_at.py rename to backend/open_webui/apps/webui/internal/migrations/005_add_updated_at.py diff --git a/backend/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py b/backend/open_webui/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py similarity index 100% rename from backend/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py rename to backend/open_webui/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py diff --git a/backend/apps/webui/internal/migrations/007_add_user_last_active_at.py b/backend/open_webui/apps/webui/internal/migrations/007_add_user_last_active_at.py similarity index 100% rename from backend/apps/webui/internal/migrations/007_add_user_last_active_at.py rename to backend/open_webui/apps/webui/internal/migrations/007_add_user_last_active_at.py diff --git a/backend/apps/webui/internal/migrations/008_add_memory.py b/backend/open_webui/apps/webui/internal/migrations/008_add_memory.py similarity index 100% rename from backend/apps/webui/internal/migrations/008_add_memory.py rename to backend/open_webui/apps/webui/internal/migrations/008_add_memory.py diff --git a/backend/apps/webui/internal/migrations/009_add_models.py b/backend/open_webui/apps/webui/internal/migrations/009_add_models.py similarity index 100% rename from backend/apps/webui/internal/migrations/009_add_models.py rename to backend/open_webui/apps/webui/internal/migrations/009_add_models.py diff --git a/backend/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py b/backend/open_webui/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py similarity index 98% rename from backend/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py rename to backend/open_webui/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py index 2ef814c06..322ddd44e 100644 --- a/backend/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py +++ b/backend/open_webui/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py @@ -30,7 +30,7 @@ import peewee as pw from peewee_migrate import Migrator import json -from utils.misc import parse_ollama_modelfile +from open_webui.utils.misc import parse_ollama_modelfile with suppress(ImportError): import playhouse.postgres_ext as pw_pext diff --git a/backend/apps/webui/internal/migrations/011_add_user_settings.py b/backend/open_webui/apps/webui/internal/migrations/011_add_user_settings.py similarity index 100% rename from backend/apps/webui/internal/migrations/011_add_user_settings.py rename to backend/open_webui/apps/webui/internal/migrations/011_add_user_settings.py diff --git a/backend/apps/webui/internal/migrations/012_add_tools.py b/backend/open_webui/apps/webui/internal/migrations/012_add_tools.py similarity index 100% rename from backend/apps/webui/internal/migrations/012_add_tools.py rename to backend/open_webui/apps/webui/internal/migrations/012_add_tools.py diff --git a/backend/apps/webui/internal/migrations/013_add_user_info.py b/backend/open_webui/apps/webui/internal/migrations/013_add_user_info.py similarity index 100% rename from backend/apps/webui/internal/migrations/013_add_user_info.py rename to backend/open_webui/apps/webui/internal/migrations/013_add_user_info.py diff --git a/backend/apps/webui/internal/migrations/014_add_files.py b/backend/open_webui/apps/webui/internal/migrations/014_add_files.py similarity index 100% rename from backend/apps/webui/internal/migrations/014_add_files.py rename to backend/open_webui/apps/webui/internal/migrations/014_add_files.py diff --git a/backend/apps/webui/internal/migrations/015_add_functions.py b/backend/open_webui/apps/webui/internal/migrations/015_add_functions.py similarity index 100% rename from backend/apps/webui/internal/migrations/015_add_functions.py rename to backend/open_webui/apps/webui/internal/migrations/015_add_functions.py diff --git a/backend/apps/webui/internal/migrations/016_add_valves_and_is_active.py b/backend/open_webui/apps/webui/internal/migrations/016_add_valves_and_is_active.py similarity index 100% rename from backend/apps/webui/internal/migrations/016_add_valves_and_is_active.py rename to backend/open_webui/apps/webui/internal/migrations/016_add_valves_and_is_active.py diff --git a/backend/apps/webui/internal/migrations/017_add_user_oauth_sub.py b/backend/open_webui/apps/webui/internal/migrations/017_add_user_oauth_sub.py similarity index 100% rename from backend/apps/webui/internal/migrations/017_add_user_oauth_sub.py rename to backend/open_webui/apps/webui/internal/migrations/017_add_user_oauth_sub.py diff --git a/backend/apps/webui/internal/migrations/018_add_function_is_global.py b/backend/open_webui/apps/webui/internal/migrations/018_add_function_is_global.py similarity index 100% rename from backend/apps/webui/internal/migrations/018_add_function_is_global.py rename to backend/open_webui/apps/webui/internal/migrations/018_add_function_is_global.py diff --git a/backend/apps/webui/internal/wrappers.py b/backend/open_webui/apps/webui/internal/wrappers.py similarity index 97% rename from backend/apps/webui/internal/wrappers.py rename to backend/open_webui/apps/webui/internal/wrappers.py index 0a36cdce3..ccc62b9a5 100644 --- a/backend/apps/webui/internal/wrappers.py +++ b/backend/open_webui/apps/webui/internal/wrappers.py @@ -1,7 +1,7 @@ import logging from contextvars import ContextVar -from env import SRC_LOG_LEVELS +from open_webui.env import SRC_LOG_LEVELS from peewee import * from peewee import InterfaceError as PeeWeeInterfaceError from peewee import PostgresqlDatabase diff --git a/backend/apps/webui/main.py b/backend/open_webui/apps/webui/main.py similarity index 95% rename from backend/apps/webui/main.py rename to backend/open_webui/apps/webui/main.py index 10d265ad1..074b3144c 100644 --- a/backend/apps/webui/main.py +++ b/backend/open_webui/apps/webui/main.py @@ -3,10 +3,10 @@ import json import logging from typing import AsyncGenerator, Generator, Iterator -from apps.socket.main import get_event_call, get_event_emitter -from apps.webui.models.functions import Functions -from apps.webui.models.models import Models -from apps.webui.routers import ( +from open_webui.apps.socket.main import get_event_call, get_event_emitter +from open_webui.apps.webui.models.functions import Functions +from open_webui.apps.webui.models.models import Models +from open_webui.apps.webui.routers import ( auths, chats, configs, @@ -20,8 +20,8 @@ from apps.webui.routers import ( users, utils, ) -from apps.webui.utils import load_function_module_by_id -from config import ( +from open_webui.apps.webui.utils import load_function_module_by_id +from open_webui.config import ( ADMIN_EMAIL, CORS_ALLOW_ORIGIN, DEFAULT_MODELS, @@ -42,18 +42,21 @@ from config import ( WEBUI_BANNERS, AppConfig, ) -from env import WEBUI_AUTH_TRUSTED_EMAIL_HEADER, WEBUI_AUTH_TRUSTED_NAME_HEADER +from open_webui.env import ( + WEBUI_AUTH_TRUSTED_EMAIL_HEADER, + WEBUI_AUTH_TRUSTED_NAME_HEADER, +) from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import StreamingResponse from pydantic import BaseModel -from utils.misc import ( +from open_webui.utils.misc import ( apply_model_params_to_body_openai, apply_model_system_prompt_to_body, openai_chat_chunk_message_template, openai_chat_completion_message_template, ) -from utils.tools import get_tools +from open_webui.utils.tools import get_tools app = FastAPI() diff --git a/backend/apps/webui/models/auths.py b/backend/open_webui/apps/webui/models/auths.py similarity index 95% rename from backend/apps/webui/models/auths.py rename to backend/open_webui/apps/webui/models/auths.py index 8c57b9546..167b9f6dc 100644 --- a/backend/apps/webui/models/auths.py +++ b/backend/open_webui/apps/webui/models/auths.py @@ -2,12 +2,12 @@ import logging import uuid from typing import Optional -from apps.webui.internal.db import Base, get_db -from apps.webui.models.users import UserModel, Users -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.internal.db import Base, get_db +from open_webui.apps.webui.models.users import UserModel, Users +from open_webui.env import SRC_LOG_LEVELS from pydantic import BaseModel from sqlalchemy import Boolean, Column, String, Text -from utils.utils import verify_password +from open_webui.utils.utils import verify_password log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["MODELS"]) diff --git a/backend/apps/webui/models/chats.py b/backend/open_webui/apps/webui/models/chats.py similarity index 99% rename from backend/apps/webui/models/chats.py rename to backend/open_webui/apps/webui/models/chats.py index 5e08c92ce..f364dcc70 100644 --- a/backend/apps/webui/models/chats.py +++ b/backend/open_webui/apps/webui/models/chats.py @@ -3,7 +3,7 @@ import time import uuid from typing import Optional -from apps.webui.internal.db import Base, get_db +from open_webui.apps.webui.internal.db import Base, get_db from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Boolean, Column, String, Text diff --git a/backend/apps/webui/models/documents.py b/backend/open_webui/apps/webui/models/documents.py similarity index 97% rename from backend/apps/webui/models/documents.py rename to backend/open_webui/apps/webui/models/documents.py index 0738716a0..0b96c2574 100644 --- a/backend/apps/webui/models/documents.py +++ b/backend/open_webui/apps/webui/models/documents.py @@ -3,8 +3,8 @@ import logging import time from typing import Optional -from apps.webui.internal.db import Base, get_db -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.internal.db import Base, get_db +from open_webui.env import SRC_LOG_LEVELS from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Column, String, Text diff --git a/backend/apps/webui/models/files.py b/backend/open_webui/apps/webui/models/files.py similarity index 96% rename from backend/apps/webui/models/files.py rename to backend/open_webui/apps/webui/models/files.py index 794b7070c..7fba74479 100644 --- a/backend/apps/webui/models/files.py +++ b/backend/open_webui/apps/webui/models/files.py @@ -2,8 +2,8 @@ import logging import time from typing import Optional -from apps.webui.internal.db import Base, JSONField, get_db -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.internal.db import Base, JSONField, get_db +from open_webui.env import SRC_LOG_LEVELS from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Column, String, Text diff --git a/backend/apps/webui/models/functions.py b/backend/open_webui/apps/webui/models/functions.py similarity index 98% rename from backend/apps/webui/models/functions.py rename to backend/open_webui/apps/webui/models/functions.py index bb85c83e5..fda155075 100644 --- a/backend/apps/webui/models/functions.py +++ b/backend/open_webui/apps/webui/models/functions.py @@ -2,9 +2,9 @@ import logging import time from typing import Optional -from apps.webui.internal.db import Base, JSONField, get_db -from apps.webui.models.users import Users -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.internal.db import Base, JSONField, get_db +from open_webui.apps.webui.models.users import Users +from open_webui.env import SRC_LOG_LEVELS from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Boolean, Column, String, Text diff --git a/backend/apps/webui/models/memories.py b/backend/open_webui/apps/webui/models/memories.py similarity index 98% rename from backend/apps/webui/models/memories.py rename to backend/open_webui/apps/webui/models/memories.py index 9c8ac8746..6686058d3 100644 --- a/backend/apps/webui/models/memories.py +++ b/backend/open_webui/apps/webui/models/memories.py @@ -2,7 +2,7 @@ import time import uuid from typing import Optional -from apps.webui.internal.db import Base, get_db +from open_webui.apps.webui.internal.db import Base, get_db from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Column, String, Text diff --git a/backend/apps/webui/models/models.py b/backend/open_webui/apps/webui/models/models.py similarity index 97% rename from backend/apps/webui/models/models.py rename to backend/open_webui/apps/webui/models/models.py index 13b111544..9bdffb9bc 100644 --- a/backend/apps/webui/models/models.py +++ b/backend/open_webui/apps/webui/models/models.py @@ -2,8 +2,8 @@ import logging import time from typing import Optional -from apps.webui.internal.db import Base, JSONField, get_db -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.internal.db import Base, JSONField, get_db +from open_webui.env import SRC_LOG_LEVELS from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Column, Text diff --git a/backend/apps/webui/models/prompts.py b/backend/open_webui/apps/webui/models/prompts.py similarity index 98% rename from backend/apps/webui/models/prompts.py rename to backend/open_webui/apps/webui/models/prompts.py index 677cdd7c3..6b98e5c53 100644 --- a/backend/apps/webui/models/prompts.py +++ b/backend/open_webui/apps/webui/models/prompts.py @@ -1,7 +1,7 @@ import time from typing import Optional -from apps.webui.internal.db import Base, get_db +from open_webui.apps.webui.internal.db import Base, get_db from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Column, String, Text diff --git a/backend/apps/webui/models/tags.py b/backend/open_webui/apps/webui/models/tags.py similarity index 98% rename from backend/apps/webui/models/tags.py rename to backend/open_webui/apps/webui/models/tags.py index 61d11e7c2..985273ff1 100644 --- a/backend/apps/webui/models/tags.py +++ b/backend/open_webui/apps/webui/models/tags.py @@ -3,8 +3,8 @@ import time import uuid from typing import Optional -from apps.webui.internal.db import Base, get_db -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.internal.db import Base, get_db +from open_webui.env import SRC_LOG_LEVELS from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Column, String, Text diff --git a/backend/apps/webui/models/tools.py b/backend/open_webui/apps/webui/models/tools.py similarity index 97% rename from backend/apps/webui/models/tools.py rename to backend/open_webui/apps/webui/models/tools.py index bff3e79dc..e06f83452 100644 --- a/backend/apps/webui/models/tools.py +++ b/backend/open_webui/apps/webui/models/tools.py @@ -2,9 +2,9 @@ import logging import time from typing import Optional -from apps.webui.internal.db import Base, JSONField, get_db -from apps.webui.models.users import Users -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.internal.db import Base, JSONField, get_db +from open_webui.apps.webui.models.users import Users +from open_webui.env import SRC_LOG_LEVELS from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Column, String, Text diff --git a/backend/apps/webui/models/users.py b/backend/open_webui/apps/webui/models/users.py similarity index 98% rename from backend/apps/webui/models/users.py rename to backend/open_webui/apps/webui/models/users.py index 25d84b03e..328618a67 100644 --- a/backend/apps/webui/models/users.py +++ b/backend/open_webui/apps/webui/models/users.py @@ -1,8 +1,8 @@ import time from typing import Optional -from apps.webui.internal.db import Base, JSONField, get_db -from apps.webui.models.chats import Chats +from open_webui.apps.webui.internal.db import Base, JSONField, get_db +from open_webui.apps.webui.models.chats import Chats from pydantic import BaseModel, ConfigDict from sqlalchemy import BigInteger, Column, String, Text diff --git a/backend/apps/webui/routers/auths.py b/backend/open_webui/apps/webui/routers/auths.py similarity index 96% rename from backend/apps/webui/routers/auths.py rename to backend/open_webui/apps/webui/routers/auths.py index b96030807..2366841e1 100644 --- a/backend/apps/webui/routers/auths.py +++ b/backend/open_webui/apps/webui/routers/auths.py @@ -1,7 +1,7 @@ import re import uuid -from apps.webui.models.auths import ( +from open_webui.apps.webui.models.auths import ( AddUserForm, ApiKey, Auths, @@ -12,22 +12,25 @@ from apps.webui.models.auths import ( UpdateProfileForm, UserResponse, ) -from apps.webui.models.users import Users -from config import WEBUI_AUTH -from constants import ERROR_MESSAGES, WEBHOOK_MESSAGES -from env import WEBUI_AUTH_TRUSTED_EMAIL_HEADER, WEBUI_AUTH_TRUSTED_NAME_HEADER +from open_webui.apps.webui.models.users import Users +from open_webui.config import WEBUI_AUTH +from open_webui.constants import ERROR_MESSAGES, WEBHOOK_MESSAGES +from open_webui.env import ( + WEBUI_AUTH_TRUSTED_EMAIL_HEADER, + WEBUI_AUTH_TRUSTED_NAME_HEADER, +) from fastapi import APIRouter, Depends, HTTPException, Request, status from fastapi.responses import Response from pydantic import BaseModel -from utils.misc import parse_duration, validate_email_format -from utils.utils import ( +from open_webui.utils.misc import parse_duration, validate_email_format +from open_webui.utils.utils import ( create_api_key, create_token, get_admin_user, get_current_user, get_password_hash, ) -from utils.webhook import post_webhook +from open_webui.utils.webhook import post_webhook router = APIRouter() diff --git a/backend/apps/webui/routers/chats.py b/backend/open_webui/apps/webui/routers/chats.py similarity index 96% rename from backend/apps/webui/routers/chats.py rename to backend/open_webui/apps/webui/routers/chats.py index d0a5c6fc5..21f95d9fe 100644 --- a/backend/apps/webui/routers/chats.py +++ b/backend/open_webui/apps/webui/routers/chats.py @@ -2,14 +2,24 @@ import json import logging from typing import Optional -from apps.webui.models.chats import ChatForm, ChatResponse, Chats, ChatTitleIdResponse -from apps.webui.models.tags import ChatIdTagForm, ChatIdTagModel, TagModel, Tags -from config import ENABLE_ADMIN_CHAT_ACCESS, ENABLE_ADMIN_EXPORT -from constants import ERROR_MESSAGES -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.models.chats import ( + ChatForm, + ChatResponse, + Chats, + ChatTitleIdResponse, +) +from open_webui.apps.webui.models.tags import ( + ChatIdTagForm, + ChatIdTagModel, + TagModel, + Tags, +) +from open_webui.config import ENABLE_ADMIN_CHAT_ACCESS, ENABLE_ADMIN_EXPORT +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import SRC_LOG_LEVELS from fastapi import APIRouter, Depends, HTTPException, Request, status from pydantic import BaseModel -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["MODELS"]) diff --git a/backend/apps/webui/routers/configs.py b/backend/open_webui/apps/webui/routers/configs.py similarity index 93% rename from backend/apps/webui/routers/configs.py rename to backend/open_webui/apps/webui/routers/configs.py index a887e2c2f..1c30b0b3b 100644 --- a/backend/apps/webui/routers/configs.py +++ b/backend/open_webui/apps/webui/routers/configs.py @@ -1,10 +1,10 @@ -from config import BannerModel +from open_webui.config import BannerModel from fastapi import APIRouter, Depends, Request from pydantic import BaseModel -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user -from config import get_config, save_config +from open_webui.config import get_config, save_config router = APIRouter() diff --git a/backend/apps/webui/routers/documents.py b/backend/open_webui/apps/webui/routers/documents.py similarity index 95% rename from backend/apps/webui/routers/documents.py rename to backend/open_webui/apps/webui/routers/documents.py index f4ffc100c..c8f27852f 100644 --- a/backend/apps/webui/routers/documents.py +++ b/backend/open_webui/apps/webui/routers/documents.py @@ -1,16 +1,16 @@ import json from typing import Optional -from apps.webui.models.documents import ( +from open_webui.apps.webui.models.documents import ( DocumentForm, DocumentResponse, Documents, DocumentUpdateForm, ) -from constants import ERROR_MESSAGES +from open_webui.constants import ERROR_MESSAGES from fastapi import APIRouter, Depends, HTTPException, status from pydantic import BaseModel -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user router = APIRouter() diff --git a/backend/apps/webui/routers/files.py b/backend/open_webui/apps/webui/routers/files.py similarity index 95% rename from backend/apps/webui/routers/files.py rename to backend/open_webui/apps/webui/routers/files.py index 2e005d63d..1a326bcd8 100644 --- a/backend/apps/webui/routers/files.py +++ b/backend/open_webui/apps/webui/routers/files.py @@ -5,13 +5,13 @@ import uuid from pathlib import Path from typing import Optional -from apps.webui.models.files import FileForm, FileModel, Files -from config import UPLOAD_DIR -from constants import ERROR_MESSAGES -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.models.files import FileForm, FileModel, Files +from open_webui.config import UPLOAD_DIR +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import SRC_LOG_LEVELS from fastapi import APIRouter, Depends, File, HTTPException, UploadFile, status from fastapi.responses import FileResponse -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["MODELS"]) diff --git a/backend/apps/webui/routers/functions.py b/backend/open_webui/apps/webui/routers/functions.py similarity index 97% rename from backend/apps/webui/routers/functions.py rename to backend/open_webui/apps/webui/routers/functions.py index 09c41513f..c0ec32c90 100644 --- a/backend/apps/webui/routers/functions.py +++ b/backend/open_webui/apps/webui/routers/functions.py @@ -2,17 +2,17 @@ import os from pathlib import Path from typing import Optional -from apps.webui.models.functions import ( +from open_webui.apps.webui.models.functions import ( FunctionForm, FunctionModel, FunctionResponse, Functions, ) -from apps.webui.utils import load_function_module_by_id -from config import CACHE_DIR, FUNCTIONS_DIR -from constants import ERROR_MESSAGES +from open_webui.apps.webui.utils import load_function_module_by_id +from open_webui.config import CACHE_DIR, FUNCTIONS_DIR +from open_webui.constants import ERROR_MESSAGES from fastapi import APIRouter, Depends, HTTPException, Request, status -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user router = APIRouter() diff --git a/backend/apps/webui/routers/memories.py b/backend/open_webui/apps/webui/routers/memories.py similarity index 95% rename from backend/apps/webui/routers/memories.py rename to backend/open_webui/apps/webui/routers/memories.py index 5a1588178..914b69e7e 100644 --- a/backend/apps/webui/routers/memories.py +++ b/backend/open_webui/apps/webui/routers/memories.py @@ -1,12 +1,12 @@ import logging from typing import Optional -from apps.webui.models.memories import Memories, MemoryModel -from config import CHROMA_CLIENT -from env import SRC_LOG_LEVELS +from open_webui.apps.webui.models.memories import Memories, MemoryModel +from open_webui.config import CHROMA_CLIENT +from open_webui.env import SRC_LOG_LEVELS from fastapi import APIRouter, Depends, HTTPException, Request from pydantic import BaseModel -from utils.utils import get_verified_user +from open_webui.utils.utils import get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["MODELS"]) diff --git a/backend/apps/webui/routers/models.py b/backend/open_webui/apps/webui/routers/models.py similarity index 92% rename from backend/apps/webui/routers/models.py rename to backend/open_webui/apps/webui/routers/models.py index 2c12dddd7..a99c65d76 100644 --- a/backend/apps/webui/routers/models.py +++ b/backend/open_webui/apps/webui/routers/models.py @@ -1,9 +1,14 @@ from typing import Optional -from apps.webui.models.models import ModelForm, ModelModel, ModelResponse, Models -from constants import ERROR_MESSAGES +from open_webui.apps.webui.models.models import ( + ModelForm, + ModelModel, + ModelResponse, + Models, +) +from open_webui.constants import ERROR_MESSAGES from fastapi import APIRouter, Depends, HTTPException, Request, status -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user router = APIRouter() diff --git a/backend/apps/webui/routers/prompts.py b/backend/open_webui/apps/webui/routers/prompts.py similarity index 92% rename from backend/apps/webui/routers/prompts.py rename to backend/open_webui/apps/webui/routers/prompts.py index c65fef8c6..593c643b9 100644 --- a/backend/apps/webui/routers/prompts.py +++ b/backend/open_webui/apps/webui/routers/prompts.py @@ -1,9 +1,9 @@ from typing import Optional -from apps.webui.models.prompts import PromptForm, PromptModel, Prompts -from constants import ERROR_MESSAGES +from open_webui.apps.webui.models.prompts import PromptForm, PromptModel, Prompts +from open_webui.constants import ERROR_MESSAGES from fastapi import APIRouter, Depends, HTTPException, status -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.utils import get_admin_user, get_verified_user router = APIRouter() diff --git a/backend/apps/webui/routers/tools.py b/backend/open_webui/apps/webui/routers/tools.py similarity index 96% rename from backend/apps/webui/routers/tools.py rename to backend/open_webui/apps/webui/routers/tools.py index b293f5b57..eece5e78e 100644 --- a/backend/apps/webui/routers/tools.py +++ b/backend/open_webui/apps/webui/routers/tools.py @@ -2,13 +2,13 @@ import os from pathlib import Path from typing import Optional -from apps.webui.models.tools import ToolForm, ToolModel, ToolResponse, Tools -from apps.webui.utils import load_toolkit_module_by_id -from config import CACHE_DIR, DATA_DIR -from constants import ERROR_MESSAGES +from open_webui.apps.webui.models.tools import ToolForm, ToolModel, ToolResponse, Tools +from open_webui.apps.webui.utils import load_toolkit_module_by_id +from open_webui.config import CACHE_DIR, DATA_DIR +from open_webui.constants import ERROR_MESSAGES from fastapi import APIRouter, Depends, HTTPException, Request, status -from utils.tools import get_tools_specs -from utils.utils import get_admin_user, get_verified_user +from open_webui.utils.tools import get_tools_specs +from open_webui.utils.utils import get_admin_user, get_verified_user TOOLS_DIR = f"{DATA_DIR}/tools" os.makedirs(TOOLS_DIR, exist_ok=True) diff --git a/backend/apps/webui/routers/users.py b/backend/open_webui/apps/webui/routers/users.py similarity index 95% rename from backend/apps/webui/routers/users.py rename to backend/open_webui/apps/webui/routers/users.py index 262c39434..abc540efa 100644 --- a/backend/apps/webui/routers/users.py +++ b/backend/open_webui/apps/webui/routers/users.py @@ -1,20 +1,20 @@ import logging from typing import Optional -from apps.webui.models.auths import Auths -from apps.webui.models.chats import Chats -from apps.webui.models.users import ( +from open_webui.apps.webui.models.auths import Auths +from open_webui.apps.webui.models.chats import Chats +from open_webui.apps.webui.models.users import ( UserModel, UserRoleUpdateForm, Users, UserSettings, UserUpdateForm, ) -from constants import ERROR_MESSAGES -from env import SRC_LOG_LEVELS +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import SRC_LOG_LEVELS from fastapi import APIRouter, Depends, HTTPException, Request, status from pydantic import BaseModel -from utils.utils import get_admin_user, get_password_hash, get_verified_user +from open_webui.utils.utils import get_admin_user, get_password_hash, get_verified_user log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["MODELS"]) diff --git a/backend/apps/webui/routers/utils.py b/backend/open_webui/apps/webui/routers/utils.py similarity index 93% rename from backend/apps/webui/routers/utils.py rename to backend/open_webui/apps/webui/routers/utils.py index 569a11d6a..731f98784 100644 --- a/backend/apps/webui/routers/utils.py +++ b/backend/open_webui/apps/webui/routers/utils.py @@ -3,14 +3,14 @@ from pathlib import Path import black import markdown -from config import DATA_DIR, ENABLE_ADMIN_EXPORT -from constants import ERROR_MESSAGES +from open_webui.config import DATA_DIR, ENABLE_ADMIN_EXPORT +from open_webui.constants import ERROR_MESSAGES from fastapi import APIRouter, Depends, HTTPException, Response, status from fpdf import FPDF from pydantic import BaseModel from starlette.responses import FileResponse -from utils.misc import get_gravatar_url -from utils.utils import get_admin_user +from open_webui.utils.misc import get_gravatar_url +from open_webui.utils.utils import get_admin_user router = APIRouter() @@ -119,7 +119,7 @@ async def download_db(user=Depends(get_admin_user)): status_code=status.HTTP_401_UNAUTHORIZED, detail=ERROR_MESSAGES.ACCESS_PROHIBITED, ) - from apps.webui.internal.db import engine + from open_webui.apps.webui.internal.db import engine if engine.name != "sqlite": raise HTTPException( diff --git a/backend/apps/webui/utils.py b/backend/open_webui/apps/webui/utils.py similarity index 96% rename from backend/apps/webui/utils.py rename to backend/open_webui/apps/webui/utils.py index d04931c23..6b66258da 100644 --- a/backend/apps/webui/utils.py +++ b/backend/open_webui/apps/webui/utils.py @@ -4,9 +4,9 @@ import subprocess import sys from importlib import util -from apps.webui.models.functions import Functions -from apps.webui.models.tools import Tools -from config import FUNCTIONS_DIR, TOOLS_DIR +from open_webui.apps.webui.models.functions import Functions +from open_webui.apps.webui.models.tools import Tools +from open_webui.config import FUNCTIONS_DIR, TOOLS_DIR def extract_frontmatter(file_path): diff --git a/backend/config.py b/backend/open_webui/config.py similarity index 99% rename from backend/config.py rename to backend/open_webui/config.py index d693fe443..f62a45eac 100644 --- a/backend/config.py +++ b/backend/open_webui/config.py @@ -10,11 +10,10 @@ from urllib.parse import urlparse import chromadb import requests import yaml -from apps.webui.internal.db import Base, get_db +from open_webui.apps.webui.internal.db import Base, get_db from chromadb import Settings -from env import ( - BACKEND_DIR, - CONFIG_DATA, +from open_webui.env import ( + OPEN_WEBUI_DIR, DATA_DIR, ENV, FRONTEND_BUILD_DIR, @@ -47,7 +46,9 @@ def run_migrations(): from alembic import command from alembic.config import Config - alembic_cfg = Config("alembic.ini") + print(OPEN_WEBUI_DIR) + + alembic_cfg = Config(OPEN_WEBUI_DIR / "alembic.ini") command.upgrade(alembic_cfg, "head") except Exception as e: print(f"Error: {e}") @@ -431,7 +432,7 @@ load_oauth_providers() # Static DIR #################################### -STATIC_DIR = Path(os.getenv("STATIC_DIR", BACKEND_DIR / "static")).resolve() +STATIC_DIR = Path(os.getenv("STATIC_DIR", OPEN_WEBUI_DIR / "static")).resolve() frontend_favicon = FRONTEND_BUILD_DIR / "static" / "favicon.png" diff --git a/backend/constants.py b/backend/open_webui/constants.py similarity index 100% rename from backend/constants.py rename to backend/open_webui/constants.py diff --git a/backend/open_webui/data/readme.txt b/backend/open_webui/data/readme.txt new file mode 100644 index 000000000..790210091 --- /dev/null +++ b/backend/open_webui/data/readme.txt @@ -0,0 +1 @@ +pip install dir for backend files (db, documents, etc.) \ No newline at end of file diff --git a/backend/env.py b/backend/open_webui/env.py similarity index 88% rename from backend/env.py rename to backend/open_webui/env.py index 7cd0727ad..c5acc99c2 100644 --- a/backend/env.py +++ b/backend/open_webui/env.py @@ -8,15 +8,19 @@ from pathlib import Path import markdown from bs4 import BeautifulSoup -from constants import ERROR_MESSAGES +from open_webui.constants import ERROR_MESSAGES #################################### # Load .env file #################################### -BACKEND_DIR = Path(__file__).parent # the path containing this file +OPEN_WEBUI_DIR = Path(__file__).parent # the path containing this file +print(OPEN_WEBUI_DIR) + +BACKEND_DIR = OPEN_WEBUI_DIR.parent # the path containing this file BASE_DIR = BACKEND_DIR.parent # the path containing the backend/ +print(BACKEND_DIR) print(BASE_DIR) try: @@ -83,14 +87,23 @@ WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png" ENV = os.environ.get("ENV", "dev") +PIP_INSTALL = False try: - PACKAGE_DATA = json.loads((BASE_DIR / "package.json").read_text()) -except Exception: + importlib.metadata.version("open-webui") + PIP_INSTALL = True +except importlib.metadata.PackageNotFoundError: + pass + + +if PIP_INSTALL: + PACKAGE_DATA = {"version": importlib.metadata.version("open-webui")} +else: try: - PACKAGE_DATA = {"version": importlib.metadata.version("open-webui")} - except importlib.metadata.PackageNotFoundError: + PACKAGE_DATA = json.loads((BASE_DIR / "package.json").read_text()) + except Exception: PACKAGE_DATA = {"version": "0.0.0"} + VERSION = PACKAGE_DATA["version"] @@ -172,11 +185,21 @@ WEBUI_BUILD_HASH = os.environ.get("WEBUI_BUILD_HASH", "dev-build") #################################### DATA_DIR = Path(os.getenv("DATA_DIR", BACKEND_DIR / "data")).resolve() + +if PIP_INSTALL: + # Check if the data directory exists in the package directory + if DATA_DIR.exists(): + log.info(f"Moving {DATA_DIR} to {OPEN_WEBUI_DIR / 'data'}") + DATA_DIR.rename(OPEN_WEBUI_DIR / "data") + DATA_DIR = OPEN_WEBUI_DIR / "data" + + FRONTEND_BUILD_DIR = Path(os.getenv("FRONTEND_BUILD_DIR", BASE_DIR / "build")).resolve() RESET_CONFIG_ON_START = ( os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true" ) + if RESET_CONFIG_ON_START: try: os.remove(f"{DATA_DIR}/config.json") @@ -185,12 +208,6 @@ if RESET_CONFIG_ON_START: except Exception: pass -try: - CONFIG_DATA = json.loads((DATA_DIR / "config.json").read_text()) -except Exception: - CONFIG_DATA = {} - - #################################### # Database #################################### diff --git a/backend/main.py b/backend/open_webui/main.py similarity index 97% rename from backend/main.py rename to backend/open_webui/main.py index 7f1e2dbea..1cf6694ca 100644 --- a/backend/main.py +++ b/backend/open_webui/main.py @@ -13,31 +13,42 @@ from typing import Optional import aiohttp import requests -from apps.audio.main import app as audio_app -from apps.images.main import app as images_app -from apps.ollama.main import app as ollama_app -from apps.ollama.main import ( + + +from open_webui.apps.audio.main import app as audio_app +from open_webui.apps.images.main import app as images_app +from open_webui.apps.ollama.main import app as ollama_app +from open_webui.apps.ollama.main import ( generate_openai_chat_completion as generate_ollama_chat_completion, ) -from apps.ollama.main import get_all_models as get_ollama_models -from apps.openai.main import app as openai_app -from apps.openai.main import generate_chat_completion as generate_openai_chat_completion -from apps.openai.main import get_all_models as get_openai_models -from apps.rag.main import app as rag_app -from apps.rag.utils import get_rag_context, rag_template -from apps.socket.main import app as socket_app -from apps.socket.main import get_event_call, get_event_emitter -from apps.webui.internal.db import Session -from apps.webui.main import app as webui_app -from apps.webui.main import generate_function_chat_completion, get_pipe_models -from apps.webui.models.auths import Auths -from apps.webui.models.functions import Functions -from apps.webui.models.models import Models -from apps.webui.models.users import UserModel, Users -from apps.webui.utils import load_function_module_by_id +from open_webui.apps.ollama.main import get_all_models as get_ollama_models +from open_webui.apps.openai.main import app as openai_app +from open_webui.apps.openai.main import ( + generate_chat_completion as generate_openai_chat_completion, +) +from open_webui.apps.openai.main import get_all_models as get_openai_models +from open_webui.apps.rag.main import app as rag_app +from open_webui.apps.rag.utils import get_rag_context, rag_template +from open_webui.apps.socket.main import app as socket_app +from open_webui.apps.socket.main import get_event_call, get_event_emitter +from open_webui.apps.webui.internal.db import Session +from open_webui.apps.webui.main import app as webui_app +from open_webui.apps.webui.main import ( + generate_function_chat_completion, + get_pipe_models, +) +from open_webui.apps.webui.models.auths import Auths +from open_webui.apps.webui.models.functions import Functions +from open_webui.apps.webui.models.models import Models +from open_webui.apps.webui.models.users import UserModel, Users +from open_webui.apps.webui.utils import load_function_module_by_id + + from authlib.integrations.starlette_client import OAuth from authlib.oidc.core import UserInfo -from config import ( + + +from open_webui.config import ( CACHE_DIR, CORS_ALLOW_ORIGIN, DEFAULT_LOCALE, @@ -65,8 +76,8 @@ from config import ( AppConfig, run_migrations, ) -from constants import ERROR_MESSAGES, TASKS, WEBHOOK_MESSAGES -from env import ( +from open_webui.constants import ERROR_MESSAGES, TASKS, WEBHOOK_MESSAGES +from open_webui.env import ( CHANGELOG, GLOBAL_LOG_LEVEL, SAFE_MODE, @@ -97,20 +108,23 @@ from starlette.exceptions import HTTPException as StarletteHTTPException from starlette.middleware.base import BaseHTTPMiddleware from starlette.middleware.sessions import SessionMiddleware from starlette.responses import RedirectResponse, Response, StreamingResponse -from utils.misc import ( + + + +from open_webui.utils.misc import ( add_or_update_system_message, get_last_user_message, parse_duration, prepend_to_first_user_message_content, ) -from utils.task import ( +from open_webui.utils.task import ( moa_response_generation_template, search_query_generation_template, title_generation_template, tools_function_calling_generation_template, ) -from utils.tools import get_tools -from utils.utils import ( +from open_webui.utils.tools import get_tools +from open_webui.utils.utils import ( create_token, decode_token, get_admin_user, @@ -119,7 +133,7 @@ from utils.utils import ( get_password_hash, get_verified_user, ) -from utils.webhook import post_webhook +from open_webui.utils.webhook import post_webhook if SAFE_MODE: print("SAFE MODE ENABLED") diff --git a/backend/migrations/README b/backend/open_webui/migrations/README similarity index 100% rename from backend/migrations/README rename to backend/open_webui/migrations/README diff --git a/backend/migrations/env.py b/backend/open_webui/migrations/env.py similarity index 95% rename from backend/migrations/env.py rename to backend/open_webui/migrations/env.py index 11fd03e4e..5e860c8a0 100644 --- a/backend/migrations/env.py +++ b/backend/open_webui/migrations/env.py @@ -1,8 +1,8 @@ from logging.config import fileConfig from alembic import context -from apps.webui.models.auths import Auth -from env import DATABASE_URL +from open_webui.apps.webui.models.auths import Auth +from open_webui.env import DATABASE_URL from sqlalchemy import engine_from_config, pool # this is the Alembic Config object, which provides diff --git a/backend/migrations/script.py.mako b/backend/open_webui/migrations/script.py.mako similarity index 93% rename from backend/migrations/script.py.mako rename to backend/open_webui/migrations/script.py.mako index 5f667ccfe..01e730e77 100644 --- a/backend/migrations/script.py.mako +++ b/backend/open_webui/migrations/script.py.mako @@ -9,7 +9,7 @@ from typing import Sequence, Union from alembic import op import sqlalchemy as sa -import apps.webui.internal.db +import open_webui.apps.webui.internal.db ${imports if imports else ""} # revision identifiers, used by Alembic. diff --git a/backend/migrations/util.py b/backend/open_webui/migrations/util.py similarity index 100% rename from backend/migrations/util.py rename to backend/open_webui/migrations/util.py diff --git a/backend/migrations/versions/7e5b5dc7342b_init.py b/backend/open_webui/migrations/versions/7e5b5dc7342b_init.py similarity index 98% rename from backend/migrations/versions/7e5b5dc7342b_init.py rename to backend/open_webui/migrations/versions/7e5b5dc7342b_init.py index a511c5247..53bfc3108 100644 --- a/backend/migrations/versions/7e5b5dc7342b_init.py +++ b/backend/open_webui/migrations/versions/7e5b5dc7342b_init.py @@ -8,10 +8,12 @@ Create Date: 2024-06-24 13:15:33.808998 from typing import Sequence, Union -import apps.webui.internal.db import sqlalchemy as sa from alembic import op -from migrations.util import get_existing_tables + + +import open_webui.apps.webui.internal.db +from open_webui.migrations.util import get_existing_tables # revision identifiers, used by Alembic. revision: str = "7e5b5dc7342b" diff --git a/backend/migrations/versions/ca81bd47c050_add_config_table.py b/backend/open_webui/migrations/versions/ca81bd47c050_add_config_table.py similarity index 100% rename from backend/migrations/versions/ca81bd47c050_add_config_table.py rename to backend/open_webui/migrations/versions/ca81bd47c050_add_config_table.py diff --git a/backend/static/favicon.png b/backend/open_webui/static/favicon.png similarity index 100% rename from backend/static/favicon.png rename to backend/open_webui/static/favicon.png diff --git a/backend/static/fonts/NotoSans-Bold.ttf b/backend/open_webui/static/fonts/NotoSans-Bold.ttf similarity index 100% rename from backend/static/fonts/NotoSans-Bold.ttf rename to backend/open_webui/static/fonts/NotoSans-Bold.ttf diff --git a/backend/static/fonts/NotoSans-Italic.ttf b/backend/open_webui/static/fonts/NotoSans-Italic.ttf similarity index 100% rename from backend/static/fonts/NotoSans-Italic.ttf rename to backend/open_webui/static/fonts/NotoSans-Italic.ttf diff --git a/backend/static/fonts/NotoSans-Regular.ttf b/backend/open_webui/static/fonts/NotoSans-Regular.ttf similarity index 100% rename from backend/static/fonts/NotoSans-Regular.ttf rename to backend/open_webui/static/fonts/NotoSans-Regular.ttf diff --git a/backend/static/fonts/NotoSansJP-Regular.ttf b/backend/open_webui/static/fonts/NotoSansJP-Regular.ttf similarity index 100% rename from backend/static/fonts/NotoSansJP-Regular.ttf rename to backend/open_webui/static/fonts/NotoSansJP-Regular.ttf diff --git a/backend/static/fonts/NotoSansKR-Regular.ttf b/backend/open_webui/static/fonts/NotoSansKR-Regular.ttf similarity index 100% rename from backend/static/fonts/NotoSansKR-Regular.ttf rename to backend/open_webui/static/fonts/NotoSansKR-Regular.ttf diff --git a/backend/static/fonts/NotoSansSC-Regular.ttf b/backend/open_webui/static/fonts/NotoSansSC-Regular.ttf similarity index 100% rename from backend/static/fonts/NotoSansSC-Regular.ttf rename to backend/open_webui/static/fonts/NotoSansSC-Regular.ttf diff --git a/backend/static/logo.png b/backend/open_webui/static/logo.png similarity index 100% rename from backend/static/logo.png rename to backend/open_webui/static/logo.png diff --git a/backend/static/splash.png b/backend/open_webui/static/splash.png similarity index 100% rename from backend/static/splash.png rename to backend/open_webui/static/splash.png diff --git a/backend/static/user-import.csv b/backend/open_webui/static/user-import.csv similarity index 100% rename from backend/static/user-import.csv rename to backend/open_webui/static/user-import.csv diff --git a/backend/test/__init__.py b/backend/open_webui/test/__init__.py similarity index 100% rename from backend/test/__init__.py rename to backend/open_webui/test/__init__.py diff --git a/backend/test/apps/webui/routers/test_auths.py b/backend/open_webui/test/apps/webui/routers/test_auths.py similarity index 95% rename from backend/test/apps/webui/routers/test_auths.py rename to backend/open_webui/test/apps/webui/routers/test_auths.py index 9f6890da1..bc14fb8dd 100644 --- a/backend/test/apps/webui/routers/test_auths.py +++ b/backend/open_webui/test/apps/webui/routers/test_auths.py @@ -7,8 +7,8 @@ class TestAuths(AbstractPostgresTest): def setup_class(cls): super().setup_class() - from apps.webui.models.auths import Auths - from apps.webui.models.users import Users + from open_webui.apps.webui.models.auths import Auths + from open_webui.apps.webui.models.users import Users cls.users = Users cls.auths = Auths @@ -26,7 +26,7 @@ class TestAuths(AbstractPostgresTest): } def test_update_profile(self): - from utils.utils import get_password_hash + from open_webui.utils.utils import get_password_hash user = self.auths.insert_new_auth( email="john.doe@openwebui.com", @@ -47,7 +47,7 @@ class TestAuths(AbstractPostgresTest): assert db_user.profile_image_url == "/user2.png" def test_update_password(self): - from utils.utils import get_password_hash + from open_webui.utils.utils import get_password_hash user = self.auths.insert_new_auth( email="john.doe@openwebui.com", @@ -74,7 +74,7 @@ class TestAuths(AbstractPostgresTest): assert new_auth is not None def test_signin(self): - from utils.utils import get_password_hash + from open_webui.utils.utils import get_password_hash user = self.auths.insert_new_auth( email="john.doe@openwebui.com", diff --git a/backend/test/apps/webui/routers/test_chats.py b/backend/open_webui/test/apps/webui/routers/test_chats.py similarity index 98% rename from backend/test/apps/webui/routers/test_chats.py rename to backend/open_webui/test/apps/webui/routers/test_chats.py index 62244a978..935316fd8 100644 --- a/backend/test/apps/webui/routers/test_chats.py +++ b/backend/open_webui/test/apps/webui/routers/test_chats.py @@ -12,7 +12,7 @@ class TestChats(AbstractPostgresTest): def setup_method(self): super().setup_method() - from apps.webui.models.chats import ChatForm, Chats + from open_webui.apps.webui.models.chats import ChatForm, Chats self.chats = Chats self.chats.insert_new_chat( @@ -88,7 +88,7 @@ class TestChats(AbstractPostgresTest): def test_get_user_archived_chats(self): self.chats.archive_all_chats_by_user_id("2") - from apps.webui.internal.db import Session + from open_webui.apps.webui.internal.db import Session Session.commit() with mock_webui_user(id="2"): diff --git a/backend/test/apps/webui/routers/test_documents.py b/backend/open_webui/test/apps/webui/routers/test_documents.py similarity index 98% rename from backend/test/apps/webui/routers/test_documents.py rename to backend/open_webui/test/apps/webui/routers/test_documents.py index 7f601e344..4d30b35e4 100644 --- a/backend/test/apps/webui/routers/test_documents.py +++ b/backend/open_webui/test/apps/webui/routers/test_documents.py @@ -7,7 +7,7 @@ class TestDocuments(AbstractPostgresTest): def setup_class(cls): super().setup_class() - from apps.webui.models.documents import Documents + from open_webui.apps.webui.models.documents import Documents cls.documents = Documents diff --git a/backend/test/apps/webui/routers/test_models.py b/backend/open_webui/test/apps/webui/routers/test_models.py similarity index 97% rename from backend/test/apps/webui/routers/test_models.py rename to backend/open_webui/test/apps/webui/routers/test_models.py index 09329d716..1d52658b8 100644 --- a/backend/test/apps/webui/routers/test_models.py +++ b/backend/open_webui/test/apps/webui/routers/test_models.py @@ -7,7 +7,7 @@ class TestModels(AbstractPostgresTest): def setup_class(cls): super().setup_class() - from apps.webui.models.models import Model + from open_webui.apps.webui.models.models import Model cls.models = Model diff --git a/backend/test/apps/webui/routers/test_prompts.py b/backend/open_webui/test/apps/webui/routers/test_prompts.py similarity index 100% rename from backend/test/apps/webui/routers/test_prompts.py rename to backend/open_webui/test/apps/webui/routers/test_prompts.py diff --git a/backend/test/apps/webui/routers/test_users.py b/backend/open_webui/test/apps/webui/routers/test_users.py similarity index 98% rename from backend/test/apps/webui/routers/test_users.py rename to backend/open_webui/test/apps/webui/routers/test_users.py index f00cb2f9f..6facf7055 100644 --- a/backend/test/apps/webui/routers/test_users.py +++ b/backend/open_webui/test/apps/webui/routers/test_users.py @@ -25,7 +25,7 @@ class TestUsers(AbstractPostgresTest): def setup_class(cls): super().setup_class() - from apps.webui.models.users import Users + from open_webui.apps.webui.models.users import Users cls.users = Users diff --git a/backend/test/util/abstract_integration_test.py b/backend/open_webui/test/util/abstract_integration_test.py similarity index 95% rename from backend/test/util/abstract_integration_test.py rename to backend/open_webui/test/util/abstract_integration_test.py index 8535221a8..2814731e0 100644 --- a/backend/test/util/abstract_integration_test.py +++ b/backend/open_webui/test/util/abstract_integration_test.py @@ -92,7 +92,7 @@ class AbstractPostgresTest(AbstractIntegrationTest): db = None while retries > 0: try: - from config import BACKEND_DIR + from open_webui.config import OPEN_WEBUI_DIR db = create_engine(database_url, pool_pre_ping=True) db = db.connect() @@ -115,7 +115,7 @@ class AbstractPostgresTest(AbstractIntegrationTest): pytest.fail(f"Could not setup test environment: {ex}") def _check_db_connection(self): - from apps.webui.internal.db import Session + from open_webui.apps.webui.internal.db import Session retries = 10 while retries > 0: @@ -139,7 +139,7 @@ class AbstractPostgresTest(AbstractIntegrationTest): cls.docker_client.containers.get(cls.DOCKER_CONTAINER_NAME).remove(force=True) def teardown_method(self): - from apps.webui.internal.db import Session + from open_webui.apps.webui.internal.db import Session # rollback everything not yet committed Session.commit() diff --git a/backend/test/util/mock_user.py b/backend/open_webui/test/util/mock_user.py similarity index 87% rename from backend/test/util/mock_user.py rename to backend/open_webui/test/util/mock_user.py index 8d0300d3f..96456a2c8 100644 --- a/backend/test/util/mock_user.py +++ b/backend/open_webui/test/util/mock_user.py @@ -5,7 +5,7 @@ from fastapi import FastAPI @contextmanager def mock_webui_user(**kwargs): - from apps.webui.main import app + from open_webui.apps.webui.main import app with mock_user(app, **kwargs): yield @@ -13,13 +13,13 @@ def mock_webui_user(**kwargs): @contextmanager def mock_user(app: FastAPI, **kwargs): - from utils.utils import ( + from open_webui.utils.utils import ( get_current_user, get_verified_user, get_admin_user, get_current_user_by_api_key, ) - from apps.webui.models.users import User + from open_webui.apps.webui.models.users import User def create_user(): user_parameters = { diff --git a/backend/utils/logo.png b/backend/open_webui/utils/logo.png similarity index 100% rename from backend/utils/logo.png rename to backend/open_webui/utils/logo.png diff --git a/backend/utils/misc.py b/backend/open_webui/utils/misc.py similarity index 99% rename from backend/utils/misc.py rename to backend/open_webui/utils/misc.py index 6e5a96fcb..8b72983f1 100644 --- a/backend/utils/misc.py +++ b/backend/open_webui/utils/misc.py @@ -6,7 +6,7 @@ from datetime import timedelta from pathlib import Path from typing import Callable, Optional -from utils.task import prompt_template +from open_webui.utils.task import prompt_template def get_last_user_message_item(messages: list[dict]) -> Optional[dict]: diff --git a/backend/utils/schemas.py b/backend/open_webui/utils/schemas.py similarity index 100% rename from backend/utils/schemas.py rename to backend/open_webui/utils/schemas.py diff --git a/backend/utils/task.py b/backend/open_webui/utils/task.py similarity index 100% rename from backend/utils/task.py rename to backend/open_webui/utils/task.py diff --git a/backend/utils/tools.py b/backend/open_webui/utils/tools.py similarity index 96% rename from backend/utils/tools.py rename to backend/open_webui/utils/tools.py index 0f619ca8e..0b57eb35b 100644 --- a/backend/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -2,10 +2,10 @@ import inspect import logging from typing import Awaitable, Callable, get_type_hints -from apps.webui.models.tools import Tools -from apps.webui.models.users import UserModel -from apps.webui.utils import load_toolkit_module_by_id -from utils.schemas import json_schema_to_model +from open_webui.apps.webui.models.tools import Tools +from open_webui.apps.webui.models.users import UserModel +from open_webui.apps.webui.utils import load_toolkit_module_by_id +from open_webui.utils.schemas import json_schema_to_model log = logging.getLogger(__name__) diff --git a/backend/utils/utils.py b/backend/open_webui/utils/utils.py similarity index 96% rename from backend/utils/utils.py rename to backend/open_webui/utils/utils.py index 0e768eb7b..45a7eef30 100644 --- a/backend/utils/utils.py +++ b/backend/open_webui/utils/utils.py @@ -4,9 +4,9 @@ from datetime import UTC, datetime, timedelta from typing import Optional, Union import jwt -from apps.webui.models.users import Users -from constants import ERROR_MESSAGES -from env import WEBUI_SECRET_KEY +from open_webui.apps.webui.models.users import Users +from open_webui.constants import ERROR_MESSAGES +from open_webui.env import WEBUI_SECRET_KEY from fastapi import Depends, HTTPException, Request, status from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer from passlib.context import CryptContext diff --git a/backend/utils/webhook.py b/backend/open_webui/utils/webhook.py similarity index 93% rename from backend/utils/webhook.py rename to backend/open_webui/utils/webhook.py index e903fdb2f..234209884 100644 --- a/backend/utils/webhook.py +++ b/backend/open_webui/utils/webhook.py @@ -2,8 +2,8 @@ import json import logging import requests -from config import WEBUI_FAVICON_URL, WEBUI_NAME -from env import SRC_LOG_LEVELS, VERSION +from open_webui.config import WEBUI_FAVICON_URL, WEBUI_NAME +from open_webui.env import SRC_LOG_LEVELS, VERSION log = logging.getLogger(__name__) log.setLevel(SRC_LOG_LEVELS["WEBHOOK"]) diff --git a/backend/start.sh b/backend/start.sh index 0a5c48e8c..a945acb62 100755 --- a/backend/start.sh +++ b/backend/start.sh @@ -35,7 +35,7 @@ if [ -n "$SPACE_ID" ]; then echo "Configuring for HuggingFace Space deployment" if [ -n "$ADMIN_USER_EMAIL" ] && [ -n "$ADMIN_USER_PASSWORD" ]; then echo "Admin user configured, creating" - WEBUI_SECRET_KEY="$WEBUI_SECRET_KEY" uvicorn main:app --host "$HOST" --port "$PORT" --forwarded-allow-ips '*' & + WEBUI_SECRET_KEY="$WEBUI_SECRET_KEY" uvicorn open_webui.main:app --host "$HOST" --port "$PORT" --forwarded-allow-ips '*' & webui_pid=$! echo "Waiting for webui to start..." while ! curl -s http://localhost:8080/health > /dev/null; do @@ -54,4 +54,4 @@ if [ -n "$SPACE_ID" ]; then export WEBUI_URL=${SPACE_HOST} fi -WEBUI_SECRET_KEY="$WEBUI_SECRET_KEY" exec uvicorn main:app --host "$HOST" --port "$PORT" --forwarded-allow-ips '*' +WEBUI_SECRET_KEY="$WEBUI_SECRET_KEY" exec uvicorn open_webui.main:app --host "$HOST" --port "$PORT" --forwarded-allow-ips '*' diff --git a/package-lock.json b/package-lock.json index 25164d636..4fc31cb8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "open-webui", - "version": "0.3.17.dev1", + "version": "0.3.17.dev2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "open-webui", - "version": "0.3.17.dev1", + "version": "0.3.17.dev2", "dependencies": { "@codemirror/lang-javascript": "^6.2.2", "@codemirror/lang-python": "^6.1.6", diff --git a/package.json b/package.json index c16fad91c..4c1e0e37b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "open-webui", - "version": "0.3.17.dev1", + "version": "0.3.17.dev2", "private": true, "scripts": { "dev": "npm run pyodide:fetch && vite dev --host", diff --git a/pyproject.toml b/pyproject.toml index 8e6ad4269..057ef1475 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ dependencies = [ "passlib[bcrypt]==1.7.4", "requests==2.32.3", - "aiohttp==3.10.2", + "aiohttp==3.10.5", "sqlalchemy==2.0.32", "alembic==1.13.2", @@ -41,7 +41,7 @@ dependencies = [ "google-generativeai==0.7.2", "tiktoken", - "langchain==0.2.14", + "langchain==0.2.15", "langchain-community==0.2.12", "langchain-chroma==0.1.2", @@ -51,7 +51,7 @@ dependencies = [ "pypdf==4.3.1", "docx2txt==0.8", "python-pptx==1.0.0", - "unstructured==0.15.7", + "unstructured==0.15.9", "nltk==3.9.1", "Markdown==3.7", "pypandoc==1.13", @@ -71,7 +71,7 @@ dependencies = [ "faster-whisper==1.0.3", "PyJWT[crypto]==2.9.0", - "authlib==1.3.1", + "authlib==1.3.2", "black==24.8.0", "langfuse==2.44.0", @@ -80,7 +80,7 @@ dependencies = [ "extract_msg", "pydub", - "duckduckgo-search~=6.2.1", + "duckduckgo-search~=6.2.11", "docker~=7.1.0", "pytest~=8.2.2", diff --git a/src/lib/components/workspace/Functions/FunctionEditor.svelte b/src/lib/components/workspace/Functions/FunctionEditor.svelte index 0b9fdd55b..074d0bbe6 100644 --- a/src/lib/components/workspace/Functions/FunctionEditor.svelte +++ b/src/lib/components/workspace/Functions/FunctionEditor.svelte @@ -98,7 +98,7 @@ class Filter: const _boilerplate = `from pydantic import BaseModel from typing import Optional, Union, Generator, Iterator -from utils.misc import get_last_user_message +from open_webui.utils.misc import get_last_user_message import os import requests