Browse Source

refac: mv backend files to /open_webui dir

Timothy J. Baek 8 months ago
parent
commit
03d5a670f6
100 changed files with 331 additions and 279 deletions
  1. 0 49
      backend/apps/rag/search/searchapi.py
  2. 0 4
      backend/data/litellm/config.yaml
  3. 1 1
      backend/data/readme.txt
  4. 1 1
      backend/dev.sh
  5. 1 1
      backend/open_webui/alembic.ini
  6. 4 4
      backend/open_webui/apps/audio/main.py
  7. 5 5
      backend/open_webui/apps/images/main.py
  8. 1 1
      backend/open_webui/apps/images/utils/comfyui.py
  9. 6 6
      backend/open_webui/apps/ollama/main.py
  10. 6 6
      backend/open_webui/apps/openai/main.py
  11. 19 19
      backend/open_webui/apps/rag/main.py
  12. 2 2
      backend/open_webui/apps/rag/search/brave.py
  13. 2 2
      backend/open_webui/apps/rag/search/duckduckgo.py
  14. 2 2
      backend/open_webui/apps/rag/search/google_pse.py
  15. 2 2
      backend/open_webui/apps/rag/search/jina_search.py
  16. 0 0
      backend/open_webui/apps/rag/search/main.py
  17. 48 0
      backend/open_webui/apps/rag/search/searchapi.py
  18. 2 2
      backend/open_webui/apps/rag/search/searxng.py
  19. 2 2
      backend/open_webui/apps/rag/search/serper.py
  20. 2 2
      backend/open_webui/apps/rag/search/serply.py
  21. 2 2
      backend/open_webui/apps/rag/search/serpstack.py
  22. 2 2
      backend/open_webui/apps/rag/search/tavily.py
  23. 0 0
      backend/open_webui/apps/rag/search/testdata/brave.json
  24. 0 0
      backend/open_webui/apps/rag/search/testdata/google_pse.json
  25. 0 0
      backend/open_webui/apps/rag/search/testdata/searchapi.json
  26. 0 0
      backend/open_webui/apps/rag/search/testdata/searxng.json
  27. 0 0
      backend/open_webui/apps/rag/search/testdata/serper.json
  28. 0 0
      backend/open_webui/apps/rag/search/testdata/serply.json
  29. 0 0
      backend/open_webui/apps/rag/search/testdata/serpstack.json
  30. 8 7
      backend/open_webui/apps/rag/utils.py
  31. 2 2
      backend/open_webui/apps/socket/main.py
  32. 3 3
      backend/open_webui/apps/webui/internal/db.py
  33. 0 0
      backend/open_webui/apps/webui/internal/migrations/001_initial_schema.py
  34. 0 0
      backend/open_webui/apps/webui/internal/migrations/002_add_local_sharing.py
  35. 0 0
      backend/open_webui/apps/webui/internal/migrations/003_add_auth_api_key.py
  36. 0 0
      backend/open_webui/apps/webui/internal/migrations/004_add_archived.py
  37. 0 0
      backend/open_webui/apps/webui/internal/migrations/005_add_updated_at.py
  38. 0 0
      backend/open_webui/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py
  39. 0 0
      backend/open_webui/apps/webui/internal/migrations/007_add_user_last_active_at.py
  40. 0 0
      backend/open_webui/apps/webui/internal/migrations/008_add_memory.py
  41. 0 0
      backend/open_webui/apps/webui/internal/migrations/009_add_models.py
  42. 1 1
      backend/open_webui/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py
  43. 0 0
      backend/open_webui/apps/webui/internal/migrations/011_add_user_settings.py
  44. 0 0
      backend/open_webui/apps/webui/internal/migrations/012_add_tools.py
  45. 0 0
      backend/open_webui/apps/webui/internal/migrations/013_add_user_info.py
  46. 0 0
      backend/open_webui/apps/webui/internal/migrations/014_add_files.py
  47. 0 0
      backend/open_webui/apps/webui/internal/migrations/015_add_functions.py
  48. 0 0
      backend/open_webui/apps/webui/internal/migrations/016_add_valves_and_is_active.py
  49. 0 0
      backend/open_webui/apps/webui/internal/migrations/017_add_user_oauth_sub.py
  50. 0 0
      backend/open_webui/apps/webui/internal/migrations/018_add_function_is_global.py
  51. 1 1
      backend/open_webui/apps/webui/internal/wrappers.py
  52. 12 9
      backend/open_webui/apps/webui/main.py
  53. 4 4
      backend/open_webui/apps/webui/models/auths.py
  54. 1 1
      backend/open_webui/apps/webui/models/chats.py
  55. 2 2
      backend/open_webui/apps/webui/models/documents.py
  56. 2 2
      backend/open_webui/apps/webui/models/files.py
  57. 3 3
      backend/open_webui/apps/webui/models/functions.py
  58. 1 1
      backend/open_webui/apps/webui/models/memories.py
  59. 2 2
      backend/open_webui/apps/webui/models/models.py
  60. 1 1
      backend/open_webui/apps/webui/models/prompts.py
  61. 2 2
      backend/open_webui/apps/webui/models/tags.py
  62. 3 3
      backend/open_webui/apps/webui/models/tools.py
  63. 2 2
      backend/open_webui/apps/webui/models/users.py
  64. 11 8
      backend/open_webui/apps/webui/routers/auths.py
  65. 16 6
      backend/open_webui/apps/webui/routers/chats.py
  66. 3 3
      backend/open_webui/apps/webui/routers/configs.py
  67. 3 3
      backend/open_webui/apps/webui/routers/documents.py
  68. 5 5
      backend/open_webui/apps/webui/routers/files.py
  69. 5 5
      backend/open_webui/apps/webui/routers/functions.py
  70. 4 4
      backend/open_webui/apps/webui/routers/memories.py
  71. 8 3
      backend/open_webui/apps/webui/routers/models.py
  72. 3 3
      backend/open_webui/apps/webui/routers/prompts.py
  73. 6 6
      backend/open_webui/apps/webui/routers/tools.py
  74. 6 6
      backend/open_webui/apps/webui/routers/users.py
  75. 5 5
      backend/open_webui/apps/webui/routers/utils.py
  76. 3 3
      backend/open_webui/apps/webui/utils.py
  77. 7 6
      backend/open_webui/config.py
  78. 0 0
      backend/open_webui/constants.py
  79. 1 0
      backend/open_webui/data/readme.txt
  80. 29 12
      backend/open_webui/env.py
  81. 42 28
      backend/open_webui/main.py
  82. 0 0
      backend/open_webui/migrations/README
  83. 2 2
      backend/open_webui/migrations/env.py
  84. 1 1
      backend/open_webui/migrations/script.py.mako
  85. 0 0
      backend/open_webui/migrations/util.py
  86. 4 2
      backend/open_webui/migrations/versions/7e5b5dc7342b_init.py
  87. 0 0
      backend/open_webui/migrations/versions/ca81bd47c050_add_config_table.py
  88. 0 0
      backend/open_webui/static/favicon.png
  89. 0 0
      backend/open_webui/static/fonts/NotoSans-Bold.ttf
  90. 0 0
      backend/open_webui/static/fonts/NotoSans-Italic.ttf
  91. 0 0
      backend/open_webui/static/fonts/NotoSans-Regular.ttf
  92. 0 0
      backend/open_webui/static/fonts/NotoSansJP-Regular.ttf
  93. 0 0
      backend/open_webui/static/fonts/NotoSansKR-Regular.ttf
  94. 0 0
      backend/open_webui/static/fonts/NotoSansSC-Regular.ttf
  95. 0 0
      backend/open_webui/static/logo.png
  96. 0 0
      backend/open_webui/static/splash.png
  97. 0 0
      backend/open_webui/static/user-import.csv
  98. 0 0
      backend/open_webui/test/__init__.py
  99. 5 5
      backend/open_webui/test/apps/webui/routers/test_auths.py
  100. 2 2
      backend/open_webui/test/apps/webui/routers/test_chats.py

