flip_api.model_services.services.model_service ============================================== .. py:module:: flip_api.model_services.services.model_service Functions --------- .. autoapisummary:: flip_api.model_services.services.model_service.edit_model flip_api.model_services.services.model_service.update_model_status flip_api.model_services.services.model_service.add_log flip_api.model_services.services.model_service.delete_model flip_api.model_services.services.model_service.delete_models flip_api.model_services.services.model_service.get_model_status flip_api.model_services.services.model_service.validate_trusts flip_api.model_services.services.model_service.get_metrics Module Contents --------------- .. py:function:: edit_model(model_id: uuid.UUID, model_details: flip_api.domain.interfaces.model.IModelDetails, user_id: uuid.UUID, session: sqlmodel.Session) -> None Edit the model details :param model_id: The ID of the model to be edited :type model_id: UUID :param model_details: The new details for the model :type model_details: IModelDetails :param user_id: The ID of the user making the changes :type user_id: UUID :param session: The database session :type session: Session :raises ValueError: If no model exists with the given ``model_id``. .. py:function:: update_model_status(model_id: uuid.UUID, status: flip_api.domain.schemas.status.ModelStatus | None, session: sqlmodel.Session) -> flip_api.domain.schemas.status.ModelStatus | None Update the status of a model :param model_id: The ID of the model :type model_id: UUID :param status: The new status to be set :type status: ModelStatus | None :param session: The database session :type session: Session :returns: The updated status of the model, or None if the model does not exist. :rtype: ModelStatus | None .. py:function:: add_log(model_id: uuid.UUID, log: str, session: sqlmodel.Session, transaction: Any | None = None, success: bool = True) -> None Add a log entry to the database :param model_id: The ID of the model. :type model_id: UUID :param log: The log message to be added. :type log: str :param session: The database session. :type session: Session :param transaction: Optional transaction to control commit behavior. :type transaction: Any | None :param success: Indicates if the log entry is a success or failure. :type success: bool :returns: None :raises Exception: Re-raises any error encountered when persisting the log entry, after rolling back the session. .. py:function:: delete_model(model_id: uuid.UUID, user_id: uuid.UUID, session: sqlmodel.Session) -> None Delete a model by setting its 'deleted' attribute to True. :param model_id: The ID of the model to be deleted. :type model_id: UUID :param user_id: The ID of the user performing the deletion. :type user_id: UUID :param session: The database session. :type session: Session :raises ValueError: If the model with the given ID does not exist. .. py:function:: delete_models(project_id: uuid.UUID, user_id: str, session: sqlmodel.Session, ensure_deletion: bool = True) -> int Delete all models associated with a given project by setting their 'deleted' attribute to True. :param project_id: The ID of the project whose models are to be deleted. :type project_id: UUID :param user_id: The ID of the user performing the deletion. :type user_id: str :param session: The database session. :type session: Session :param ensure_deletion: If True, raises an error if no models are found for deletion. :type ensure_deletion: bool :returns: The number of models deleted. :rtype: int :raises ValueError: If ``ensure_deletion`` is True and no non-deleted models exist for the given project. .. py:function:: get_model_status(model_id: uuid.UUID, session: sqlmodel.Session) -> flip_api.domain.interfaces.model.IDetailedModelStatus | None Get the status of a model. :param model_id: The ID of the model. :type model_id: UUID :param session: The database session. :type session: Session :returns: The model's status and deleted flag, or None if the model does not exist. :rtype: IDetailedModelStatus | None .. py:function:: validate_trusts(model_id: uuid.UUID, trusts: list[str], session: sqlmodel.Session) -> bool Validate whether the trusts are associated with the model. :param model_id: The ID of the model. :type model_id: UUID :param trusts: A list of trust names to validate. :type trusts: list[str] :param session: The database session. :type session: Session :returns: True if all trusts are associated with the model, False otherwise. :rtype: bool .. py:function:: get_metrics(model_id: uuid.UUID, session: sqlmodel.Session) -> list[flip_api.domain.interfaces.model.IModelMetrics] Get the metrics for a given model. :param model_id: The ID of the model. :type model_id: UUID :param session: The database session. :type session: Session :returns: A list of metrics associated with the model. :rtype: list[IModelMetrics]