flip_api.model_services.services.model_service ============================================== .. py:module:: flip_api.model_services.services.model_service Attributes ---------- .. autoapisummary:: flip_api.model_services.services.model_service._STATUS_AUDIT_MAP 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.resolve_trust_from_fl_client_name flip_api.model_services.services.model_service.validate_trust_ids 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:data:: _STATUS_AUDIT_MAP :type: dict[flip_api.domain.schemas.status.ModelStatus, flip_api.domain.schemas.actions.ModelAuditAction] .. py:function:: update_model_status(model_id: uuid.UUID, status: flip_api.domain.schemas.status.ModelStatus | None, session: sqlmodel.Session, user_id: uuid.UUID | None = None) -> 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 :param user_id: Optional user who triggered the change; recorded on the audit row when present. Background transitions pass None. :type user_id: UUID | None :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, trust: flip_api.db.models.main_models.Trust | None = None, fl_client_name: str | None = None) -> 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 :param trust: The trust the log is attributed to, when the log was reported by an FL client. None for model-level (hub) logs. :type trust: Trust | None :param fl_client_name: The FL client name as reported by the FL server. None for model-level logs. :type fl_client_name: str | None :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:: resolve_trust_from_fl_client_name(fl_client_name: str, session: sqlmodel.Session) -> flip_api.db.models.main_models.Trust | None Resolve an FL client name (its FL kit slot) to its Trust. Both backends report the FL kit slot as the client name, so resolution is uniform — the slot is mapped to its assigned trust via the FLKitSlot table, independent of the operator-chosen trust display name (closes the #538 drift from Flower's previous free-form name lookup): - NVFLARE: the slot is the certificate CN baked in at provisioning time (e.g. ``Trust_2``). - Flower: the slot is the ``SUPERNODE_NAME`` env var, set to ``FL_KIT_SLOT`` in the trust compose so the FL identity is the slot, not the trust name. :param fl_client_name: The FL kit slot name reported by the FL server. :type fl_client_name: str :param session: The database session. :type session: Session :returns: The resolved trust, or None when the slot name matches no assigned slot (an unknown / unassigned FL kit slot). :rtype: Trust | None .. py:function:: validate_trust_ids(model_id: uuid.UUID, trust_ids: list[uuid.UUID], session: sqlmodel.Session) -> bool Validate that every trust id is associated with the model via ModelTrustIntersect. :param model_id: The ID of the model. :type model_id: UUID :param trust_ids: Trust ids to validate. :type trust_ids: list[UUID] :param session: The database session. :type session: Session :returns: True if every id is 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]