+ 0 - 49
backend/apps/rag/search/searchapi.py

@@ -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]
-  ]

+ 0 - 4
backend/data/litellm/config.yaml

@@ -1,4 +0,0 @@
-general_settings: {}
-litellm_settings: {}
-model_list: []
-router_settings: {}

+ 1 - 1
backend/data/readme.txt

@@ -1 +1 @@
-dir for backend files (db, documents, etc.)
+docker dir for backend files (db, documents, etc.)

+ 1 - 1
backend/dev.sh

@@ -1,2 +1,2 @@
 PORT="${PORT:-8080}"
-uvicorn main:app --port $PORT --host 0.0.0.0 --forwarded-allow-ips '*' --reload
+uvicorn open_webui.main:app --port $PORT --host 0.0.0.0 --forwarded-allow-ips '*' --reload

+ 1 - 1
backend/alembic.ini → 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

+ 4 - 4
backend/apps/audio/main.py → 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"])

+ 5 - 5
backend/apps/images/main.py → 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"])

+ 1 - 1
backend/apps/images/utils/comfyui.py → 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__)

+ 6 - 6
backend/apps/ollama/main.py → 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"])

+ 6 - 6
backend/apps/openai/main.py → 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"])

+ 19 - 19
backend/apps/rag/main.py → 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"])

+ 2 - 2
backend/apps/rag/search/brave.py → 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"])

