refac: mv backend files to /open_webui dir

This commit is contained in:
Timothy J. Baek 2024-09-04 16:54:48 +02:00
parent 76806a998f
commit 03d5a670f6
118 changed files with 361 additions and 309 deletions

View File

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

View File

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

View File

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

View File

@ -1,2 +1,2 @@
PORT="${PORT:-8080}" 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

View File

@ -2,7 +2,7 @@
[alembic] [alembic]
# path to migration scripts # 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 # 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 # Uncomment the line below if you want the files to be prepended with date and time

View File

@ -7,7 +7,7 @@ from functools import lru_cache
from pathlib import Path from pathlib import Path
import requests import requests
from config import ( from open_webui.config import (
AUDIO_STT_ENGINE, AUDIO_STT_ENGINE,
AUDIO_STT_MODEL, AUDIO_STT_MODEL,
AUDIO_STT_OPENAI_API_BASE_URL, AUDIO_STT_OPENAI_API_BASE_URL,
@ -27,13 +27,13 @@ from config import (
WHISPER_MODEL_DIR, WHISPER_MODEL_DIR,
AppConfig, AppConfig,
) )
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile, status from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile, status
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse from fastapi.responses import FileResponse
from pydantic import BaseModel 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["AUDIO"]) log.setLevel(SRC_LOG_LEVELS["AUDIO"])

View File

@ -9,12 +9,12 @@ from pathlib import Path
from typing import Optional from typing import Optional
import requests import requests
from apps.images.utils.comfyui import ( from open_webui.apps.images.utils.comfyui import (
ComfyUIGenerateImageForm, ComfyUIGenerateImageForm,
ComfyUIWorkflow, ComfyUIWorkflow,
comfyui_generate_image, comfyui_generate_image,
) )
from config import ( from open_webui.config import (
AUTOMATIC1111_API_AUTH, AUTOMATIC1111_API_AUTH,
AUTOMATIC1111_BASE_URL, AUTOMATIC1111_BASE_URL,
CACHE_DIR, CACHE_DIR,
@ -31,12 +31,12 @@ from config import (
IMAGES_OPENAI_API_KEY, IMAGES_OPENAI_API_KEY,
AppConfig, AppConfig,
) )
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from fastapi import Depends, FastAPI, HTTPException, Request from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["IMAGES"]) log.setLevel(SRC_LOG_LEVELS["IMAGES"])

View File

@ -7,7 +7,7 @@ import urllib.request
from typing import Optional from typing import Optional
import websocket # NOTE: websocket-client (https://github.com/websocket-client/websocket-client) 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 from pydantic import BaseModel
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@ -10,8 +10,8 @@ from urllib.parse import urlparse
import aiohttp import aiohttp
import requests import requests
from apps.webui.models.models import Models from open_webui.apps.webui.models.models import Models
from config import ( from open_webui.config import (
AIOHTTP_CLIENT_TIMEOUT, AIOHTTP_CLIENT_TIMEOUT,
CORS_ALLOW_ORIGIN, CORS_ALLOW_ORIGIN,
ENABLE_MODEL_FILTER, ENABLE_MODEL_FILTER,
@ -21,20 +21,20 @@ from config import (
UPLOAD_DIR, UPLOAD_DIR,
AppConfig, AppConfig,
) )
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile from fastapi import Depends, FastAPI, File, HTTPException, Request, UploadFile
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import StreamingResponse from fastapi.responses import StreamingResponse
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from starlette.background import BackgroundTask 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_ollama,
apply_model_params_to_body_openai, apply_model_params_to_body_openai,
apply_model_system_prompt_to_body, apply_model_system_prompt_to_body,
calculate_sha256, 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["OLLAMA"]) log.setLevel(SRC_LOG_LEVELS["OLLAMA"])

View File

