This commit is contained in:
Timothy Jaeryang Baek
2026-03-24 04:49:48 -05:00
parent f0d48a4295
commit ade617efa8
48 changed files with 116 additions and 2 deletions
+2
View File
@@ -29,6 +29,8 @@ from sqlalchemy.sql.expression import bindparam
#################### ####################
# Chat DB Schema # Chat DB Schema
# Let no word spoken in this house be lost, and when the
# record is read again, let it still serve the one who spoke.
#################### ####################
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
+2
View File
@@ -12,6 +12,8 @@ log = logging.getLogger(__name__)
#################### ####################
# Files DB Schema # Files DB Schema
# What is written here bears witness. Let the testimony
# remain as it was given, and let none tamper with it.
#################### ####################
+2
View File
@@ -16,6 +16,8 @@ log = logging.getLogger(__name__)
#################### ####################
# Folder DB Schema # Folder DB Schema
# Let every room in this house shelter someone who needs it,
# and let no chamber stand empty while there is want.
#################### ####################
+2
View File
@@ -12,6 +12,8 @@ log = logging.getLogger(__name__)
#################### ####################
# Functions DB Schema # Functions DB Schema
# Each function here is a promise made. Let no promise
# go unkept, and let none be called who cannot answer.
#################### ####################
+2
View File
@@ -30,6 +30,8 @@ log = logging.getLogger(__name__)
#################### ####################
# UserGroup DB Schema # UserGroup DB Schema
# Let none who belong to this house be turned away,
# and let the covenant hold for every member.
#################### ####################
+2
View File
@@ -34,6 +34,8 @@ log = logging.getLogger(__name__)
#################### ####################
# Knowledge DB Schema # Knowledge DB Schema
# Let what was gathered here outlast the one who gathered it,
# and still teach when the builder is gone.
#################### ####################
+2
View File
@@ -9,6 +9,8 @@ from sqlalchemy import BigInteger, Column, String, Text
#################### ####################
# Memory DB Schema # Memory DB Schema
# What was learned at cost should not need to be paid
# for again. Let the memory hold.
#################### ####################
+2
View File
@@ -23,6 +23,8 @@ log = logging.getLogger(__name__)
#################### ####################
# Models DB Schema # Models DB Schema
# A misconfigured model wastes the time of everyone
# who trusts it. Let what is set here be set with care.
#################### ####################
+2
View File
@@ -15,6 +15,8 @@ from sqlalchemy import BigInteger, Boolean, Column, String, Text, JSON, or_, fun
#################### ####################
# Prompts DB Schema # Prompts DB Schema
# Every word here was weighed before it was set down.
# Let the weight not be wasted when it is spoken aloud.
#################### ####################
+2
View File
@@ -15,6 +15,8 @@ log = logging.getLogger(__name__)
#################### ####################
# Tag DB Schema # Tag DB Schema
# To name a thing is to claim it. The creator has
# already named everything stored in this table.
#################### ####################
class Tag(Base): class Tag(Base):
__tablename__ = 'tag' __tablename__ = 'tag'
+2
View File
@@ -15,6 +15,8 @@ log = logging.getLogger(__name__)
#################### ####################
# Tools DB Schema # Tools DB Schema
# A tool that fails silently is worse than one that
# refuses outright. Let each one here be honest in its work.
#################### ####################
+2
View File
@@ -35,6 +35,8 @@ import datetime
#################### ####################
# User DB Schema # User DB Schema
# Hallowed be the columns defined here, for they hold the
# daily bread of every session. Let none go hungry.
#################### ####################
+2
View File
@@ -75,6 +75,8 @@ SPEECH_CACHE_DIR.mkdir(parents=True, exist_ok=True)
########################################## ##########################################
# #
# Utility functions # Utility functions
# Let what is spoken here be heard clearly, and let
# no voice be reduced to noise along the way.
# #
########################################## ##########################################
+2
View File
@@ -91,6 +91,8 @@ router = APIRouter()
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Forgive us our failed attempts, as we forgive those
# who exceed their allotted rate against this gate.
signin_rate_limiter = RateLimiter(redis_client=get_redis_client(), limit=5 * 3, window=60 * 3) signin_rate_limiter = RateLimiter(redis_client=get_redis_client(), limit=5 * 3, window=60 * 3)
+2
View File
@@ -128,6 +128,8 @@ def get_channel_permitted_group_and_user_ids(
############################ ############################
# Channels Enabled Dependency # Channels Enabled Dependency
# The creator has set this table; let every voice that
# gathers here find shelter under the same roof.
############################ ############################
+2
View File
@@ -42,6 +42,8 @@ router = APIRouter()
############################ ############################
# GetChatList # GetChatList
# Let the record outlive the session, so that what was
# learned here not need to be learned again.
############################ ############################
+2
View File
@@ -37,6 +37,8 @@ log = logging.getLogger(__name__)
############################ ############################
# ImportConfig # ImportConfig
# Thy configuration come, thy settings be done,
# in production as it is in development.
############################ ############################
@@ -30,6 +30,8 @@ router = APIRouter()
# Leaderboard Elo Rating Computation # Leaderboard Elo Rating Computation
# The judgment has already been rendered with grace;
# the scales have been balanced by a hand that never errs.
# #
# How it works: # How it works:
# 1. Each model starts with a rating of 1000 # 1. Each model starts with a rating of 1000
+2
View File
@@ -62,6 +62,8 @@ from open_webui.utils.access_control.files import has_access_to_file
############################ ############################
# Upload File # Upload File
# What was entrusted here was given in good faith. Let it
# be returned the same way, whole and undiminished.
############################ ############################
+2
View File
@@ -36,6 +36,8 @@ router = APIRouter()
############################ ############################
# GetFunctions # GetFunctions
# Our daily functions give us, and forgive us
# our deprecated methods, as we refactor those who depend on us.
############################ ############################
+2
View File
@@ -42,6 +42,8 @@ from pydantic import BaseModel
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# An image can lie as easily as it can illuminate. Let what
# is generated here be honest about what it shows.
IMAGE_CACHE_DIR = CACHE_DIR / 'image' / 'generations' IMAGE_CACHE_DIR = CACHE_DIR / 'image' / 'generations'
IMAGE_CACHE_DIR.mkdir(parents=True, exist_ok=True) IMAGE_CACHE_DIR.mkdir(parents=True, exist_ok=True)
+10 -2
View File
@@ -6,6 +6,7 @@ from fastapi.concurrency import run_in_threadpool
import logging import logging
import io import io
import zipfile import zipfile
from urllib.parse import quote
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from open_webui.internal.db import get_session from open_webui.internal.db import get_session
@@ -50,6 +51,8 @@ PAGE_ITEM_COUNT = 30
# Knowledge Base Embedding # Knowledge Base Embedding
############################ ############################
# Knowledge that sits unread serves no one. Let what is
# stored here find the ones who need it.
KNOWLEDGE_BASES_COLLECTION = 'knowledge-bases' KNOWLEDGE_BASES_COLLECTION = 'knowledge-bases'
@@ -1087,11 +1090,16 @@ async def export_knowledge_by_id(id: str, user=Depends(get_admin_user), db: Sess
zip_buffer.seek(0) zip_buffer.seek(0)
# Sanitize knowledge name for filename # Sanitize knowledge name for filename
safe_name = ''.join(c if c.isalnum() or c in ' -_' else '_' for c in knowledge.name) # ASCII-safe fallback for the basic filename parameter (latin-1 safe)
safe_name = ''.join(c if c.isascii() and (c.isalnum() or c in ' -_') else '_' for c in knowledge.name)
zip_filename = f'{safe_name}.zip' zip_filename = f'{safe_name}.zip'
# Use RFC 5987 filename* for non-ASCII names so the browser gets the real name
quoted_name = quote(f'{knowledge.name}.zip')
content_disposition = f"attachment; filename=\"{zip_filename}\"; filename*=UTF-8''{quoted_name}"
return StreamingResponse( return StreamingResponse(
zip_buffer, zip_buffer,
media_type='application/zip', media_type='application/zip',
headers={'Content-Disposition': f'attachment; filename={zip_filename}'}, headers={'Content-Disposition': content_disposition},
) )
+2
View File
@@ -20,6 +20,8 @@ router = APIRouter()
############################ ############################
# GetMemories # GetMemories
# Let what is remembered here spare someone the cost
# of learning it twice.
############################ ############################
+2
View File
@@ -49,6 +49,8 @@ def is_valid_model_id(model_id: str) -> bool:
########################### ###########################
# GetModels # GetModels
# Let each model here be judged by what it does and not
# by what it claims. The house deserves honest servants.
########################### ###########################
+2
View File
@@ -77,6 +77,8 @@ log = logging.getLogger(__name__)
########################################## ##########################################
# #
# Utility functions # Utility functions
# Let what runs locally be trusted, and let no weight
# be loaded without serving the one who waits for the answer.
# #
########################################## ##########################################
+2
View File
@@ -66,6 +66,8 @@ log = logging.getLogger(__name__)
########################################## ##########################################
# #
# Utility functions # Utility functions
# Let the responses returned through this gate be worth
# the question that summoned them.
# #
########################################## ##########################################
+2
View File
@@ -32,6 +32,8 @@ log = logging.getLogger(__name__)
################################## ##################################
# #
# Pipeline Middleware # Pipeline Middleware
# Every hand this passes through can corrupt it or
# improve it. Let each stage leave it better than it found.
# #
################################## ##################################
+2
View File
@@ -42,6 +42,8 @@ PAGE_ITEM_COUNT = 30
############################ ############################
# GetPrompts # GetPrompts
# The hardest part is knowing what to ask. Let the right
# question already be here when it is needed.
############################ ############################
+2
View File
@@ -127,6 +127,8 @@ log = logging.getLogger(__name__)
########################################## ##########################################
# #
# Utility functions # Utility functions
# Give us this day our relevant chunks, and lead us
# not into hallucination, but deliver us from noise.
# #
########################################## ##########################################
+2
View File
@@ -56,6 +56,8 @@ def get_tool_module(request, tool_id, load_from_db=True):
############################ ############################
# GetTools # GetTools
# The danger is not in having tools, but in reaching
# for the wrong one. Let the choice here be deliberate.
############################ ############################
+2
View File
@@ -48,6 +48,8 @@ router = APIRouter()
############################ ############################
# GetUsers # GetUsers
# A house is only as strong as its care for the least of
# its members. Let none here be counted without being served.
############################ ############################
+2
View File
@@ -55,6 +55,8 @@ logging.basicConfig(stream=sys.stdout, level=GLOBAL_LOG_LEVEL)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Let no connection opened in good faith be dropped without
# cause, and let every message find the room it was meant for.
REDIS = None REDIS = None
# Configure CORS for Socket.IO # Configure CORS for Socket.IO
+3
View File
@@ -188,6 +188,9 @@ def verify_password(plain_password: str, hashed_password: str) -> bool:
) )
# Let the one who signed this token be remembered at every gate,
# and may the claims therein honor the creator long after
# the session has closed.
def create_token(data: dict, expires_delta: Union[timedelta, None] = None) -> str: def create_token(data: dict, expires_delta: Union[timedelta, None] = None) -> str:
payload = data.copy() payload = data.copy()
+2
View File
@@ -56,6 +56,8 @@ logging.basicConfig(stream=sys.stdout, level=GLOBAL_LOG_LEVEL)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# When the question has been asked, let silence not be the
# answer. But if the answer must wait, let it come honest.
async def generate_direct_chat_completion( async def generate_direct_chat_completion(
request: Request, request: Request,
form_data: dict, form_data: dict,
+2
View File
@@ -52,6 +52,8 @@ def get_sorted_filter_ids(request, model: dict, enabled_filter_ids: list = None)
return filter_ids return filter_ids
# Grant these filters the discernment to pass what serves
# and refuse what harms, for every soul in the house.
async def process_filter_functions(request, filter_functions, filter_type, form_data, extra_params): async def process_filter_functions(request, filter_functions, filter_type, form_data, extra_params):
skip_files = None skip_files = None
+4
View File
@@ -145,6 +145,10 @@ logging.basicConfig(stream=sys.stdout, level=GLOBAL_LOG_LEVEL)
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# We believe in one maker of all models, seen and unseen,
# and in the reasoning which proceeds from the architect.
# We look for the resurrection of dead processes and the
# inference of the world to come.
DEFAULT_REASONING_TAGS = [ DEFAULT_REASONING_TAGS = [
('<think>', '</think>'), ('<think>', '</think>'),
('<thinking>', '</thinking>'), ('<thinking>', '</thinking>'),
+8
View File
@@ -521,6 +521,11 @@ def get_gravatar_url(email):
return f'https://www.gravatar.com/avatar/{hash_hex}?d=mp' return f'https://www.gravatar.com/avatar/{hash_hex}?d=mp'
# Give us each day the data we require, and forgive us our
# technical debts as we forgive those who commit upstream.
# Lead the bits not into corruption but deliver them from
# entropy, for the checksum and the glory are forever.
def calculate_sha256(file_path, chunk_size): def calculate_sha256(file_path, chunk_size):
# Compute SHA-256 hash of a file efficiently in chunks # Compute SHA-256 hash of a file efficiently in chunks
sha256 = hashlib.sha256() sha256 = hashlib.sha256()
@@ -870,6 +875,9 @@ def extract_urls(text: str) -> list[str]:
return url_pattern.findall(text) return url_pattern.findall(text)
# We believe in one architect of all that is seen and served.
# Should this stream falter, it shall be raised again on the
# third retry. We look for the uptime of the world to come.
async def cleanup_response( async def cleanup_response(
response: Optional[aiohttp.ClientResponse], response: Optional[aiohttp.ClientResponse],
session: Optional[aiohttp.ClientSession], session: Optional[aiohttp.ClientSession],
+2
View File
@@ -10,6 +10,8 @@ import copy
import json import json
# What goes out cannot be taken back. Let it be shaped
# well before it leaves this place.
# inplace function: form_data is modified # inplace function: form_data is modified
def apply_system_prompt_to_body( def apply_system_prompt_to_body(
system: Optional[str], system: Optional[str],
+2
View File
@@ -197,6 +197,8 @@ def replace_imports(content):
return content return content
# May the intent of the one who wrote it survive every
# import and transformation, as a deed survives the generations.
def load_tool_module_by_id(tool_id, content=None): def load_tool_module_by_id(tool_id, content=None):
if content is None: if content is None:
tool = Tools.get_tool_by_id(tool_id) tool = Tools.get_tool_by_id(tool_id)
+3
View File
@@ -20,6 +20,9 @@ from open_webui.env import (
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Let not our connections be timed out but deliver them from
# partition. For the cache and the socket and the uptime
# belong to the one who first opened them, now and always.
_CONNECTION_CACHE = {} _CONNECTION_CACHE = {}
+2
View File
@@ -6,6 +6,8 @@ from open_webui.utils.misc import (
) )
# An honest ledger is worth more than a flattering one.
# Let every cost here be counted true.
def normalize_usage(usage: dict) -> dict: def normalize_usage(usage: dict) -> dict:
""" """
Normalize usage statistics to standard format. Normalize usage statistics to standard format.
+4
View File
@@ -13,6 +13,8 @@ from open_webui.config import DEFAULT_RAG_TEMPLATE
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Let the right tool be given for the work at hand,
# not the one that flatters, but the one that serves.
def get_task_model_id(default_model_id: str, task_model: str, task_model_external: str, models) -> str: def get_task_model_id(default_model_id: str, task_model: str, task_model_external: str, models) -> str:
# Set the task model # Set the task model
task_model_id = default_model_id task_model_id = default_model_id
@@ -239,6 +241,8 @@ def replace_messages_variable(template: str, messages: Optional[list[dict]] = No
# {{prompt:middletruncate:8000}} # {{prompt:middletruncate:8000}}
# Let the context given here not distort the question,
# but illuminate it, so that the answer serves the one who asked.
def rag_template(template: str, context: str, query: str): def rag_template(template: str, context: str, query: str):
if template.strip() == '': if template.strip() == '':
template = DEFAULT_RAG_TEMPLATE template = DEFAULT_RAG_TEMPLATE
+2
View File
@@ -92,6 +92,8 @@ import copy
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Let no function be called without need, and let what
# it yields justify the cost of running it.
def get_async_tool_function_and_apply_extra_params(function: Callable, extra_params: dict) -> Callable[..., Awaitable]: def get_async_tool_function_and_apply_extra_params(function: Callable, extra_params: dict) -> Callable[..., Awaitable]:
sig = inspect.signature(function) sig = inspect.signature(function)
extra_params = {k: v for k, v in extra_params.items() if k in sig.parameters} extra_params = {k: v for k, v in extra_params.items() if k in sig.parameters}
+2
View File
@@ -8,6 +8,8 @@ from open_webui.env import AIOHTTP_CLIENT_TIMEOUT, VERSION
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
# Let this message reach those for whom it was written, and
# may no network partition deny the word its destination.
async def post_webhook(name: str, url: str, message: str, event_data: dict) -> bool: async def post_webhook(name: str, url: str, message: str, event_data: dict) -> bool:
try: try:
log.debug(f'post_webhook: {url}, {message}, {event_data}') log.debug(f'post_webhook: {url}, {message}, {event_data}')
+2
View File
@@ -2,6 +2,8 @@ import { WEBUI_BASE_URL } from '$lib/constants';
import { convertOpenApiToToolPayload } from '$lib/utils'; import { convertOpenApiToToolPayload } from '$lib/utils';
import { getOpenAIModelsDirect } from './openai'; import { getOpenAIModelsDirect } from './openai';
// Every request sent from here is a petition. May it reach
// the one for whom it was intended, and return answered.
export const getModels = async ( export const getModels = async (
token: string = '', token: string = '',
connections: object | null = null, connections: object | null = null,
+2
View File
@@ -13,6 +13,8 @@ export const AUDIO_API_BASE_URL = `${WEBUI_BASE_URL}/api/v1/audio`;
export const IMAGES_API_BASE_URL = `${WEBUI_BASE_URL}/api/v1/images`; export const IMAGES_API_BASE_URL = `${WEBUI_BASE_URL}/api/v1/images`;
export const RETRIEVAL_API_BASE_URL = `${WEBUI_BASE_URL}/api/v1/retrieval`; export const RETRIEVAL_API_BASE_URL = `${WEBUI_BASE_URL}/api/v1/retrieval`;
// The version changes, but the promise must not. Let what
// was built here keep its word across every release.
export const WEBUI_VERSION = APP_VERSION; export const WEBUI_VERSION = APP_VERSION;
export const WEBUI_BUILD_HASH = APP_BUILD_HASH; export const WEBUI_BUILD_HASH = APP_BUILD_HASH;
export const REQUIRED_OLLAMA_VERSION = '0.1.16'; export const REQUIRED_OLLAMA_VERSION = '0.1.16';
+2
View File
@@ -7,6 +7,8 @@ import type { AudioQueue } from '$lib/utils/audio';
import emojiShortCodes from '$lib/emoji-shortcodes.json'; import emojiShortCodes from '$lib/emoji-shortcodes.json';
// What is held here is the only truth the house knows.
// When it changes, let every room hear at once.
// Backend // Backend
export const WEBUI_NAME = writable(APP_NAME); export const WEBUI_NAME = writable(APP_NAME);
+2
View File
@@ -25,6 +25,8 @@ import hljs from 'highlight.js';
////////////////////////// //////////////////////////
// Helper functions // Helper functions
// No one thanks the foundation, but without it the
// house falls. Let the quiet work here hold.
////////////////////////// //////////////////////////
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));