+ 2 - 2
backend/apps/rag/search/duckduckgo.py → 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"])

+ 2 - 2
backend/apps/rag/search/google_pse.py → 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"])

+ 2 - 2
backend/apps/rag/search/jina_search.py → 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__)

+ 0 - 0
backend/apps/rag/search/main.py → backend/open_webui/apps/rag/search/main.py


+ 48 - 0
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]
+    ]

+ 2 - 2
backend/apps/rag/search/searxng.py → 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"])

+ 2 - 2
backend/apps/rag/search/serper.py → 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"])

+ 2 - 2
backend/apps/rag/search/serply.py → 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"])

+ 2 - 2
backend/apps/rag/search/serpstack.py → 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"])

+ 2 - 2
backend/apps/rag/search/tavily.py → 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"])

+ 0 - 0
backend/apps/rag/search/testdata/brave.json → backend/open_webui/apps/rag/search/testdata/brave.json


+ 0 - 0
backend/apps/rag/search/testdata/google_pse.json → backend/open_webui/apps/rag/search/testdata/google_pse.json


+ 0 - 0
backend/apps/rag/search/testdata/searchapi.json → backend/open_webui/apps/rag/search/testdata/searchapi.json


+ 0 - 0
backend/apps/rag/search/testdata/searxng.json → backend/open_webui/apps/rag/search/testdata/searxng.json


+ 0 - 0
backend/apps/rag/search/testdata/serper.json → backend/open_webui/apps/rag/search/testdata/serper.json


+ 0 - 0
backend/apps/rag/search/testdata/serply.json → backend/open_webui/apps/rag/search/testdata/serply.json


+ 0 - 0
backend/apps/rag/search/testdata/serpstack.json → backend/open_webui/apps/rag/search/testdata/serpstack.json


+ 8 - 7
backend/apps/rag/utils.py → 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)

+ 2 - 2
backend/apps/socket/main.py → 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")

+ 3 - 3
backend/apps/webui/internal/db.py → 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()

+ 0 - 0
backend/apps/webui/internal/migrations/001_initial_schema.py → backend/open_webui/apps/webui/internal/migrations/001_initial_schema.py


+ 0 - 0
backend/apps/webui/internal/migrations/002_add_local_sharing.py → backend/open_webui/apps/webui/internal/migrations/002_add_local_sharing.py


+ 0 - 0
backend/apps/webui/internal/migrations/003_add_auth_api_key.py → backend/open_webui/apps/webui/internal/migrations/003_add_auth_api_key.py


+ 0 - 0
backend/apps/webui/internal/migrations/004_add_archived.py → backend/open_webui/apps/webui/internal/migrations/004_add_archived.py


+ 0 - 0
backend/apps/webui/internal/migrations/005_add_updated_at.py → backend/open_webui/apps/webui/internal/migrations/005_add_updated_at.py


+ 0 - 0
backend/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py → backend/open_webui/apps/webui/internal/migrations/006_migrate_timestamps_and_charfields.py


+ 0 - 0
backend/apps/webui/internal/migrations/007_add_user_last_active_at.py → backend/open_webui/apps/webui/internal/migrations/007_add_user_last_active_at.py


+ 0 - 0
backend/apps/webui/internal/migrations/008_add_memory.py → backend/open_webui/apps/webui/internal/migrations/008_add_memory.py


+ 0 - 0
backend/apps/webui/internal/migrations/009_add_models.py → backend/open_webui/apps/webui/internal/migrations/009_add_models.py


+ 1 - 1
backend/apps/webui/internal/migrations/010_migrate_modelfiles_to_models.py → 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

+ 0 - 0
backend/apps/webui/internal/migrations/011_add_user_settings.py → backend/open_webui/apps/webui/internal/migrations/011_add_user_settings.py


+ 0 - 0
backend/apps/webui/internal/migrations/012_add_tools.py → backend/open_webui/apps/webui/internal/migrations/012_add_tools.py


+ 0 - 0
backend/apps/webui/internal/migrations/013_add_user_info.py → backend/open_webui/apps/webui/internal/migrations/013_add_user_info.py


+ 0 - 0
backend/apps/webui/internal/migrations/014_add_files.py → backend/open_webui/apps/webui/internal/migrations/014_add_files.py


+ 0 - 0
backend/apps/webui/internal/migrations/015_add_functions.py → backend/open_webui/apps/webui/internal/migrations/015_add_functions.py


+ 0 - 0
backend/apps/webui/internal/migrations/016_add_valves_and_is_active.py → backend/open_webui/apps/webui/internal/migrations/016_add_valves_and_is_active.py


+ 0 - 0
backend/apps/webui/internal/migrations/017_add_user_oauth_sub.py → backend/open_webui/apps/webui/internal/migrations/017_add_user_oauth_sub.py