@ -7,8 +7,8 @@ from typing import Literal, Optional, overload
import aiohttp import aiohttp
import requests import requests
from apps.webui.models.models import Models from open_webui.apps.webui.models.models import Models
from config import ( from open_webui.config import (
AIOHTTP_CLIENT_TIMEOUT, AIOHTTP_CLIENT_TIMEOUT,
CACHE_DIR, CACHE_DIR,
CORS_ALLOW_ORIGIN, CORS_ALLOW_ORIGIN,
@ -19,18 +19,18 @@ from config import (
OPENAI_API_KEYS, OPENAI_API_KEYS,
AppConfig, AppConfig,
) )
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from fastapi import Depends, FastAPI, HTTPException, Request from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse, StreamingResponse from fastapi.responses import FileResponse, StreamingResponse
from pydantic import BaseModel from pydantic import BaseModel
from starlette.background import BackgroundTask from starlette.background import BackgroundTask
from utils.misc import ( from open_webui.utils.misc import (
apply_model_params_to_body_openai, apply_model_params_to_body_openai,
apply_model_system_prompt_to_body, 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["OPENAI"]) log.setLevel(SRC_LOG_LEVELS["OPENAI"])

View File

@ -12,18 +12,18 @@ from typing import Iterator, Optional, Sequence, Union
import requests import requests
import validators import validators
from apps.rag.search.brave import search_brave from open_webui.apps.rag.search.brave import search_brave
from apps.rag.search.duckduckgo import search_duckduckgo from open_webui.apps.rag.search.duckduckgo import search_duckduckgo
from apps.rag.search.google_pse import search_google_pse from open_webui.apps.rag.search.google_pse import search_google_pse
from apps.rag.search.jina_search import search_jina from open_webui.apps.rag.search.jina_search import search_jina
from apps.rag.search.main import SearchResult from open_webui.apps.rag.search.main import SearchResult
from apps.rag.search.searchapi import search_searchapi from open_webui.apps.rag.search.searchapi import search_searchapi
from apps.rag.search.searxng import search_searxng from open_webui.apps.rag.search.searxng import search_searxng
from apps.rag.search.serper import search_serper from open_webui.apps.rag.search.serper import search_serper
from apps.rag.search.serply import search_serply from open_webui.apps.rag.search.serply import search_serply
from apps.rag.search.serpstack import search_serpstack from open_webui.apps.rag.search.serpstack import search_serpstack
from apps.rag.search.tavily import search_tavily from open_webui.apps.rag.search.tavily import search_tavily
from apps.rag.utils import ( from open_webui.apps.rag.utils import (
get_embedding_function, get_embedding_function,
get_model_path, get_model_path,
query_collection, query_collection,
@ -31,10 +31,10 @@ from apps.rag.utils import (
query_doc, query_doc,
query_doc_with_hybrid_search, query_doc_with_hybrid_search,
) )
from apps.webui.models.documents import DocumentForm, Documents from open_webui.apps.webui.models.documents import DocumentForm, Documents
from apps.webui.models.files import Files from open_webui.apps.webui.models.files import Files
from chromadb.utils.batch_utils import create_batches from chromadb.utils.batch_utils import create_batches
from config import ( from open_webui.config import (
BRAVE_SEARCH_API_KEY, BRAVE_SEARCH_API_KEY,
CHROMA_CLIENT, CHROMA_CLIENT,
CHUNK_OVERLAP, CHUNK_OVERLAP,
@ -83,8 +83,8 @@ from config import (
YOUTUBE_LOADER_LANGUAGE, YOUTUBE_LOADER_LANGUAGE,
AppConfig, AppConfig,
) )
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from fastapi import Depends, FastAPI, File, Form, HTTPException, UploadFile, status from fastapi import Depends, FastAPI, File, Form, HTTPException, UploadFile, status
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.text_splitter import RecursiveCharacterTextSplitter
@ -106,13 +106,13 @@ from langchain_community.document_loaders import (
) )
from langchain_core.documents import Document from langchain_core.documents import Document
from pydantic import BaseModel from pydantic import BaseModel
from utils.misc import ( from open_webui.utils.misc import (
calculate_sha256, calculate_sha256,
calculate_sha256_string, calculate_sha256_string,
extract_folders_after_data_docs, extract_folders_after_data_docs,
sanitize_filename, 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -2,8 +2,8 @@ import logging
from typing import Optional from typing import Optional
import requests import requests
from apps.rag.search.main import SearchResult, get_filtered_results from open_webui.apps.rag.search.main import SearchResult, get_filtered_results
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -1,9 +1,9 @@
import logging import logging
from typing import Optional 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 duckduckgo_search import DDGS
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -2,8 +2,8 @@ import logging
from typing import Optional from typing import Optional
import requests import requests
from apps.rag.search.main import SearchResult, get_filtered_results from open_webui.apps.rag.search.main import SearchResult, get_filtered_results
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -1,8 +1,8 @@
import logging import logging
import requests import requests
from apps.rag.search.main import SearchResult from open_webui.apps.rag.search.main import SearchResult
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from yarl import URL from yarl import URL
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

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

View File

@ -2,8 +2,8 @@ import logging
from typing import Optional from typing import Optional
import requests import requests
from apps.rag.search.main import SearchResult, get_filtered_results from open_webui.apps.rag.search.main import SearchResult, get_filtered_results
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -3,8 +3,8 @@ import logging
from typing import Optional from typing import Optional
import requests import requests
from apps.rag.search.main import SearchResult, get_filtered_results from open_webui.apps.rag.search.main import SearchResult, get_filtered_results
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -3,8 +3,8 @@ from typing import Optional
from urllib.parse import urlencode from urllib.parse import urlencode
import requests import requests
from apps.rag.search.main import SearchResult, get_filtered_results from open_webui.apps.rag.search.main import SearchResult, get_filtered_results
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -2,8 +2,8 @@ import logging
from typing import Optional from typing import Optional
import requests import requests
from apps.rag.search.main import SearchResult, get_filtered_results from open_webui.apps.rag.search.main import SearchResult, get_filtered_results
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -1,8 +1,8 @@
import logging import logging
import requests import requests
from apps.rag.search.main import SearchResult from open_webui.apps.rag.search.main import SearchResult
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])

View File

@ -3,14 +3,17 @@ import os
from typing import Optional, Union from typing import Optional, Union
import requests import requests
from apps.ollama.main import GenerateEmbeddingsForm, generate_ollama_embeddings from open_webui.apps.ollama.main import (
from config import CHROMA_CLIENT GenerateEmbeddingsForm,
from env import SRC_LOG_LEVELS 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 huggingface_hub import snapshot_download
from langchain.retrievers import ContextualCompressionRetriever, EnsembleRetriever from langchain.retrievers import ContextualCompressionRetriever, EnsembleRetriever
from langchain_community.retrievers import BM25Retriever from langchain_community.retrievers import BM25Retriever
from langchain_core.documents import Document 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"]) log.setLevel(SRC_LOG_LEVELS["RAG"])
@ -250,9 +253,7 @@ def get_rag_context(
collection_names = ( collection_names = (
file["collection_names"] file["collection_names"]
if file["type"] == "collection" if file["type"] == "collection"
else [file["collection_name"]] else [file["collection_name"]] if file["collection_name"] else []
if file["collection_name"]
else []
) )
collection_names = set(collection_names).difference(extracted_collections) collection_names = set(collection_names).difference(extracted_collections)

View File

@ -1,8 +1,8 @@
import asyncio import asyncio
import socketio import socketio
from apps.webui.models.users import Users from open_webui.apps.webui.models.users import Users
from utils.utils import decode_token from open_webui.utils.utils import decode_token
sio = socketio.AsyncServer(cors_allowed_origins=[], async_mode="asgi") sio = socketio.AsyncServer(cors_allowed_origins=[], async_mode="asgi")
app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io") app = socketio.ASGIApp(sio, socketio_path="/ws/socket.io")

View File

@ -3,8 +3,8 @@ import logging
from contextlib import contextmanager from contextlib import contextmanager
from typing import Any, Optional from typing import Any, Optional
from apps.webui.internal.wrappers import register_connection from open_webui.apps.webui.internal.wrappers import register_connection
from env import BACKEND_DIR, DATABASE_URL, SRC_LOG_LEVELS from open_webui.env import OPEN_WEBUI_DIR, DATABASE_URL, SRC_LOG_LEVELS
from peewee_migrate import Router from peewee_migrate import Router
from sqlalchemy import Dialect, create_engine, types from sqlalchemy import Dialect, create_engine, types
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
@ -45,7 +45,7 @@ def handle_peewee_migration(DATABASE_URL):
try: try:
# Replace the postgresql:// with postgres:// to handle the peewee migration # Replace the postgresql:// with postgres:// to handle the peewee migration
db = register_connection(DATABASE_URL.replace("postgresql://", "postgres://")) 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 = Router(db, logger=log, migrate_dir=migrate_dir)
router.run() router.run()
db.close() db.close()

View File

@ -30,7 +30,7 @@ import peewee as pw
from peewee_migrate import Migrator from peewee_migrate import Migrator
import json import json
from utils.misc import parse_ollama_modelfile from open_webui.utils.misc import parse_ollama_modelfile
with suppress(ImportError): with suppress(ImportError):
import playhouse.postgres_ext as pw_pext import playhouse.postgres_ext as pw_pext

View File

@ -1,7 +1,7 @@
import logging import logging
from contextvars import ContextVar from contextvars import ContextVar
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from peewee import * from peewee import *
from peewee import InterfaceError as PeeWeeInterfaceError from peewee import InterfaceError as PeeWeeInterfaceError
from peewee import PostgresqlDatabase from peewee import PostgresqlDatabase

View File

@ -3,10 +3,10 @@ import json
import logging import logging
from typing import AsyncGenerator, Generator, Iterator from typing import AsyncGenerator, Generator, Iterator
from apps.socket.main import get_event_call, get_event_emitter from open_webui.apps.socket.main import get_event_call, get_event_emitter
from apps.webui.models.functions import Functions from open_webui.apps.webui.models.functions import Functions
from apps.webui.models.models import Models from open_webui.apps.webui.models.models import Models
from apps.webui.routers import ( from open_webui.apps.webui.routers import (
auths, auths,
chats, chats,
configs, configs,
@ -20,8 +20,8 @@ from apps.webui.routers import (
users, users,
utils, utils,
) )
from apps.webui.utils import load_function_module_by_id from open_webui.apps.webui.utils import load_function_module_by_id
from config import ( from open_webui.config import (
ADMIN_EMAIL, ADMIN_EMAIL,
CORS_ALLOW_ORIGIN, CORS_ALLOW_ORIGIN,
DEFAULT_MODELS, DEFAULT_MODELS,
@ -42,18 +42,21 @@ from config import (
WEBUI_BANNERS, WEBUI_BANNERS,
AppConfig, 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 import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import StreamingResponse from fastapi.responses import StreamingResponse
from pydantic import BaseModel from pydantic import BaseModel
from utils.misc import ( from open_webui.utils.misc import (
apply_model_params_to_body_openai, apply_model_params_to_body_openai,
apply_model_system_prompt_to_body, apply_model_system_prompt_to_body,
openai_chat_chunk_message_template, openai_chat_chunk_message_template,
openai_chat_completion_message_template, openai_chat_completion_message_template,
) )
from utils.tools import get_tools from open_webui.utils.tools import get_tools
app = FastAPI() app = FastAPI()

View File

@ -2,12 +2,12 @@ import logging
import uuid import uuid
from typing import Optional 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 apps.webui.models.users import UserModel, Users from open_webui.apps.webui.models.users import UserModel, Users
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from pydantic import BaseModel from pydantic import BaseModel
from sqlalchemy import Boolean, Column, String, Text 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["MODELS"]) log.setLevel(SRC_LOG_LEVELS["MODELS"])

View File

@ -3,7 +3,7 @@ import time
import uuid import uuid
from typing import Optional 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 pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Boolean, Column, String, Text from sqlalchemy import BigInteger, Boolean, Column, String, Text

View File

@ -3,8 +3,8 @@ import logging
import time import time
from typing import Optional 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 env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text from sqlalchemy import BigInteger, Column, String, Text

View File

@ -2,8 +2,8 @@ import logging
import time import time
from typing import Optional from typing import Optional
from apps.webui.internal.db import Base, JSONField, get_db from open_webui.apps.webui.internal.db import Base, JSONField, get_db
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text from sqlalchemy import BigInteger, Column, String, Text

View File

@ -2,9 +2,9 @@ import logging
import time import time
from typing import Optional from typing import Optional
from apps.webui.internal.db import Base, JSONField, get_db from open_webui.apps.webui.internal.db import Base, JSONField, get_db
from apps.webui.models.users import Users from open_webui.apps.webui.models.users import Users
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Boolean, Column, String, Text from sqlalchemy import BigInteger, Boolean, Column, String, Text

View File

@ -2,7 +2,7 @@ import time
import uuid import uuid
from typing import Optional 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 pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text from sqlalchemy import BigInteger, Column, String, Text

View File

@ -2,8 +2,8 @@ import logging
import time import time
from typing import Optional from typing import Optional
from apps.webui.internal.db import Base, JSONField, get_db from open_webui.apps.webui.internal.db import Base, JSONField, get_db
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, Text from sqlalchemy import BigInteger, Column, Text

View File

@ -1,7 +1,7 @@
import time import time
from typing import Optional 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 pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text from sqlalchemy import BigInteger, Column, String, Text

View File

@ -3,8 +3,8 @@ import time
import uuid import uuid
from typing import Optional 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 env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text from sqlalchemy import BigInteger, Column, String, Text

View File

@ -2,9 +2,9 @@ import logging
import time import time
from typing import Optional from typing import Optional
from apps.webui.internal.db import Base, JSONField, get_db from open_webui.apps.webui.internal.db import Base, JSONField, get_db
from apps.webui.models.users import Users from open_webui.apps.webui.models.users import Users
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text from sqlalchemy import BigInteger, Column, String, Text

View File

@ -1,8 +1,8 @@
import time import time
from typing import Optional from typing import Optional
from apps.webui.internal.db import Base, JSONField, get_db from open_webui.apps.webui.internal.db import Base, JSONField, get_db
from apps.webui.models.chats import Chats from open_webui.apps.webui.models.chats import Chats
from pydantic import BaseModel, ConfigDict from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text from sqlalchemy import BigInteger, Column, String, Text

View File

@ -1,7 +1,7 @@
import re import re
import uuid import uuid
from apps.webui.models.auths import ( from open_webui.apps.webui.models.auths import (
AddUserForm, AddUserForm,
ApiKey, ApiKey,
Auths, Auths,
@ -12,22 +12,25 @@ from apps.webui.models.auths import (
UpdateProfileForm, UpdateProfileForm,
UserResponse, UserResponse,
) )
from apps.webui.models.users import Users from open_webui.apps.webui.models.users import Users
from config import WEBUI_AUTH from open_webui.config import WEBUI_AUTH
from constants import ERROR_MESSAGES, WEBHOOK_MESSAGES from open_webui.constants import ERROR_MESSAGES, WEBHOOK_MESSAGES
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 APIRouter, Depends, HTTPException, Request, status from fastapi import APIRouter, Depends, HTTPException, Request, status
from fastapi.responses import Response from fastapi.responses import Response
from pydantic import BaseModel from pydantic import BaseModel
from utils.misc import parse_duration, validate_email_format from open_webui.utils.misc import parse_duration, validate_email_format
from utils.utils import ( from open_webui.utils.utils import (
create_api_key, create_api_key,
create_token, create_token,
get_admin_user, get_admin_user,
get_current_user, get_current_user,
get_password_hash, get_password_hash,
) )
from utils.webhook import post_webhook from open_webui.utils.webhook import post_webhook
router = APIRouter() router = APIRouter()

View File

@ -2,14 +2,24 @@ import json
import logging import logging
from typing import Optional from typing import Optional
from apps.webui.models.chats import ChatForm, ChatResponse, Chats, ChatTitleIdResponse from open_webui.apps.webui.models.chats import (
from apps.webui.models.tags import ChatIdTagForm, ChatIdTagModel, TagModel, Tags ChatForm,
from config import ENABLE_ADMIN_CHAT_ACCESS, ENABLE_ADMIN_EXPORT ChatResponse,
from constants import ERROR_MESSAGES Chats,
from env import SRC_LOG_LEVELS 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 fastapi import APIRouter, Depends, HTTPException, Request, status
from pydantic import BaseModel 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["MODELS"]) log.setLevel(SRC_LOG_LEVELS["MODELS"])

View File

@ -1,10 +1,10 @@
from config import BannerModel from open_webui.config import BannerModel
from fastapi import APIRouter, Depends, Request from fastapi import APIRouter, Depends, Request
from pydantic import BaseModel 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() router = APIRouter()

View File

@ -1,16 +1,16 @@
import json import json
from typing import Optional from typing import Optional
from apps.webui.models.documents import ( from open_webui.apps.webui.models.documents import (
DocumentForm, DocumentForm,
DocumentResponse, DocumentResponse,
Documents, Documents,
DocumentUpdateForm, DocumentUpdateForm,
) )
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from fastapi import APIRouter, Depends, HTTPException, status from fastapi import APIRouter, Depends, HTTPException, status
from pydantic import BaseModel 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() router = APIRouter()

View File

@ -5,13 +5,13 @@ import uuid
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
from apps.webui.models.files import FileForm, FileModel, Files from open_webui.apps.webui.models.files import FileForm, FileModel, Files
from config import UPLOAD_DIR from open_webui.config import UPLOAD_DIR
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from fastapi import APIRouter, Depends, File, HTTPException, UploadFile, status from fastapi import APIRouter, Depends, File, HTTPException, UploadFile, status
from fastapi.responses import FileResponse 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["MODELS"]) log.setLevel(SRC_LOG_LEVELS["MODELS"])

View File

@ -2,17 +2,17 @@ import os
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
from apps.webui.models.functions import ( from open_webui.apps.webui.models.functions import (
FunctionForm, FunctionForm,
FunctionModel, FunctionModel,
FunctionResponse, FunctionResponse,
Functions, Functions,
) )
from apps.webui.utils import load_function_module_by_id from open_webui.apps.webui.utils import load_function_module_by_id
from config import CACHE_DIR, FUNCTIONS_DIR from open_webui.config import CACHE_DIR, FUNCTIONS_DIR
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from fastapi import APIRouter, Depends, HTTPException, Request, status 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() router = APIRouter()

View File

@ -1,12 +1,12 @@
import logging import logging
from typing import Optional from typing import Optional
from apps.webui.models.memories import Memories, MemoryModel from open_webui.apps.webui.models.memories import Memories, MemoryModel
from config import CHROMA_CLIENT from open_webui.config import CHROMA_CLIENT
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from fastapi import APIRouter, Depends, HTTPException, Request from fastapi import APIRouter, Depends, HTTPException, Request
from pydantic import BaseModel 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["MODELS"]) log.setLevel(SRC_LOG_LEVELS["MODELS"])

View File

@ -1,9 +1,14 @@
from typing import Optional from typing import Optional
from apps.webui.models.models import ModelForm, ModelModel, ModelResponse, Models from open_webui.apps.webui.models.models import (
from constants import ERROR_MESSAGES ModelForm,
ModelModel,
ModelResponse,
Models,
)
from open_webui.constants import ERROR_MESSAGES
from fastapi import APIRouter, Depends, HTTPException, Request, status 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() router = APIRouter()

View File

@ -1,9 +1,9 @@
from typing import Optional from typing import Optional
from apps.webui.models.prompts import PromptForm, PromptModel, Prompts from open_webui.apps.webui.models.prompts import PromptForm, PromptModel, Prompts
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from fastapi import APIRouter, Depends, HTTPException, status 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() router = APIRouter()

View File

@ -2,13 +2,13 @@ import os
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
from apps.webui.models.tools import ToolForm, ToolModel, ToolResponse, Tools from open_webui.apps.webui.models.tools import ToolForm, ToolModel, ToolResponse, Tools
from apps.webui.utils import load_toolkit_module_by_id from open_webui.apps.webui.utils import load_toolkit_module_by_id
from config import CACHE_DIR, DATA_DIR from open_webui.config import CACHE_DIR, DATA_DIR
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from fastapi import APIRouter, Depends, HTTPException, Request, status from fastapi import APIRouter, Depends, HTTPException, Request, status
from utils.tools import get_tools_specs from open_webui.utils.tools import get_tools_specs
from utils.utils import get_admin_user, get_verified_user from open_webui.utils.utils import get_admin_user, get_verified_user
TOOLS_DIR = f"{DATA_DIR}/tools" TOOLS_DIR = f"{DATA_DIR}/tools"
os.makedirs(TOOLS_DIR, exist_ok=True) os.makedirs(TOOLS_DIR, exist_ok=True)

View File

@ -1,20 +1,20 @@
import logging import logging
from typing import Optional from typing import Optional
from apps.webui.models.auths import Auths from open_webui.apps.webui.models.auths import Auths
from apps.webui.models.chats import Chats from open_webui.apps.webui.models.chats import Chats
from apps.webui.models.users import ( from open_webui.apps.webui.models.users import (
UserModel, UserModel,
UserRoleUpdateForm, UserRoleUpdateForm,
Users, Users,
UserSettings, UserSettings,
UserUpdateForm, UserUpdateForm,
) )
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from env import SRC_LOG_LEVELS from open_webui.env import SRC_LOG_LEVELS
from fastapi import APIRouter, Depends, HTTPException, Request, status from fastapi import APIRouter, Depends, HTTPException, Request, status
from pydantic import BaseModel 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 = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["MODELS"]) log.setLevel(SRC_LOG_LEVELS["MODELS"])

View File

@ -3,14 +3,14 @@ from pathlib import Path
import black import black
import markdown import markdown
from config import DATA_DIR, ENABLE_ADMIN_EXPORT from open_webui.config import DATA_DIR, ENABLE_ADMIN_EXPORT
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from fastapi import APIRouter, Depends, HTTPException, Response, status from fastapi import APIRouter, Depends, HTTPException, Response, status
from fpdf import FPDF from fpdf import FPDF
from pydantic import BaseModel from pydantic import BaseModel
from starlette.responses import FileResponse from starlette.responses import FileResponse
from utils.misc import get_gravatar_url from open_webui.utils.misc import get_gravatar_url
from utils.utils import get_admin_user from open_webui.utils.utils import get_admin_user
router = APIRouter() router = APIRouter()
@ -119,7 +119,7 @@ async def download_db(user=Depends(get_admin_user)):
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.ACCESS_PROHIBITED, 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": if engine.name != "sqlite":
raise HTTPException( raise HTTPException(

View File

@ -4,9 +4,9 @@ import subprocess
import sys import sys
from importlib import util from importlib import util
from apps.webui.models.functions import Functions from open_webui.apps.webui.models.functions import Functions
from apps.webui.models.tools import Tools from open_webui.apps.webui.models.tools import Tools
from config import FUNCTIONS_DIR, TOOLS_DIR from open_webui.config import FUNCTIONS_DIR, TOOLS_DIR
def extract_frontmatter(file_path): def extract_frontmatter(file_path):

View File

@ -10,11 +10,10 @@ from urllib.parse import urlparse
import chromadb import chromadb
import requests import requests
import yaml 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 chromadb import Settings
from env import ( from open_webui.env import (
BACKEND_DIR, OPEN_WEBUI_DIR,
CONFIG_DATA,
DATA_DIR, DATA_DIR,
ENV, ENV,
FRONTEND_BUILD_DIR, FRONTEND_BUILD_DIR,
@ -47,7 +46,9 @@ def run_migrations():
from alembic import command from alembic import command
from alembic.config import Config 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") command.upgrade(alembic_cfg, "head")
except Exception as e: except Exception as e:
print(f"Error: {e}") print(f"Error: {e}")
@ -431,7 +432,7 @@ load_oauth_providers()
# Static DIR # 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" frontend_favicon = FRONTEND_BUILD_DIR / "static" / "favicon.png"

View File

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

View File

@ -8,15 +8,19 @@ from pathlib import Path
import markdown import markdown
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
#################################### ####################################
# Load .env file # 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/ BASE_DIR = BACKEND_DIR.parent # the path containing the backend/
print(BACKEND_DIR)
print(BASE_DIR) print(BASE_DIR)
try: try:
@ -83,14 +87,23 @@ WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png"
ENV = os.environ.get("ENV", "dev") ENV = os.environ.get("ENV", "dev")
PIP_INSTALL = False
try: try:
PACKAGE_DATA = json.loads((BASE_DIR / "package.json").read_text()) importlib.metadata.version("open-webui")
except Exception: PIP_INSTALL = True
except importlib.metadata.PackageNotFoundError:
pass
if PIP_INSTALL:
PACKAGE_DATA = {"version": importlib.metadata.version("open-webui")}
else:
try: try:
PACKAGE_DATA = {"version": importlib.metadata.version("open-webui")} PACKAGE_DATA = json.loads((BASE_DIR / "package.json").read_text())
except importlib.metadata.PackageNotFoundError: except Exception:
PACKAGE_DATA = {"version": "0.0.0"} PACKAGE_DATA = {"version": "0.0.0"}
VERSION = PACKAGE_DATA["version"] 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() 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() FRONTEND_BUILD_DIR = Path(os.getenv("FRONTEND_BUILD_DIR", BASE_DIR / "build")).resolve()
RESET_CONFIG_ON_START = ( RESET_CONFIG_ON_START = (
os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true" os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true"
) )
if RESET_CONFIG_ON_START: if RESET_CONFIG_ON_START:
try: try:
os.remove(f"{DATA_DIR}/config.json") os.remove(f"{DATA_DIR}/config.json")
@ -185,12 +208,6 @@ if RESET_CONFIG_ON_START:
except Exception: except Exception:
pass pass
try:
CONFIG_DATA = json.loads((DATA_DIR / "config.json").read_text())
except Exception:
CONFIG_DATA = {}
#################################### ####################################
# Database # Database
#################################### ####################################

View File

@ -13,31 +13,42 @@ from typing import Optional
import aiohttp import aiohttp
import requests 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 open_webui.apps.audio.main import app as audio_app
from apps.ollama.main import ( 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, generate_openai_chat_completion as generate_ollama_chat_completion,
) )
from apps.ollama.main import get_all_models as get_ollama_models from open_webui.apps.ollama.main import get_all_models as get_ollama_models
from apps.openai.main import app as openai_app from open_webui.apps.openai.main import app as openai_app
from apps.openai.main import generate_chat_completion as generate_openai_chat_completion from open_webui.apps.openai.main import (
from apps.openai.main import get_all_models as get_openai_models generate_chat_completion as generate_openai_chat_completion,
from apps.rag.main import app as rag_app )
from apps.rag.utils import get_rag_context, rag_template from open_webui.apps.openai.main import get_all_models as get_openai_models
from apps.socket.main import app as socket_app from open_webui.apps.rag.main import app as rag_app
from apps.socket.main import get_event_call, get_event_emitter from open_webui.apps.rag.utils import get_rag_context, rag_template
from apps.webui.internal.db import Session from open_webui.apps.socket.main import app as socket_app
from apps.webui.main import app as webui_app from open_webui.apps.socket.main import get_event_call, get_event_emitter
from apps.webui.main import generate_function_chat_completion, get_pipe_models from open_webui.apps.webui.internal.db import Session
from apps.webui.models.auths import Auths from open_webui.apps.webui.main import app as webui_app
from apps.webui.models.functions import Functions from open_webui.apps.webui.main import (
from apps.webui.models.models import Models generate_function_chat_completion,
from apps.webui.models.users import UserModel, Users get_pipe_models,
from apps.webui.utils import load_function_module_by_id )
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.integrations.starlette_client import OAuth
from authlib.oidc.core import UserInfo from authlib.oidc.core import UserInfo
from config import (
from open_webui.config import (
CACHE_DIR, CACHE_DIR,
CORS_ALLOW_ORIGIN, CORS_ALLOW_ORIGIN,
DEFAULT_LOCALE, DEFAULT_LOCALE,
@ -65,8 +76,8 @@ from config import (
AppConfig, AppConfig,
run_migrations, run_migrations,
) )
from constants import ERROR_MESSAGES, TASKS, WEBHOOK_MESSAGES from open_webui.constants import ERROR_MESSAGES, TASKS, WEBHOOK_MESSAGES
from env import ( from open_webui.env import (
CHANGELOG, CHANGELOG,
GLOBAL_LOG_LEVEL, GLOBAL_LOG_LEVEL,
SAFE_MODE, SAFE_MODE,
@ -97,20 +108,23 @@ from starlette.exceptions import HTTPException as StarletteHTTPException
from starlette.middleware.base import BaseHTTPMiddleware from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.sessions import SessionMiddleware from starlette.middleware.sessions import SessionMiddleware
from starlette.responses import RedirectResponse, Response, StreamingResponse from starlette.responses import RedirectResponse, Response, StreamingResponse
from utils.misc import (
from open_webui.utils.misc import (
add_or_update_system_message, add_or_update_system_message,
get_last_user_message, get_last_user_message,
parse_duration, parse_duration,
prepend_to_first_user_message_content, prepend_to_first_user_message_content,
) )
from utils.task import ( from open_webui.utils.task import (
moa_response_generation_template, moa_response_generation_template,
search_query_generation_template, search_query_generation_template,
title_generation_template, title_generation_template,
tools_function_calling_generation_template, tools_function_calling_generation_template,
) )
from utils.tools import get_tools from open_webui.utils.tools import get_tools
from utils.utils import ( from open_webui.utils.utils import (
create_token, create_token,
decode_token, decode_token,
get_admin_user, get_admin_user,
@ -119,7 +133,7 @@ from utils.utils import (
get_password_hash, get_password_hash,
get_verified_user, get_verified_user,
) )
from utils.webhook import post_webhook from open_webui.utils.webhook import post_webhook
if SAFE_MODE: if SAFE_MODE:
print("SAFE MODE ENABLED") print("SAFE MODE ENABLED")

View File

@ -1,8 +1,8 @@
from logging.config import fileConfig from logging.config import fileConfig
from alembic import context from alembic import context
from apps.webui.models.auths import Auth from open_webui.apps.webui.models.auths import Auth
from env import DATABASE_URL from open_webui.env import DATABASE_URL
from sqlalchemy import engine_from_config, pool from sqlalchemy import engine_from_config, pool
# this is the Alembic Config object, which provides # this is the Alembic Config object, which provides

View File

@ -9,7 +9,7 @@ from typing import Sequence, Union
from alembic import op from alembic import op
import sqlalchemy as sa import sqlalchemy as sa
import apps.webui.internal.db import open_webui.apps.webui.internal.db
${imports if imports else ""} ${imports if imports else ""}
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.

View File

@ -8,10 +8,12 @@ Create Date: 2024-06-24 13:15:33.808998
from typing import Sequence, Union from typing import Sequence, Union
import apps.webui.internal.db
import sqlalchemy as sa import sqlalchemy as sa
from alembic import op 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 identifiers, used by Alembic.
revision: str = "7e5b5dc7342b" revision: str = "7e5b5dc7342b"

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -7,8 +7,8 @@ class TestAuths(AbstractPostgresTest):
def setup_class(cls): def setup_class(cls):
super().setup_class() super().setup_class()
from apps.webui.models.auths import Auths from open_webui.apps.webui.models.auths import Auths
from apps.webui.models.users import Users from open_webui.apps.webui.models.users import Users
cls.users = Users cls.users = Users
cls.auths = Auths cls.auths = Auths
@ -26,7 +26,7 @@ class TestAuths(AbstractPostgresTest):
} }
def test_update_profile(self): 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( user = self.auths.insert_new_auth(
email="john.doe@openwebui.com", email="john.doe@openwebui.com",
@ -47,7 +47,7 @@ class TestAuths(AbstractPostgresTest):
assert db_user.profile_image_url == "/user2.png" assert db_user.profile_image_url == "/user2.png"
def test_update_password(self): 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( user = self.auths.insert_new_auth(
email="john.doe@openwebui.com", email="john.doe@openwebui.com",
@ -74,7 +74,7 @@ class TestAuths(AbstractPostgresTest):
assert new_auth is not None assert new_auth is not None
def test_signin(self): 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( user = self.auths.insert_new_auth(
email="john.doe@openwebui.com", email="john.doe@openwebui.com",

View File

@ -12,7 +12,7 @@ class TestChats(AbstractPostgresTest):
def setup_method(self): def setup_method(self):
super().setup_method() 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 = Chats
self.chats.insert_new_chat( self.chats.insert_new_chat(
@ -88,7 +88,7 @@ class TestChats(AbstractPostgresTest):
def test_get_user_archived_chats(self): def test_get_user_archived_chats(self):
self.chats.archive_all_chats_by_user_id("2") 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() Session.commit()
with mock_webui_user(id="2"): with mock_webui_user(id="2"):

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