| 
									
										
										
										
											2024-05-19 22:11:28 +08:00
										 |  |  | import logging | 
					
						
							| 
									
										
										
										
											2024-08-28 06:10:27 +08:00
										 |  |  | import time | 
					
						
							|  |  |  | from typing import Optional | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-10 16:54:13 +08:00
										 |  |  | from open_webui.internal.db import Base, JSONField, get_db | 
					
						
							| 
									
										
										
										
											2024-09-04 22:54:48 +08:00
										 |  |  | from open_webui.env import SRC_LOG_LEVELS | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-10 16:54:13 +08:00
										 |  |  | from open_webui.models.users import Users, UserResponse | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-28 06:10:27 +08:00
										 |  |  | from pydantic import BaseModel, ConfigDict | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | from sqlalchemy import or_, and_, func | 
					
						
							|  |  |  | from sqlalchemy.dialects import postgresql, sqlite | 
					
						
							| 
									
										
										
										
											2024-11-16 10:21:41 +08:00
										 |  |  | from sqlalchemy import BigInteger, Column, Text, JSON, Boolean | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-17 08:51:55 +08:00
										 |  |  | from open_webui.utils.access_control import has_access | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-19 22:11:28 +08:00
										 |  |  | log = logging.getLogger(__name__) | 
					
						
							|  |  |  | log.setLevel(SRC_LOG_LEVELS["MODELS"]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #################### | 
					
						
							|  |  |  | # Models DB Schema | 
					
						
							|  |  |  | #################### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # ModelParams is a model for the data stored in the params field of the Model table | 
					
						
							|  |  |  | class ModelParams(BaseModel): | 
					
						
							| 
									
										
										
										
											2024-05-24 14:47:01 +08:00
										 |  |  |     model_config = ConfigDict(extra="allow") | 
					
						
							| 
									
										
										
										
											2024-05-22 05:05:16 +08:00
										 |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # ModelMeta is a model for the data stored in the meta field of the Model table | 
					
						
							|  |  |  | class ModelMeta(BaseModel): | 
					
						
							| 
									
										
										
										
											2024-07-09 14:07:23 +08:00
										 |  |  |     profile_image_url: Optional[str] = "/static/favicon.png" | 
					
						
							| 
									
										
										
										
											2024-05-25 09:26:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-24 14:47:01 +08:00
										 |  |  |     description: Optional[str] = None | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-05-19 22:11:28 +08:00
										 |  |  |         User-facing description of the model. | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-25 14:34:58 +08:00
										 |  |  |     capabilities: Optional[dict] = None | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-24 14:47:01 +08:00
										 |  |  |     model_config = ConfigDict(extra="allow") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-18 21:03:31 +08:00
										 |  |  | class Model(Base): | 
					
						
							|  |  |  |     __tablename__ = "model" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-24 19:21:51 +08:00
										 |  |  |     id = Column(Text, primary_key=True) | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							|  |  |  |         The model's id as used in the API. If set to an existing model, it will override the model. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-06-24 19:21:51 +08:00
										 |  |  |     user_id = Column(Text) | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-24 19:21:51 +08:00
										 |  |  |     base_model_id = Column(Text, nullable=True) | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-05-22 05:05:16 +08:00
										 |  |  |         An optional pointer to the actual model that should be used when proxying requests. | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-24 19:21:51 +08:00
										 |  |  |     name = Column(Text) | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-05-22 05:05:16 +08:00
										 |  |  |         The human-readable display name of the model. | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-18 21:03:31 +08:00
										 |  |  |     params = Column(JSONField) | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-05-22 05:05:16 +08:00
										 |  |  |         Holds a JSON encoded blob of parameters, see `ModelParams`. | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-18 21:03:31 +08:00
										 |  |  |     meta = Column(JSONField) | 
					
						
							| 
									
										
										
										
											2024-05-24 13:58:26 +08:00
										 |  |  |     """
 | 
					
						
							|  |  |  |         Holds a JSON encoded blob of metadata, see `ModelMeta`. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 10:57:25 +08:00
										 |  |  |     access_control = Column(JSON, nullable=True)  # Controls data access levels. | 
					
						
							| 
									
										
										
										
											2024-11-15 12:13:43 +08:00
										 |  |  |     # Defines access control rules for this entry. | 
					
						
							|  |  |  |     # - `None`: Public access, available to all users with the "user" role. | 
					
						
							|  |  |  |     # - `{}`: Private access, restricted exclusively to the owner. | 
					
						
							|  |  |  |     # - Custom permissions: Specific access control for reading and writing; | 
					
						
							|  |  |  |     #   Can specify group or user-level restrictions: | 
					
						
							|  |  |  |     #   { | 
					
						
							|  |  |  |     #      "read": { | 
					
						
							|  |  |  |     #          "group_ids": ["group_id1", "group_id2"], | 
					
						
							|  |  |  |     #          "user_ids":  ["user_id1", "user_id2"] | 
					
						
							|  |  |  |     #      }, | 
					
						
							|  |  |  |     #      "write": { | 
					
						
							|  |  |  |     #          "group_ids": ["group_id1", "group_id2"], | 
					
						
							|  |  |  |     #          "user_ids":  ["user_id1", "user_id2"] | 
					
						
							|  |  |  |     #      } | 
					
						
							|  |  |  |     #   } | 
					
						
							| 
									
										
										
										
											2024-11-15 10:57:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-16 10:21:41 +08:00
										 |  |  |     is_active = Column(Boolean, default=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-18 21:03:31 +08:00
										 |  |  |     updated_at = Column(BigInteger) | 
					
						
							|  |  |  |     created_at = Column(BigInteger) | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ModelModel(BaseModel): | 
					
						
							|  |  |  |     id: str | 
					
						
							| 
									
										
										
										
											2024-05-25 09:26:36 +08:00
										 |  |  |     user_id: str | 
					
						
							| 
									
										
										
										
											2024-05-22 05:05:16 +08:00
										 |  |  |     base_model_id: Optional[str] = None | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |     name: str | 
					
						
							| 
									
										
										
										
											2024-05-22 05:05:16 +08:00
										 |  |  |     params: ModelParams | 
					
						
							| 
									
										
										
										
											2024-05-24 13:58:26 +08:00
										 |  |  |     meta: ModelMeta | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 12:13:43 +08:00
										 |  |  |     access_control: Optional[dict] = None | 
					
						
							| 
									
										
										
										
											2024-11-15 10:57:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-16 10:21:41 +08:00
										 |  |  |     is_active: bool | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  |     updated_at: int  # timestamp in epoch | 
					
						
							|  |  |  |     created_at: int  # timestamp in epoch | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-21 20:58:57 +08:00
										 |  |  |     model_config = ConfigDict(from_attributes=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #################### | 
					
						
							|  |  |  | # Forms | 
					
						
							|  |  |  | #################### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-18 21:37:04 +08:00
										 |  |  | class ModelUserResponse(ModelModel): | 
					
						
							|  |  |  |     user: Optional[UserResponse] = None | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-16 10:21:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-18 21:37:04 +08:00
										 |  |  | class ModelResponse(ModelModel): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ModelForm(BaseModel): | 
					
						
							|  |  |  |     id: str | 
					
						
							|  |  |  |     base_model_id: Optional[str] = None | 
					
						
							|  |  |  |     name: str | 
					
						
							|  |  |  |     meta: ModelMeta | 
					
						
							|  |  |  |     params: ModelParams | 
					
						
							| 
									
										
										
										
											2024-11-16 10:21:41 +08:00
										 |  |  |     access_control: Optional[dict] = None | 
					
						
							|  |  |  |     is_active: bool = True | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | class ModelsTable: | 
					
						
							| 
									
										
										
										
											2024-05-25 09:26:36 +08:00
										 |  |  |     def insert_new_model( | 
					
						
							| 
									
										
										
										
											2024-06-21 20:58:57 +08:00
										 |  |  |         self, form_data: ModelForm, user_id: str | 
					
						
							| 
									
										
										
										
											2024-05-25 09:26:36 +08:00
										 |  |  |     ) -> Optional[ModelModel]: | 
					
						
							|  |  |  |         model = ModelModel( | 
					
						
							|  |  |  |             **{ | 
					
						
							|  |  |  |                 **form_data.model_dump(), | 
					
						
							|  |  |  |                 "user_id": user_id, | 
					
						
							|  |  |  |                 "created_at": int(time.time()), | 
					
						
							|  |  |  |                 "updated_at": int(time.time()), | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  |         try: | 
					
						
							| 
									
										
										
										
											2024-07-04 14:32:39 +08:00
										 |  |  |             with get_db() as db: | 
					
						
							|  |  |  |                 result = Model(**model.model_dump()) | 
					
						
							|  |  |  |                 db.add(result) | 
					
						
							|  |  |  |                 db.commit() | 
					
						
							|  |  |  |                 db.refresh(result) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if result: | 
					
						
							|  |  |  |                     return ModelModel.model_validate(result) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     return None | 
					
						
							| 
									
										
										
										
											2024-05-25 09:26:36 +08:00
										 |  |  |         except Exception as e: | 
					
						
							| 
									
										
										
										
											2025-02-25 22:36:25 +08:00
										 |  |  |             log.exception(f"Failed to insert a new model: {e}") | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  |             return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-14 20:46:31 +08:00
										 |  |  |     def get_all_models(self) -> list[ModelModel]: | 
					
						
							| 
									
										
										
										
											2024-07-04 14:32:39 +08:00
										 |  |  |         with get_db() as db: | 
					
						
							|  |  |  |             return [ModelModel.model_validate(model) for model in db.query(Model).all()] | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-18 21:37:04 +08:00
										 |  |  |     def get_models(self) -> list[ModelUserResponse]: | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  |         with get_db() as db: | 
					
						
							| 
									
										
										
										
											2024-11-20 08:47:35 +08:00
										 |  |  |             models = [] | 
					
						
							|  |  |  |             for model in db.query(Model).filter(Model.base_model_id != None).all(): | 
					
						
							|  |  |  |                 user = Users.get_user_by_id(model.user_id) | 
					
						
							|  |  |  |                 models.append( | 
					
						
							|  |  |  |                     ModelUserResponse.model_validate( | 
					
						
							|  |  |  |                         { | 
					
						
							|  |  |  |                             **ModelModel.model_validate(model).model_dump(), | 
					
						
							|  |  |  |                             "user": user.model_dump() if user else None, | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2024-11-18 21:37:04 +08:00
										 |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2024-11-20 08:47:35 +08:00
										 |  |  |             return models | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-16 10:53:50 +08:00
										 |  |  |     def get_base_models(self) -> list[ModelModel]: | 
					
						
							|  |  |  |         with get_db() as db: | 
					
						
							|  |  |  |             return [ | 
					
						
							|  |  |  |                 ModelModel.model_validate(model) | 
					
						
							|  |  |  |                 for model in db.query(Model).filter(Model.base_model_id == None).all() | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  |     def get_models_by_user_id( | 
					
						
							|  |  |  |         self, user_id: str, permission: str = "write" | 
					
						
							| 
									
										
										
										
											2024-11-18 21:37:04 +08:00
										 |  |  |     ) -> list[ModelUserResponse]: | 
					
						
							|  |  |  |         models = self.get_models() | 
					
						
							| 
									
										
										
										
											2024-11-15 17:29:07 +08:00
										 |  |  |         return [ | 
					
						
							|  |  |  |             model | 
					
						
							|  |  |  |             for model in models | 
					
						
							|  |  |  |             if model.user_id == user_id | 
					
						
							|  |  |  |             or has_access(user_id, permission, model.access_control) | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-21 20:58:57 +08:00
										 |  |  |     def get_model_by_id(self, id: str) -> Optional[ModelModel]: | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |         try: | 
					
						
							| 
									
										
										
										
											2024-07-04 14:32:39 +08:00
										 |  |  |             with get_db() as db: | 
					
						
							|  |  |  |                 model = db.get(Model, id) | 
					
						
							|  |  |  |                 return ModelModel.model_validate(model) | 
					
						
							| 
									
										
										
										
											2024-08-14 20:38:19 +08:00
										 |  |  |         except Exception: | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  |             return None | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-16 10:21:41 +08:00
										 |  |  |     def toggle_model_by_id(self, id: str) -> Optional[ModelModel]: | 
					
						
							|  |  |  |         with get_db() as db: | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 is_active = db.query(Model).filter_by(id=id).first().is_active | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 db.query(Model).filter_by(id=id).update( | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         "is_active": not is_active, | 
					
						
							|  |  |  |                         "updated_at": int(time.time()), | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |                 db.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return self.get_model_by_id(id) | 
					
						
							|  |  |  |             except Exception: | 
					
						
							|  |  |  |                 return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-24 15:57:08 +08:00
										 |  |  |     def update_model_by_id(self, id: str, model: ModelForm) -> Optional[ModelModel]: | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  |         try: | 
					
						
							| 
									
										
										
										
											2024-07-04 14:32:39 +08:00
										 |  |  |             with get_db() as db: | 
					
						
							|  |  |  |                 # update only the fields that are present in the model | 
					
						
							| 
									
										
										
										
											2024-07-09 02:58:36 +08:00
										 |  |  |                 result = ( | 
					
						
							|  |  |  |                     db.query(Model) | 
					
						
							|  |  |  |                     .filter_by(id=id) | 
					
						
							| 
									
										
										
										
											2024-11-16 14:04:33 +08:00
										 |  |  |                     .update(model.model_dump(exclude={"id"})) | 
					
						
							| 
									
										
										
										
											2024-07-09 02:58:36 +08:00
										 |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2024-07-04 14:32:39 +08:00
										 |  |  |                 db.commit() | 
					
						
							| 
									
										
										
										
											2024-07-09 02:58:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 model = db.get(Model, id) | 
					
						
							| 
									
										
										
										
											2024-07-04 14:32:39 +08:00
										 |  |  |                 db.refresh(model) | 
					
						
							|  |  |  |                 return ModelModel.model_validate(model) | 
					
						
							| 
									
										
										
										
											2024-05-25 13:21:57 +08:00
										 |  |  |         except Exception as e: | 
					
						
							| 
									
										
										
										
											2025-02-25 22:36:25 +08:00
										 |  |  |             log.exception(f"Failed to update the model by id {id}: {e}") | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  |             return None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-21 20:58:57 +08:00
										 |  |  |     def delete_model_by_id(self, id: str) -> bool: | 
					
						
							| 
									
										
										
										
											2024-05-24 15:26:00 +08:00
										 |  |  |         try: | 
					
						
							| 
									
										
										
										
											2024-07-04 14:32:39 +08:00
										 |  |  |             with get_db() as db: | 
					
						
							|  |  |  |                 db.query(Model).filter_by(id=id).delete() | 
					
						
							| 
									
										
										
										
											2024-07-06 23:10:58 +08:00
										 |  |  |                 db.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-04 14:32:39 +08:00
										 |  |  |                 return True | 
					
						
							| 
									
										
										
										
											2024-08-14 20:38:19 +08:00
										 |  |  |         except Exception: | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  |             return False | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-20 03:03:36 +08:00
										 |  |  |     def delete_all_models(self) -> bool: | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             with get_db() as db: | 
					
						
							|  |  |  |                 db.query(Model).delete() | 
					
						
							|  |  |  |                 db.commit() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return True | 
					
						
							|  |  |  |         except Exception: | 
					
						
							|  |  |  |             return False | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-19 18:46:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-18 21:03:31 +08:00
										 |  |  | Models = ModelsTable() |