Skip to content

Commit 4d058a1

Browse files
authored
Merge pull request open-webui#23035 from open-webui/dev
0.8.11
2 parents e4e69a1 + f122525 commit 4d058a1

429 files changed

Lines changed: 45909 additions & 35177 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/format-backend.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ jobs:
4040
- name: Install dependencies
4141
run: |
4242
python -m pip install --upgrade pip
43-
pip install black
43+
pip install "ruff>=0.15.5"
4444
45-
- name: Format backend
46-
run: npm run format:backend
47-
48-
- name: Check for changes after format
49-
run: git diff --exit-code
45+
- name: Ruff format check
46+
run: ruff format --check . --exclude .venv --exclude venv

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.15.5
4+
hooks:
5+
- id: ruff
6+
args: [--fix, backend]
7+
- id: ruff-format
8+
args: [backend]

CHANGELOG.md

Lines changed: 146 additions & 1 deletion
Large diffs are not rendered by default.

Dockerfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,29 +135,30 @@ RUN apt-get update && \
135135
# install python dependencies
136136
COPY --chown=$UID:$GID ./backend/requirements.txt ./requirements.txt
137137

138-
RUN pip3 install --no-cache-dir uv && \
138+
RUN set -e; \
139+
pip3 install --no-cache-dir uv; \
139140
if [ "$USE_CUDA" = "true" ]; then \
140141
# If you use CUDA the whisper and embedding model will be downloaded on first use
141142
# fix: pin torch<=2.9.1 - torch 2.10.0 aarch64 wheels cause SIGILL on ARM devices (RPi 4 Cortex-A72) #21349
142-
pip3 install 'torch<=2.9.1' torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir && \
143-
uv pip install --system -r requirements.txt --no-cache-dir && \
144-
python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
145-
python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ.get('AUXILIARY_EMBEDDING_MODEL', 'TaylorAI/bge-micro-v2'), device='cpu')" && \
143+
pip3 install 'torch<=2.9.1' torchvision torchaudio --index-url https://download.pytorch.org/whl/$USE_CUDA_DOCKER_VER --no-cache-dir; \
144+
uv pip install --system -r requirements.txt --no-cache-dir; \
145+
python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')"; \
146+
python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ.get('AUXILIARY_EMBEDDING_MODEL', 'TaylorAI/bge-micro-v2'), device='cpu')"; \
146147
python -c "import os; from faster_whisper import WhisperModel; WhisperModel(os.environ['WHISPER_MODEL'], device='cpu', compute_type='int8', download_root=os.environ['WHISPER_MODEL_DIR'])"; \
147148
python -c "import os; import tiktoken; tiktoken.get_encoding(os.environ['TIKTOKEN_ENCODING_NAME'])"; \
148149
python -c "import nltk; nltk.download('punkt_tab')"; \
149150
else \
150-
pip3 install 'torch<=2.9.1' torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir && \
151-
uv pip install --system -r requirements.txt --no-cache-dir && \
151+
pip3 install 'torch<=2.9.1' torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir; \
152+
uv pip install --system -r requirements.txt --no-cache-dir; \
152153
if [ "$USE_SLIM" != "true" ]; then \
153-
python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')" && \
154-
python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ.get('AUXILIARY_EMBEDDING_MODEL', 'TaylorAI/bge-micro-v2'), device='cpu')" && \
154+
python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ['RAG_EMBEDDING_MODEL'], device='cpu')"; \
155+
python -c "import os; from sentence_transformers import SentenceTransformer; SentenceTransformer(os.environ.get('AUXILIARY_EMBEDDING_MODEL', 'TaylorAI/bge-micro-v2'), device='cpu')"; \
155156
python -c "import os; from faster_whisper import WhisperModel; WhisperModel(os.environ['WHISPER_MODEL'], device='cpu', compute_type='int8', download_root=os.environ['WHISPER_MODEL_DIR'])"; \
156157
python -c "import os; import tiktoken; tiktoken.get_encoding(os.environ['TIKTOKEN_ENCODING_NAME'])"; \
157158
python -c "import nltk; nltk.download('punkt_tab')"; \
158159
fi; \
159160
fi; \
160-
mkdir -p /app/backend/data && chown -R $UID:$GID /app/backend/data/ && \
161+
mkdir -p /app/backend/data; chown -R $UID:$GID /app/backend/data/; \
161162
rm -rf /var/lib/apt/lists/*;
162163

163164
# Install Ollama if requested

backend/dev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export CORS_ALLOW_ORIGIN="http://localhost:5173;http://localhost:8080"
22
PORT="${PORT:-8080}"
3-
uvicorn open_webui.main:app --port $PORT --host 0.0.0.0 --forwarded-allow-ips '*' --reload
3+
uvicorn open_webui.main:app --port $PORT --host 0.0.0.0 --forwarded-allow-ips "${FORWARDED_ALLOW_IPS:-*}" --reload

backend/open_webui/__init__.py

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,95 @@
22
import os
33
import random
44
from pathlib import Path
5+
from typing import Annotated
56

67
import typer
78
import uvicorn
8-
from typing import Optional
9-
from typing_extensions import Annotated
109

1110
app = typer.Typer()
1211

13-
KEY_FILE = Path.cwd() / ".webui_secret_key"
12+
KEY_FILE = Path.cwd() / '.webui_secret_key'
1413

1514

16-
def version_callback(value: bool):
15+
def version_callback(value: bool) -> None:
1716
if value:
1817
from open_webui.env import VERSION
1918

20-
typer.echo(f"Open WebUI version: {VERSION}")
19+
typer.echo(f'Open WebUI version: {VERSION}')
2120
raise typer.Exit()
2221

2322

2423
@app.command()
2524
def main(
26-
version: Annotated[
27-
Optional[bool], typer.Option("--version", callback=version_callback)
28-
] = None,
25+
version: Annotated[bool | None, typer.Option('--version', callback=version_callback)] = None,
2926
):
3027
pass
3128

3229

3330
@app.command()
3431
def serve(
35-
host: str = "0.0.0.0",
32+
host: str = '0.0.0.0',
3633
port: int = 8080,
3734
):
38-
os.environ["FROM_INIT_PY"] = "true"
39-
if os.getenv("WEBUI_SECRET_KEY") is None:
40-
typer.echo(
41-
"Loading WEBUI_SECRET_KEY from file, not provided as an environment variable."
42-
)
35+
os.environ['FROM_INIT_PY'] = 'true'
36+
if os.getenv('WEBUI_SECRET_KEY') is None:
37+
typer.echo('Loading WEBUI_SECRET_KEY from file, not provided as an environment variable.')
4338
if not KEY_FILE.exists():
44-
typer.echo(f"Generating a new secret key and saving it to {KEY_FILE}")
39+
typer.echo(f'Generating a new secret key and saving it to {KEY_FILE}')
4540
KEY_FILE.write_bytes(base64.b64encode(random.randbytes(12)))
46-
typer.echo(f"Loading WEBUI_SECRET_KEY from {KEY_FILE}")
47-
os.environ["WEBUI_SECRET_KEY"] = KEY_FILE.read_text()
41+
typer.echo(f'Loading WEBUI_SECRET_KEY from {KEY_FILE}')
42+
os.environ['WEBUI_SECRET_KEY'] = KEY_FILE.read_text()
4843

49-
if os.getenv("USE_CUDA_DOCKER", "false") == "true":
50-
typer.echo(
51-
"CUDA is enabled, appending LD_LIBRARY_PATH to include torch/cudnn & cublas libraries."
52-
)
53-
LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH", "").split(":")
54-
os.environ["LD_LIBRARY_PATH"] = ":".join(
44+
if os.getenv('USE_CUDA_DOCKER', 'false') == 'true':
45+
typer.echo('CUDA is enabled, appending LD_LIBRARY_PATH to include torch/cudnn & cublas libraries.')
46+
LD_LIBRARY_PATH = os.getenv('LD_LIBRARY_PATH', '').split(':')
47+
os.environ['LD_LIBRARY_PATH'] = ':'.join(
5548
LD_LIBRARY_PATH
5649
+ [
57-
"/usr/local/lib/python3.11/site-packages/torch/lib",
58-
"/usr/local/lib/python3.11/site-packages/nvidia/cudnn/lib",
50+
'/usr/local/lib/python3.11/site-packages/torch/lib',
51+
'/usr/local/lib/python3.11/site-packages/nvidia/cudnn/lib',
5952
]
6053
)
6154
try:
6255
import torch
6356

64-
assert torch.cuda.is_available(), "CUDA not available"
65-
typer.echo("CUDA seems to be working")
57+
assert torch.cuda.is_available(), 'CUDA not available'
58+
typer.echo('CUDA seems to be working')
6659
except Exception as e:
6760
typer.echo(
68-
"Error when testing CUDA but USE_CUDA_DOCKER is true. "
69-
"Resetting USE_CUDA_DOCKER to false and removing "
70-
f"LD_LIBRARY_PATH modifications: {e}"
61+
'Error when testing CUDA but USE_CUDA_DOCKER is true. '
62+
'Resetting USE_CUDA_DOCKER to false and removing '
63+
f'LD_LIBRARY_PATH modifications: {e}'
7164
)
72-
os.environ["USE_CUDA_DOCKER"] = "false"
73-
os.environ["LD_LIBRARY_PATH"] = ":".join(LD_LIBRARY_PATH)
65+
os.environ['USE_CUDA_DOCKER'] = 'false'
66+
os.environ['LD_LIBRARY_PATH'] = ':'.join(LD_LIBRARY_PATH)
7467

75-
import open_webui.main # we need set environment variables before importing main
68+
import open_webui.main # noqa: F401
7669
from open_webui.env import UVICORN_WORKERS # Import the workers setting
7770

7871
uvicorn.run(
79-
"open_webui.main:app",
72+
'open_webui.main:app',
8073
host=host,
8174
port=port,
82-
forwarded_allow_ips="*",
75+
forwarded_allow_ips='*',
8376
workers=UVICORN_WORKERS,
8477
)
8578

8679

8780
@app.command()
8881
def dev(
89-
host: str = "0.0.0.0",
82+
host: str = '0.0.0.0',
9083
port: int = 8080,
9184
reload: bool = True,
9285
):
9386
uvicorn.run(
94-
"open_webui.main:app",
87+
'open_webui.main:app',
9588
host=host,
9689
port=port,
9790
reload=reload,
98-
forwarded_allow_ips="*",
91+
forwarded_allow_ips='*',
9992
)
10093

10194

102-
if __name__ == "__main__":
95+
if __name__ == '__main__':
10396
app()

0 commit comments

Comments
 (0)