From 873fb741c2d00b58a271926419360101a72af6a9 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 31 Aug 2026 00:39:16 -0400 Subject: [PATCH] refac --- backend/open_webui/models/chats.py | 2 +- backend/open_webui/models/prompts.py | 6 +++--- backend/open_webui/retrieval/web/duckduckgo.py | 2 +- backend/open_webui/retrieval/web/mojeek.py | 2 +- backend/open_webui/retrieval/web/serply.py | 2 +- backend/open_webui/retrieval/web/tavily.py | 2 +- backend/open_webui/routers/knowledge.py | 2 +- backend/open_webui/routers/ollama.py | 10 +++++----- backend/open_webui/routers/prompts.py | 2 +- backend/open_webui/routers/retrieval.py | 4 ++-- backend/open_webui/utils/misc.py | 10 +++++----- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index ae31aeda03..fd13a680a8 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -362,7 +362,7 @@ class MessageStats(BaseModel): token_count: int | None = None timestamp: int | None = None rating: int | None = None # Derived from message.annotation.rating - tags: list[str | None] = None # Derived from message.annotation.tags + tags: list[str] | None = None # Derived from message.annotation.tags class ChatHistoryStats(BaseModel): diff --git a/backend/open_webui/models/prompts.py b/backend/open_webui/models/prompts.py index ed6bc35950..e6e07eacc7 100644 --- a/backend/open_webui/models/prompts.py +++ b/backend/open_webui/models/prompts.py @@ -47,7 +47,7 @@ class PromptModel(BaseModel): content: str data: dict | None = None meta: dict | None = None - tags: list[str | None] = None + tags: list[str] | None = None is_active: bool | None = True version_id: str | None = None created_at: int | None = None @@ -86,7 +86,7 @@ class PromptForm(BaseModel): content: str data: dict | None = None meta: dict | None = None - tags: list[str | None] = None + tags: list[str] | None = None access_grants: list[dict] | None = None version_id: str | None = None # Active version commit_message: str | None = None # For history tracking @@ -558,7 +558,7 @@ class PromptsTable: prompt_id: str, name: str, command: str, - tags: list[str | None] = None, + tags: list[str] | None = None, db: AsyncSession | None = None, ) -> PromptModel | None: """Update only name, command, and tags (no history created).""" diff --git a/backend/open_webui/retrieval/web/duckduckgo.py b/backend/open_webui/retrieval/web/duckduckgo.py index 2d57b071cd..afd82eaf04 100644 --- a/backend/open_webui/retrieval/web/duckduckgo.py +++ b/backend/open_webui/retrieval/web/duckduckgo.py @@ -12,7 +12,7 @@ log = logging.getLogger(__name__) def search_duckduckgo( query: str, count: int, - filter_list: list[str | None] = None, + filter_list: list[str] | None = None, concurrent_requests: int | None = None, backend: str | None = 'auto', ) -> list[SearchResult]: diff --git a/backend/open_webui/retrieval/web/mojeek.py b/backend/open_webui/retrieval/web/mojeek.py index da24c2a87c..1f216e7dd8 100644 --- a/backend/open_webui/retrieval/web/mojeek.py +++ b/backend/open_webui/retrieval/web/mojeek.py @@ -8,7 +8,7 @@ from open_webui.retrieval.web.main import SearchResult, get_filtered_results log = logging.getLogger(__name__) -def search_mojeek(api_key: str, query: str, count: int, filter_list: list[str | None] = None) -> list[SearchResult]: +def search_mojeek(api_key: str, query: str, count: int, filter_list: list[str] | None = None) -> list[SearchResult]: """Search using Mojeek's Search API and return the results as a list of SearchResult objects. Args: diff --git a/backend/open_webui/retrieval/web/serply.py b/backend/open_webui/retrieval/web/serply.py index 1daac461df..f22bba6e6f 100644 --- a/backend/open_webui/retrieval/web/serply.py +++ b/backend/open_webui/retrieval/web/serply.py @@ -17,7 +17,7 @@ def search_serply( limit: int = 10, device_type: str = 'desktop', proxy_location: str = 'US', - filter_list: list[str | None] = None, + filter_list: list[str] | None = None, ) -> list[SearchResult]: """Search using serper.dev's API and return the results as a list of SearchResult objects. diff --git a/backend/open_webui/retrieval/web/tavily.py b/backend/open_webui/retrieval/web/tavily.py index 73cf73152e..7bf15a1e62 100644 --- a/backend/open_webui/retrieval/web/tavily.py +++ b/backend/open_webui/retrieval/web/tavily.py @@ -13,7 +13,7 @@ def search_tavily( api_key: str, query: str, count: int, - filter_list: list[str | None] = None, + filter_list: list[str] | None = None, # **kwargs, ) -> list[SearchResult]: """Search using Tavily's Search API and return the results as a list of SearchResult objects. diff --git a/backend/open_webui/routers/knowledge.py b/backend/open_webui/routers/knowledge.py index d2864683e6..3b58c6f805 100644 --- a/backend/open_webui/routers/knowledge.py +++ b/backend/open_webui/routers/knowledge.py @@ -1074,7 +1074,7 @@ async def update_external_knowledge_source( class KnowledgeFilesResponse(KnowledgeResponse): - files: list[FileMetadataResponse | None] = None + files: list[FileMetadataResponse] | None = None write_access: bool | None = False diff --git a/backend/open_webui/routers/ollama.py b/backend/open_webui/routers/ollama.py index 00f41c01b3..2704d81d1b 100644 --- a/backend/open_webui/routers/ollama.py +++ b/backend/open_webui/routers/ollama.py @@ -970,12 +970,12 @@ class GenerateCompletionForm(BaseModel): model: str prompt: str | None = None suffix: str | None = None - images: list[str | None] = None + images: list[str] | None = None format: Union[dict, str | None] = None options: dict | None = None system: str | None = None template: str | None = None - context: list[int | None] = None + context: list[int] | None = None stream: bool | None = True raw: bool | None = None keep_alive: Union[int, str | None] = None @@ -1026,8 +1026,8 @@ class ChatMessage(BaseModel): role: str content: str | None = None - tool_calls: list[dict | None] = None - images: list[str | None] = None + tool_calls: list[dict] | None = None + images: list[str] | None = None model_config = ConfigDict(extra='allow') @validator('content', pre=True) @@ -1048,7 +1048,7 @@ class GenerateChatCompletionForm(BaseModel): template: str | None = None stream: bool | None = True keep_alive: Union[int, str | None] = None - tools: list[dict | None] = None + tools: list[dict] | None = None model_config = ConfigDict(extra='allow') diff --git a/backend/open_webui/routers/prompts.py b/backend/open_webui/routers/prompts.py index 0e3c9c6ee4..9e90a404b0 100644 --- a/backend/open_webui/routers/prompts.py +++ b/backend/open_webui/routers/prompts.py @@ -36,7 +36,7 @@ class PromptVersionUpdateForm(BaseModel): class PromptMetadataForm(BaseModel): name: str command: str - tags: list[str | None] = None + tags: list[str] | None = None router = APIRouter() diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index 517565f12f..e0afd63fd0 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -848,7 +848,7 @@ class WebConfig(BaseModel): EXTERNAL_WEB_SEARCH_API_KEY: str | None = None EXTERNAL_WEB_LOADER_URL: str | None = None EXTERNAL_WEB_LOADER_API_KEY: str | None = None - YOUTUBE_LOADER_LANGUAGE: list[str | None] = None + YOUTUBE_LOADER_LANGUAGE: list[str] | None = None YOUTUBE_LOADER_PROXY_URL: str | None = None YOUTUBE_LOADER_TRANSLATION: str | None = None YANDEX_WEB_SEARCH_URL: str | None = None @@ -938,7 +938,7 @@ class ConfigForm(BaseModel): FILE_MAX_COUNT: Union[int, str | None] = None FILE_IMAGE_COMPRESSION_WIDTH: Union[int, str | None] = None FILE_IMAGE_COMPRESSION_HEIGHT: Union[int, str | None] = None - ALLOWED_FILE_EXTENSIONS: list[str | None] = None + ALLOWED_FILE_EXTENSIONS: list[str] | None = None # Integration settings ENABLE_GOOGLE_DRIVE_INTEGRATION: bool | None = None diff --git a/backend/open_webui/utils/misc.py b/backend/open_webui/utils/misc.py index ea15adf75e..247ab72441 100644 --- a/backend/open_webui/utils/misc.py +++ b/backend/open_webui/utils/misc.py @@ -89,7 +89,7 @@ def get_allow_block_lists(filter_list): return allow_list, block_list -def is_string_allowed(string: Union[str, Sequence[str]], filter_list: list[str | None] = None) -> bool: +def is_string_allowed(string: Union[str, Sequence[str]], filter_list: list[str] | None = None) -> bool: """ Checks if a string is allowed based on the provided filter list. :param string: The string or sequence of strings to check (e.g., domain or hostname). @@ -150,7 +150,7 @@ def _host_matches_pattern(host: str, pattern: str) -> bool: return host == pattern or host.endswith('.' + pattern) -def is_host_allowed(host: Union[str, Sequence[str]], filter_list: list[str | None] = None) -> bool: +def is_host_allowed(host: Union[str, Sequence[str]], filter_list: list[str] | None = None) -> bool: """Allow/block a hostname (or list of hostnames / resolved IPs) against a WEB_FETCH_FILTER_LIST-style filter, matching on label boundaries. @@ -172,7 +172,7 @@ def is_host_allowed(host: Union[str, Sequence[str]], filter_list: list[str | Non return not is_host_blocked(hosts, filter_list) -def is_host_blocked(host: Union[str, Sequence[str]], filter_list: list[str | None] = None) -> bool: +def is_host_blocked(host: Union[str, Sequence[str]], filter_list: list[str] | None = None) -> bool: """Whether a host or resolved address matches a block entry, ignoring any allow entries.""" _, block_list = get_allow_block_lists(filter_list) hosts = [host] if isinstance(host, str) else list(host or []) @@ -778,7 +778,7 @@ def openai_chat_chunk_message_template( model: str, content: str | None = None, reasoning_content: str | None = None, - tool_calls: list[dict | None] = None, + tool_calls: list[dict] | None = None, usage: dict | None = None, message_id: str | None = None, ) -> dict: @@ -809,7 +809,7 @@ def openai_chat_completion_message_template( model: str, message: str | None = None, reasoning_content: str | None = None, - tool_calls: list[dict | None] = None, + tool_calls: list[dict] | None = None, usage: dict | None = None, ) -> dict: template = openai_chat_message_template(model)