diff --git a/backend/open_webui/models/models.py b/backend/open_webui/models/models.py index 9d2b5819bc..7cab2c830e 100755 --- a/backend/open_webui/models/models.py +++ b/backend/open_webui/models/models.py @@ -414,6 +414,7 @@ class ModelsTable: with get_db_context(db) as db: # update only the fields that are present in the model data = model.model_dump(exclude={'id', 'access_grants'}) + data['updated_at'] = int(time.time()) result = db.query(Model).filter_by(id=id).update(data) db.commit() @@ -425,6 +426,20 @@ class ModelsTable: log.exception(f'Failed to update the model by id {id}: {e}') return None + def update_model_updated_at_by_id(self, id: str, db: Optional[Session] = None) -> Optional[ModelModel]: + try: + with get_db_context(db) as db: + result = db.query(Model).filter_by(id=id).first() + if not result: + return None + result.updated_at = int(time.time()) + db.commit() + db.refresh(result) + return self._to_model_model(result, db=db) + except Exception as e: + log.exception(f'Failed to update the model updated_at by id {id}: {e}') + return None + def delete_model_by_id(self, id: str, db: Optional[Session] = None) -> bool: try: with get_db_context(db) as db: diff --git a/backend/open_webui/routers/models.py b/backend/open_webui/routers/models.py index 76ed48d970..6f7b3d48df 100644 --- a/backend/open_webui/routers/models.py +++ b/backend/open_webui/routers/models.py @@ -578,6 +578,8 @@ async def update_model_access_by_id( AccessGrants.set_access_grants('model', form_data.id, form_data.access_grants, db=db) + Models.update_model_updated_at_by_id(form_data.id, db=db) + return Models.get_model_by_id(form_data.id, db=db)