replace except: with except Exception:

This commit is contained in:
Michael Poluektov 2024-08-14 13:38:19 +01:00
parent 0ec1f9e331
commit 6f72def1ac
16 changed files with 71 additions and 71 deletions

View File

@ -244,7 +244,7 @@ async def speech(request: Request, user=Depends(get_verified_user)):
res = r.json()
if "error" in res:
error_detail = f"External: {res['error']['message']}"
except:
except Exception:
error_detail = f"External: {e}"
raise HTTPException(
@ -299,7 +299,7 @@ async def speech(request: Request, user=Depends(get_verified_user)):
res = r.json()
if "error" in res:
error_detail = f"External: {res['error']['message']}"
except:
except Exception:
error_detail = f"External: {e}"
raise HTTPException(
@ -353,7 +353,7 @@ def transcribe(
try:
model = WhisperModel(**whisper_kwargs)
except:
except Exception:
log.warning(
"WhisperModel initialization failed, attempting download with local_files_only=False"
)
@ -421,7 +421,7 @@ def transcribe(
res = r.json()
if "error" in res:
error_detail = f"External: {res['error']['message']}"
except:
except Exception:
error_detail = f"External: {e}"
raise HTTPException(

View File

@ -157,7 +157,7 @@ def query_collection(
embedding_function=embedding_function,
)
results.append(result)
except:
except Exception:
pass
return merge_and_sort_query_results(results, k=k)
@ -182,7 +182,7 @@ def query_collection_with_hybrid_search(
r=r,
)
results.append(result)
except:
except Exception:
pass
return merge_and_sort_query_results(results, k=k, reverse=True)

View File

@ -140,7 +140,7 @@ class AuthsTable:
return None
else:
return None
except:
except Exception:
return None
def authenticate_user_by_api_key(self, api_key: str) -> Optional[UserModel]:
@ -152,7 +152,7 @@ class AuthsTable:
try:
user = Users.get_user_by_api_key(api_key)
return user if user else None
except:
except Exception:
return False
def authenticate_user_by_trusted_header(self, email: str) -> Optional[UserModel]:
@ -163,7 +163,7 @@ class AuthsTable:
if auth:
user = Users.get_user_by_id(auth.id)
return user
except:
except Exception:
return None
def update_user_password_by_id(self, id: str, new_password: str) -> bool:
@ -174,7 +174,7 @@ class AuthsTable:
)
db.commit()
return True if result == 1 else False
except:
except Exception:
return False
def update_email_by_id(self, id: str, email: str) -> bool:
@ -183,7 +183,7 @@ class AuthsTable:
result = db.query(Auth).filter_by(id=id).update({"email": email})
db.commit()
return True if result == 1 else False
except:
except Exception:
return False
def delete_auth_by_id(self, id: str) -> bool:
@ -200,7 +200,7 @@ class AuthsTable:
return True
else:
return False
except:
except Exception:
return False

View File

@ -164,7 +164,7 @@ class ChatTable:
db.refresh(chat)
return self.get_chat_by_id(chat.share_id)
except:
except Exception:
return None
def delete_shared_chat_by_chat_id(self, chat_id: str) -> bool:
@ -175,7 +175,7 @@ class ChatTable:
db.commit()
return True
except:
except Exception:
return False
def update_chat_share_id_by_id(
@ -189,7 +189,7 @@ class ChatTable:
db.commit()
db.refresh(chat)
return ChatModel.model_validate(chat)
except:
except Exception:
return None
def toggle_chat_archive_by_id(self, id: str) -> Optional[ChatModel]:
@ -201,7 +201,7 @@ class ChatTable:
db.commit()
db.refresh(chat)
return ChatModel.model_validate(chat)
except:
except Exception:
return None
def archive_all_chats_by_user_id(self, user_id: str) -> bool:
@ -210,7 +210,7 @@ class ChatTable:
db.query(Chat).filter_by(user_id=user_id).update({"archived": True})
db.commit()
return True
except:
except Exception:
return False
def get_archived_chat_list_by_user_id(
@ -297,7 +297,7 @@ class ChatTable:
chat = db.get(Chat, id)
return ChatModel.model_validate(chat)
except:
except Exception:
return None
def get_chat_by_share_id(self, id: str) -> Optional[ChatModel]:
@ -319,7 +319,7 @@ class ChatTable:
chat = db.query(Chat).filter_by(id=id, user_id=user_id).first()
return ChatModel.model_validate(chat)
except:
except Exception:
return None
def get_chats(self, skip: int = 0, limit: int = 50) -> List[ChatModel]:
@ -360,7 +360,7 @@ class ChatTable:
db.commit()
return True and self.delete_shared_chat_by_chat_id(id)
except:
except Exception:
return False
def delete_chat_by_id_and_user_id(self, id: str, user_id: str) -> bool:
@ -371,7 +371,7 @@ class ChatTable:
db.commit()
return True and self.delete_shared_chat_by_chat_id(id)
except:
except Exception:
return False
def delete_chats_by_user_id(self, user_id: str) -> bool:
@ -385,7 +385,7 @@ class ChatTable:
db.commit()
return True
except:
except Exception:
return False
def delete_shared_chats_by_user_id(self, user_id: str) -> bool:
@ -400,7 +400,7 @@ class ChatTable:
db.commit()
return True
except:
except Exception:
return False

View File

@ -93,7 +93,7 @@ class DocumentsTable:
return DocumentModel.model_validate(result)
else:
return None
except:
except Exception:
return None
def get_doc_by_name(self, name: str) -> Optional[DocumentModel]:
@ -102,7 +102,7 @@ class DocumentsTable:
document = db.query(Document).filter_by(name=name).first()
return DocumentModel.model_validate(document) if document else None
except:
except Exception:
return None
def get_docs(self) -> List[DocumentModel]:
@ -160,7 +160,7 @@ class DocumentsTable:
db.query(Document).filter_by(name=name).delete()
db.commit()
return True
except:
except Exception:
return False

View File

@ -90,7 +90,7 @@ class FilesTable:
try:
file = db.get(File, id)
return FileModel.model_validate(file)
except:
except Exception:
return None
def get_files(self) -> List[FileModel]:
@ -107,7 +107,7 @@ class FilesTable:
db.commit()
return True
except:
except Exception:
return False
def delete_all_files(self) -> bool:
@ -119,7 +119,7 @@ class FilesTable:
db.commit()
return True
except:
except Exception:
return False

View File

@ -122,7 +122,7 @@ class FunctionsTable:
function = db.get(Function, id)
return FunctionModel.model_validate(function)
except:
except Exception:
return None
def get_functions(self, active_only=False) -> List[FunctionModel]:
@ -198,7 +198,7 @@ class FunctionsTable:
db.commit()
db.refresh(function)
return self.get_function_by_id(id)
except:
except Exception:
return None
def get_user_valves_by_id_and_user_id(
@ -256,7 +256,7 @@ class FunctionsTable:
)
db.commit()
return self.get_function_by_id(id)
except:
except Exception:
return None
def deactivate_all_functions(self) -> Optional[bool]:
@ -271,7 +271,7 @@ class FunctionsTable:
)
db.commit()
return True
except:
except Exception:
return None
def delete_function_by_id(self, id: str) -> bool:
@ -281,7 +281,7 @@ class FunctionsTable:
db.commit()
return True
except:
except Exception:
return False

View File

@ -80,7 +80,7 @@ class MemoriesTable:
)
db.commit()
return self.get_memory_by_id(id)
except:
except Exception:
return None
def get_memories(self) -> List[MemoryModel]:
@ -89,7 +89,7 @@ class MemoriesTable:
try:
memories = db.query(Memory).all()
return [MemoryModel.model_validate(memory) for memory in memories]
except:
except Exception:
return None
def get_memories_by_user_id(self, user_id: str) -> List[MemoryModel]:
@ -98,7 +98,7 @@ class MemoriesTable:
try:
memories = db.query(Memory).filter_by(user_id=user_id).all()
return [MemoryModel.model_validate(memory) for memory in memories]
except:
except Exception:
return None
def get_memory_by_id(self, id: str) -> Optional[MemoryModel]:
@ -107,7 +107,7 @@ class MemoriesTable:
try:
memory = db.get(Memory, id)
return MemoryModel.model_validate(memory)
except:
except Exception:
return None
def delete_memory_by_id(self, id: str) -> bool:
@ -119,7 +119,7 @@ class MemoriesTable:
return True
except:
except Exception:
return False
def delete_memories_by_user_id(self, user_id: str) -> bool:
@ -130,7 +130,7 @@ class MemoriesTable:
db.commit()
return True
except:
except Exception:
return False
def delete_memory_by_id_and_user_id(self, id: str, user_id: str) -> bool:
@ -141,7 +141,7 @@ class MemoriesTable:
db.commit()
return True
except:
except Exception:
return False

View File

@ -146,7 +146,7 @@ class ModelsTable:
with get_db() as db:
model = db.get(Model, id)
return ModelModel.model_validate(model)
except:
except Exception:
return None
def update_model_by_id(self, id: str, model: ModelForm) -> Optional[ModelModel]:
@ -175,7 +175,7 @@ class ModelsTable:
db.commit()
return True
except:
except Exception:
return False

View File

@ -79,7 +79,7 @@ class PromptsTable:
prompt = db.query(Prompt).filter_by(command=command).first()
return PromptModel.model_validate(prompt)
except:
except Exception:
return None
def get_prompts(self) -> List[PromptModel]:
@ -101,7 +101,7 @@ class PromptsTable:
prompt.timestamp = int(time.time())
db.commit()
return PromptModel.model_validate(prompt)
except:
except Exception:
return None
def delete_prompt_by_command(self, command: str) -> bool:
@ -112,7 +112,7 @@ class PromptsTable:
db.commit()
return True
except:
except Exception:
return False

View File

@ -132,7 +132,7 @@ class TagTable:
return ChatIdTagModel.model_validate(result)
else:
return None
except:
except Exception:
return None
def get_tags_by_user_id(self, user_id: str) -> List[TagModel]:

View File

@ -115,7 +115,7 @@ class ToolsTable:
tool = db.get(Tool, id)
return ToolModel.model_validate(tool)
except:
except Exception:
return None
def get_tools(self) -> List[ToolModel]:
@ -141,7 +141,7 @@ class ToolsTable:
)
db.commit()
return self.get_tool_by_id(id)
except:
except Exception:
return None
def get_user_valves_by_id_and_user_id(
@ -196,7 +196,7 @@ class ToolsTable:
tool = db.query(Tool).get(id)
db.refresh(tool)
return ToolModel.model_validate(tool)
except:
except Exception:
return None
def delete_tool_by_id(self, id: str) -> bool:
@ -206,7 +206,7 @@ class ToolsTable:
db.commit()
return True
except:
except Exception:
return False

View File

@ -125,7 +125,7 @@ class UsersTable:
user = db.query(User).filter_by(api_key=api_key).first()
return UserModel.model_validate(user)
except:
except Exception:
return None
def get_user_by_email(self, email: str) -> Optional[UserModel]:
@ -134,7 +134,7 @@ class UsersTable:
user = db.query(User).filter_by(email=email).first()
return UserModel.model_validate(user)
except:
except Exception:
return None
def get_user_by_oauth_sub(self, sub: str) -> Optional[UserModel]:
@ -143,7 +143,7 @@ class UsersTable:
user = db.query(User).filter_by(oauth_sub=sub).first()
return UserModel.model_validate(user)
except:
except Exception:
return None
def get_users(self, skip: int = 0, limit: int = 50) -> List[UserModel]:
@ -164,7 +164,7 @@ class UsersTable:
with get_db() as db:
user = db.query(User).order_by(User.created_at).first()
return UserModel.model_validate(user)
except:
except Exception:
return None
def update_user_role_by_id(self, id: str, role: str) -> Optional[UserModel]:
@ -174,7 +174,7 @@ class UsersTable:
db.commit()
user = db.query(User).filter_by(id=id).first()
return UserModel.model_validate(user)
except:
except Exception:
return None
def update_user_profile_image_url_by_id(
@ -189,7 +189,7 @@ class UsersTable:
user = db.query(User).filter_by(id=id).first()
return UserModel.model_validate(user)
except:
except Exception:
return None
def update_user_last_active_by_id(self, id: str) -> Optional[UserModel]:
@ -203,7 +203,7 @@ class UsersTable:
user = db.query(User).filter_by(id=id).first()
return UserModel.model_validate(user)
except:
except Exception:
return None
def update_user_oauth_sub_by_id(
@ -216,7 +216,7 @@ class UsersTable:
user = db.query(User).filter_by(id=id).first()
return UserModel.model_validate(user)
except:
except Exception:
return None
def update_user_by_id(self, id: str, updated: dict) -> Optional[UserModel]:
@ -245,7 +245,7 @@ class UsersTable:
return True
else:
return False
except:
except Exception:
return False
def update_user_api_key_by_id(self, id: str, api_key: str) -> str:
@ -254,7 +254,7 @@ class UsersTable:
result = db.query(User).filter_by(id=id).update({"api_key": api_key})
db.commit()
return True if result == 1 else False
except:
except Exception:
return False
def get_user_api_key_by_id(self, id: str) -> Optional[str]:

View File

@ -235,7 +235,7 @@ async def delete_function_by_id(
function_path = os.path.join(FUNCTIONS_DIR, f"{id}.py")
try:
os.remove(function_path)
except:
except Exception:
pass
return result

View File

@ -104,7 +104,7 @@ ENV = os.environ.get("ENV", "dev")
try:
PACKAGE_DATA = json.loads((BASE_DIR / "package.json").read_text())
except:
except Exception:
try:
PACKAGE_DATA = {"version": importlib.metadata.version("open-webui")}
except importlib.metadata.PackageNotFoundError:
@ -137,7 +137,7 @@ try:
with open(str(changelog_path.absolute()), "r", encoding="utf8") as file:
changelog_content = file.read()
except:
except Exception:
changelog_content = (pkgutil.get_data("open_webui", "CHANGELOG.md") or b"").decode()
@ -202,12 +202,12 @@ if RESET_CONFIG_ON_START:
os.remove(f"{DATA_DIR}/config.json")
with open(f"{DATA_DIR}/config.json", "w") as f:
f.write("{}")
except:
except Exception:
pass
try:
CONFIG_DATA = json.loads((DATA_DIR / "config.json").read_text())
except:
except Exception:
CONFIG_DATA = {}
@ -647,7 +647,7 @@ if AIOHTTP_CLIENT_TIMEOUT == "":
else:
try:
AIOHTTP_CLIENT_TIMEOUT = int(AIOHTTP_CLIENT_TIMEOUT)
except:
except Exception:
AIOHTTP_CLIENT_TIMEOUT = 300
@ -727,7 +727,7 @@ try:
OPENAI_API_KEY = OPENAI_API_KEYS.value[
OPENAI_API_BASE_URLS.value.index("https://api.openai.com/v1")
]
except:
except Exception:
pass
OPENAI_API_BASE_URL = "https://api.openai.com/v1"
@ -1043,7 +1043,7 @@ RAG_EMBEDDING_MODEL = PersistentConfig(
"rag.embedding_model",
os.environ.get("RAG_EMBEDDING_MODEL", "sentence-transformers/all-MiniLM-L6-v2"),
)
log.info(f"Embedding model set: {RAG_EMBEDDING_MODEL.value}"),
log.info(f"Embedding model set: {RAG_EMBEDDING_MODEL.value}")
RAG_EMBEDDING_MODEL_AUTO_UPDATE = (
os.environ.get("RAG_EMBEDDING_MODEL_AUTO_UPDATE", "").lower() == "true"
@ -1065,7 +1065,7 @@ RAG_RERANKING_MODEL = PersistentConfig(
os.environ.get("RAG_RERANKING_MODEL", ""),
)
if RAG_RERANKING_MODEL.value != "":
log.info(f"Reranking model set: {RAG_RERANKING_MODEL.value}"),
log.info(f"Reranking model set: {RAG_RERANKING_MODEL.value}")
RAG_RERANKING_MODEL_AUTO_UPDATE = (
os.environ.get("RAG_RERANKING_MODEL_AUTO_UPDATE", "").lower() == "true"

View File

@ -1883,7 +1883,7 @@ async def get_pipeline_valves(
res = r.json()
if "detail" in res:
detail = res["detail"]
except:
except Exception:
pass
raise HTTPException(