From 4cfb99248d52d504416ee3345bd47d1993c36407 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 3 May 2025 23:48:24 +0400 Subject: [PATCH] chore: format --- backend/open_webui/retrieval/web/yacy.py | 6 ++++-- backend/open_webui/routers/audio.py | 18 ++++++++++++------ backend/open_webui/socket/main.py | 24 +++++++++++++----------- backend/open_webui/utils/tools.py | 4 +++- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/backend/open_webui/retrieval/web/yacy.py b/backend/open_webui/retrieval/web/yacy.py index 8d75dfa6e..bc61425cb 100644 --- a/backend/open_webui/retrieval/web/yacy.py +++ b/backend/open_webui/retrieval/web/yacy.py @@ -53,7 +53,7 @@ def search_yacy( # Check if provided a json API URL if not query_url.endswith("yacysearch.json"): # Strip all query parameters from the URL - query_url = query_url.rstrip('/') + "/yacysearch.json" + query_url = query_url.rstrip("/") + "/yacysearch.json" log.debug(f"searching {query_url}") @@ -79,7 +79,9 @@ def search_yacy( sorted_results = get_filtered_results(sorted_results, filter_list) return [ SearchResult( - link=result["link"], title=result.get("title"), snippet=result.get("description") + link=result["link"], + title=result.get("title"), + snippet=result.get("description"), ) for result in sorted_results[:count] ] diff --git a/backend/open_webui/routers/audio.py b/backend/open_webui/routers/audio.py index 6d9a2b604..fba41af4c 100644 --- a/backend/open_webui/routers/audio.py +++ b/backend/open_webui/routers/audio.py @@ -33,7 +33,7 @@ from open_webui.config import ( WHISPER_MODEL_AUTO_UPDATE, WHISPER_MODEL_DIR, CACHE_DIR, - WHISPER_LANGUAGE + WHISPER_LANGUAGE, ) from open_webui.constants import ERROR_MESSAGES @@ -154,6 +154,7 @@ class STTConfigForm(BaseModel): AZURE_BASE_URL: str AZURE_MAX_SPEAKERS: str + class AudioConfigUpdateForm(BaseModel): tts: TTSConfigForm stt: STTConfigForm @@ -184,7 +185,7 @@ async def get_audio_config(request: Request, user=Depends(get_admin_user)): "AZURE_REGION": request.app.state.config.AUDIO_STT_AZURE_REGION, "AZURE_LOCALES": request.app.state.config.AUDIO_STT_AZURE_LOCALES, "AZURE_BASE_URL": request.app.state.config.AUDIO_STT_AZURE_BASE_URL, - "AZURE_MAX_SPEAKERS": request.app.state.config.AUDIO_STT_AZURE_MAX_SPEAKERS, + "AZURE_MAX_SPEAKERS": request.app.state.config.AUDIO_STT_AZURE_MAX_SPEAKERS, }, } @@ -215,7 +216,9 @@ async def update_audio_config( request.app.state.config.AUDIO_STT_AZURE_REGION = form_data.stt.AZURE_REGION request.app.state.config.AUDIO_STT_AZURE_LOCALES = form_data.stt.AZURE_LOCALES request.app.state.config.AUDIO_STT_AZURE_BASE_URL = form_data.stt.AZURE_BASE_URL - request.app.state.config.AUDIO_STT_AZURE_MAX_SPEAKERS = form_data.stt.AZURE_MAX_SPEAKERS + request.app.state.config.AUDIO_STT_AZURE_MAX_SPEAKERS = ( + form_data.stt.AZURE_MAX_SPEAKERS + ) if request.app.state.config.STT_ENGINE == "": request.app.state.faster_whisper_model = set_faster_whisper_model( @@ -245,7 +248,7 @@ async def update_audio_config( "AZURE_REGION": request.app.state.config.AUDIO_STT_AZURE_REGION, "AZURE_LOCALES": request.app.state.config.AUDIO_STT_AZURE_LOCALES, "AZURE_BASE_URL": request.app.state.config.AUDIO_STT_AZURE_BASE_URL, - "AZURE_MAX_SPEAKERS": request.app.state.config.AUDIO_STT_AZURE_MAX_SPEAKERS, + "AZURE_MAX_SPEAKERS": request.app.state.config.AUDIO_STT_AZURE_MAX_SPEAKERS, }, } @@ -509,7 +512,7 @@ def transcribe(request: Request, file_path): file_path, beam_size=5, vad_filter=request.app.state.config.WHISPER_VAD_FILTER, - language=WHISPER_LANGUAGE + language=WHISPER_LANGUAGE, ) log.info( "Detected language '%s' with probability %f" @@ -698,7 +701,10 @@ def transcribe(request: Request, file_path): ) } - url = base_url or f"https://{region}.api.cognitive.microsoft.com/speechtotext/transcriptions:transcribe?api-version=2024-11-15" + url = ( + base_url + or f"https://{region}.api.cognitive.microsoft.com/speechtotext/transcriptions:transcribe?api-version=2024-11-15" + ) # Use context manager to ensure file is properly closed with open(file_path, "rb") as audio_file: diff --git a/backend/open_webui/socket/main.py b/backend/open_webui/socket/main.py index 3d81a4e1e..57ccd6e57 100644 --- a/backend/open_webui/socket/main.py +++ b/backend/open_webui/socket/main.py @@ -193,7 +193,7 @@ async def connect(sid, environ, auth): await sio.emit("user-list", {"user_ids": list(USER_POOL.keys())}) await sio.emit("usage", {"models": get_models_in_use()}) return True - + return False @@ -317,16 +317,18 @@ def get_event_emitter(request_info, update_db=True): ) ) - emit_tasks = [sio.emit( - "chat-events", - { - "chat_id": request_info.get("chat_id", None), - "message_id": request_info.get("message_id", None), - "data": event_data, - }, - to=session_id, - ) - for session_id in session_ids] + emit_tasks = [ + sio.emit( + "chat-events", + { + "chat_id": request_info.get("chat_id", None), + "message_id": request_info.get("message_id", None), + "data": event_data, + }, + to=session_id, + ) + for session_id in session_ids + ] await asyncio.gather(*emit_tasks) diff --git a/backend/open_webui/utils/tools.py b/backend/open_webui/utils/tools.py index 42df84f9e..123ec5fb9 100644 --- a/backend/open_webui/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -291,7 +291,9 @@ def convert_function_to_pydantic_model(func: Callable) -> type[BaseModel]: param_description = function_param_descriptions.get(name, None) if param_description: - field_defs[name] = type_hint, Field(default_value, description=param_description) + field_defs[name] = type_hint, Field( + default_value, description=param_description + ) else: field_defs[name] = type_hint, default_value