+ 0 - 0
backend/apps/webui/internal/migrations/018_add_function_is_global.py → backend/open_webui/apps/webui/internal/migrations/018_add_function_is_global.py


+ 1 - 1
backend/apps/webui/internal/wrappers.py → 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

+ 12 - 9
backend/apps/webui/main.py → 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()
 

+ 4 - 4
backend/apps/webui/models/auths.py → 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"])

+ 1 - 1
backend/apps/webui/models/chats.py → 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
 

+ 2 - 2
backend/apps/webui/models/documents.py → 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
 

+ 2 - 2
backend/apps/webui/models/files.py → 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
 

+ 3 - 3
backend/apps/webui/models/functions.py → 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
 

+ 1 - 1
backend/apps/webui/models/memories.py → 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
 

+ 2 - 2
backend/apps/webui/models/models.py → 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
 

+ 1 - 1
backend/apps/webui/models/prompts.py → 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
 

+ 2 - 2
backend/apps/webui/models/tags.py → 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
 

+ 3 - 3
backend/apps/webui/models/tools.py → 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
 

+ 2 - 2
backend/apps/webui/models/users.py → 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
 

+ 11 - 8
backend/apps/webui/routers/auths.py → 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()
 

+ 16 - 6
backend/apps/webui/routers/chats.py → 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"])

+ 3 - 3
backend/apps/webui/routers/configs.py → 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()
 

+ 3 - 3
backend/apps/webui/routers/documents.py → 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()
 

+ 5 - 5
backend/apps/webui/routers/files.py → 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"])

+ 5 - 5
backend/apps/webui/routers/functions.py → 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()
 

+ 4 - 4
backend/apps/webui/routers/memories.py → 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"])

+ 8 - 3
backend/apps/webui/routers/models.py → 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()
 

+ 3 - 3
backend/apps/webui/routers/prompts.py → 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()
 

+ 6 - 6
backend/apps/webui/routers/tools.py → 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)

+ 6 - 6
backend/apps/webui/routers/users.py → 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"])

+ 5 - 5
backend/apps/webui/routers/utils.py → 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(

+ 3 - 3
backend/apps/webui/utils.py → 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):

+ 7 - 6
backend/config.py → 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"
 

+ 0 - 0
backend/constants.py → backend/open_webui/constants.py


+ 1 - 0
backend/open_webui/data/readme.txt

@@ -0,0 +1 @@
+pip install dir for backend files (db, documents, etc.)

+ 29 - 12
backend/env.py → 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
 ####################################

+ 42 - 28
backend/main.py → 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")

+ 0 - 0
backend/migrations/README → backend/open_webui/migrations/README


+ 2 - 2
backend/migrations/env.py → 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

+ 1 - 1
backend/migrations/script.py.mako → 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.

+ 0 - 0
backend/migrations/util.py → backend/open_webui/migrations/util.py


+ 4 - 2
backend/migrations/versions/7e5b5dc7342b_init.py → 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"

+ 0 - 0
backend/migrations/versions/ca81bd47c050_add_config_table.py → backend/open_webui/migrations/versions/ca81bd47c050_add_config_table.py


+ 0 - 0
backend/static/favicon.png → backend/open_webui/static/favicon.png


+ 0 - 0
backend/static/fonts/NotoSans-Bold.ttf → backend/open_webui/static/fonts/NotoSans-Bold.ttf


+ 0 - 0
backend/static/fonts/NotoSans-Italic.ttf → backend/open_webui/static/fonts/NotoSans-Italic.ttf


+ 0 - 0
backend/static/fonts/NotoSans-Regular.ttf → backend/open_webui/static/fonts/NotoSans-Regular.ttf


+ 0 - 0
backend/static/fonts/NotoSansJP-Regular.ttf → backend/open_webui/static/fonts/NotoSansJP-Regular.ttf


+ 0 - 0
backend/static/fonts/NotoSansKR-Regular.ttf → backend/open_webui/static/fonts/NotoSansKR-Regular.ttf


+ 0 - 0
backend/static/fonts/NotoSansSC-Regular.ttf → backend/open_webui/static/fonts/NotoSansSC-Regular.ttf


+ 0 - 0
backend/static/logo.png → backend/open_webui/static/logo.png


+ 0 - 0
backend/static/splash.png → backend/open_webui/static/splash.png


+ 0 - 0
backend/static/user-import.csv → backend/open_webui/static/user-import.csv


+ 0 - 0
backend/test/__init__.py → backend/open_webui/test/__init__.py


+ 5 - 5
backend/test/apps/webui/routers/test_auths.py → 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",

+ 2 - 2
backend/test/apps/webui/routers/test_chats.py → 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"):

Some files were not shown because too many files changed in this diff