refac
This commit is contained in:
@@ -58,7 +58,6 @@ from open_webui.events import EVENTS, publish_event
|
||||
from open_webui.models.config import Config
|
||||
from open_webui.utils.access_control import has_permission
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.errors import error_detail
|
||||
from open_webui.utils.headers import include_user_info_headers
|
||||
from open_webui.utils.misc import strict_match_mime_type
|
||||
from open_webui.utils.session_pool import get_session
|
||||
@@ -1056,7 +1055,7 @@ async def transcribe(request: Request, file_path: str, metadata: Optional[dict]
|
||||
log.exception(e)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error processing audio file'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error processing audio file'),
|
||||
)
|
||||
|
||||
results = []
|
||||
|
||||
@@ -22,7 +22,6 @@ from open_webui.models.functions import (
|
||||
FunctionWithValvesModel,
|
||||
)
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.errors import error_detail
|
||||
from open_webui.utils.plugin import (
|
||||
get_functions_cache,
|
||||
get_function_module_from_cache,
|
||||
@@ -133,8 +132,13 @@ async def load_function_from_url(request: Request, form_data: LoadUrlForm, user=
|
||||
'name': function_name,
|
||||
'content': data,
|
||||
}
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=error_detail(e, 'Error fetching function'))
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error fetching function'),
|
||||
)
|
||||
|
||||
|
||||
############################
|
||||
@@ -174,7 +178,7 @@ async def sync_functions(
|
||||
log.exception(f'Failed to load a function: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error loading function'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error loading function'),
|
||||
)
|
||||
|
||||
|
||||
@@ -233,11 +237,13 @@ async def create_new_function(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error creating function'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Failed to create a new function: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error creating function'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error creating function'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -382,10 +388,12 @@ async def update_function_by_id(
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error updating function'),
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating function'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating function'),
|
||||
)
|
||||
|
||||
|
||||
@@ -433,7 +441,7 @@ async def get_function_valves_by_id(
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error getting function valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error getting function valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -509,7 +517,7 @@ async def update_function_valves_by_id(
|
||||
log.exception(f'Error updating function values by id {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating function valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating function valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -541,7 +549,7 @@ async def get_function_user_valves_by_id(
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error getting function user valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error getting function user valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -608,7 +616,7 @@ async def update_function_user_valves_by_id(
|
||||
log.exception(f'Error updating function user valves by id {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating function user valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating function user valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
|
||||
@@ -22,7 +22,6 @@ from open_webui.models.models import Models
|
||||
from open_webui.models.tools import Tools
|
||||
from open_webui.models.users import UserInfoResponse, Users
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.errors import error_detail
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -84,11 +83,13 @@ async def create_new_group(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error creating group'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Error creating a new group: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error creating group'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error creating group'),
|
||||
)
|
||||
|
||||
|
||||
@@ -167,7 +168,7 @@ async def get_users_in_group(id: str, user=Depends(get_admin_user), db: AsyncSes
|
||||
log.exception(f'Error adding users to group {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error getting group members'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error getting group members'),
|
||||
)
|
||||
|
||||
|
||||
@@ -203,11 +204,13 @@ async def update_group_by_id(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error updating group'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Error updating group {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating group'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating group'),
|
||||
)
|
||||
|
||||
|
||||
@@ -246,11 +249,13 @@ async def add_user_to_group(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error adding users to group'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Error adding users to group {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error adding users to group'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error adding users to group'),
|
||||
)
|
||||
|
||||
|
||||
@@ -281,11 +286,13 @@ async def remove_users_from_group(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error removing users from group'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Error removing users from group {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error removing users from group'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error removing users from group'),
|
||||
)
|
||||
|
||||
|
||||
@@ -313,11 +320,13 @@ async def delete_group_by_id(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error deleting group'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Error deleting group {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error deleting group'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error deleting group'),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ from open_webui.retrieval.web.utils import get_ssrf_safe_session, validate_url
|
||||
from open_webui.routers.files import get_file_content_by_id, upload_file_handler
|
||||
from open_webui.utils.access_control import has_permission
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.errors import error_detail
|
||||
from open_webui.utils.headers import include_user_info_headers
|
||||
from open_webui.utils.images.comfyui import (
|
||||
ComfyUICreateImageForm,
|
||||
@@ -170,7 +169,7 @@ async def get_image_model(request):
|
||||
log.exception(f'Failed to get default model from automatic1111: {e}')
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=error_detail(e, 'Failed to connect to the image generation engine'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Failed to connect to the image generation engine'),
|
||||
)
|
||||
|
||||
|
||||
@@ -389,7 +388,10 @@ async def get_models(request: Request, user=Depends(get_verified_user)):
|
||||
)
|
||||
except Exception as e:
|
||||
log.exception(f'Failed to list image generation models: {e}')
|
||||
raise HTTPException(status_code=400, detail=error_detail(e, 'Failed to retrieve image generation models'))
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Failed to retrieve image generation models'),
|
||||
)
|
||||
|
||||
|
||||
class CreateImageForm(BaseModel):
|
||||
@@ -905,8 +907,13 @@ async def image_edits(
|
||||
elif isinstance(form_data.image, list):
|
||||
# Load all images in parallel for better performance
|
||||
form_data.image = list(await asyncio.gather(*[load_url_image(img) for img in form_data.image]))
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=error_detail(e, 'Error loading image'))
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error loading image'),
|
||||
)
|
||||
|
||||
def get_image_file_item(base64_string, param_name='image'):
|
||||
data = base64_string
|
||||
|
||||
@@ -118,7 +118,6 @@ from open_webui.storage.provider import Storage
|
||||
from open_webui.utils.access_control import has_permission
|
||||
from open_webui.utils.access_control.files import has_access_to_file
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.errors import error_detail
|
||||
from open_webui.utils.misc import (
|
||||
calculate_sha256_string,
|
||||
sanitize_text_for_db,
|
||||
@@ -183,7 +182,7 @@ def get_rf(
|
||||
|
||||
except Exception as e:
|
||||
log.error(f'ColBERT: {e}')
|
||||
raise Exception(error_detail(e, 'Error loading reranking model'))
|
||||
raise Exception(ERROR_MESSAGES.DEFAULT(e, 'Error loading reranking model'))
|
||||
else:
|
||||
if engine == 'external':
|
||||
try:
|
||||
@@ -197,7 +196,9 @@ def get_rf(
|
||||
)
|
||||
except Exception as e:
|
||||
log.error(f'ExternalReranking: {e}')
|
||||
raise Exception(error_detail(e, 'Error loading reranking model'))
|
||||
raise Exception(
|
||||
ERROR_MESSAGES.DEFAULT(e, 'Error loading reranking model')
|
||||
)
|
||||
else:
|
||||
import sentence_transformers
|
||||
import torch
|
||||
@@ -217,7 +218,7 @@ def get_rf(
|
||||
)
|
||||
except Exception as e:
|
||||
log.error(f'CrossEncoder: {e}')
|
||||
raise Exception(ERROR_MESSAGES.DEFAULT('CrossEncoder error'))
|
||||
raise Exception(ERROR_MESSAGES.DEFAULT(e, 'CrossEncoder error'))
|
||||
|
||||
# Safely adjust pad_token_id if missing as some models do not have this in config
|
||||
try:
|
||||
@@ -606,7 +607,7 @@ async def update_embedding_config(request: Request, form_data: EmbeddingModelUpd
|
||||
log.exception(f'Problem updating embedding model: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=error_detail(e, 'Error updating embedding configuration'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating embedding configuration'),
|
||||
)
|
||||
|
||||
|
||||
@@ -1208,7 +1209,7 @@ async def update_rag_config(request: Request, form_data: ConfigForm, user=Depend
|
||||
log.exception(f'Problem updating reranking model: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=error_detail(e, 'Error updating reranking configuration'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating reranking configuration'),
|
||||
)
|
||||
|
||||
# Chunking settings
|
||||
@@ -2146,11 +2147,13 @@ async def process_web(
|
||||
'status': True,
|
||||
'content': content,
|
||||
}
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error querying knowledge base'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error querying knowledge base'),
|
||||
)
|
||||
|
||||
|
||||
@@ -2653,11 +2656,13 @@ async def process_web_search(request: Request, form_data: SearchForm, user=Depen
|
||||
'filenames': urls,
|
||||
'loaded_count': len(docs),
|
||||
}
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception('Web search content loading failed')
|
||||
raise HTTPException(
|
||||
status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, ERROR_MESSAGES.WEB_SEARCH_ERROR()),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, ERROR_MESSAGES.WEB_SEARCH_ERROR()),
|
||||
)
|
||||
|
||||
|
||||
@@ -2732,11 +2737,13 @@ async def query_doc_handler(
|
||||
k=form_data.k if form_data.k else config.TOP_K,
|
||||
user=user,
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error querying knowledge base'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error querying knowledge base'),
|
||||
)
|
||||
|
||||
|
||||
@@ -2798,11 +2805,13 @@ async def query_collection_handler(
|
||||
k=form_data.k if form_data.k else config.TOP_K,
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error querying knowledge base'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error querying knowledge base'),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ from open_webui.models.skills import (
|
||||
)
|
||||
from open_webui.utils.access_control import filter_allowed_access_grants, has_permission
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.errors import error_detail
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -210,11 +209,13 @@ async def create_new_skill(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error creating skill'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Failed to create skill: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error creating skill'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error creating skill'),
|
||||
)
|
||||
|
||||
|
||||
@@ -335,10 +336,12 @@ async def update_skill_by_id(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error updating skill'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating skill'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating skill'),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ from open_webui.utils.access_control import (
|
||||
has_permission,
|
||||
)
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.errors import error_detail
|
||||
from open_webui.utils.plugin import (
|
||||
get_tools_cache,
|
||||
get_tool_module_from_cache,
|
||||
@@ -295,8 +294,13 @@ async def load_tool_from_url(request: Request, form_data: LoadUrlForm, user=Depe
|
||||
'name': tool_name,
|
||||
'content': data,
|
||||
}
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=error_detail(e, 'Error fetching tool'))
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error fetching tool'),
|
||||
)
|
||||
|
||||
|
||||
############################
|
||||
@@ -401,11 +405,13 @@ async def create_new_tools(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error creating tools'),
|
||||
)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
log.exception(f'Failed to load the tool by id {form_data.id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error creating tool'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error creating tool'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
@@ -552,10 +558,12 @@ async def update_tools_by_id(
|
||||
detail=ERROR_MESSAGES.DEFAULT('Error updating tools'),
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating tool'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating tool'),
|
||||
)
|
||||
|
||||
|
||||
@@ -708,7 +716,7 @@ async def get_tools_valves_by_id(
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error getting tool valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error getting tool valves'),
|
||||
)
|
||||
|
||||
|
||||
@@ -819,7 +827,7 @@ async def update_tools_valves_by_id(
|
||||
log.exception(f'Failed to update tool valves by id {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating tool valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating tool valves'),
|
||||
)
|
||||
|
||||
|
||||
@@ -861,7 +869,7 @@ async def get_tools_user_valves_by_id(
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error getting tool user valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error getting tool user valves'),
|
||||
)
|
||||
|
||||
|
||||
@@ -959,7 +967,7 @@ async def update_tools_user_valves_by_id(
|
||||
log.exception(f'Failed to update user valves by id {id}: {e}')
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=error_detail(e, 'Error updating tool user valves'),
|
||||
detail=ERROR_MESSAGES.DEFAULT(e, 'Error updating tool user valves'),
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
|
||||
Reference in New Issue
Block a user