flip_api.model_services.services.model_service

Attributes

_STATUS_AUDIT_MAP

Functions

edit_model(→ None)

Edit the model details

update_model_status(...)

Update the status of a model.

add_log(→ None)

Add a log entry to the database

delete_model(→ None)

Delete a model by setting its 'deleted' attribute to True.

delete_models(→ int)

Delete all models associated with a given project by setting their 'deleted' attribute to True.

get_model_status(...)

Get the status of a model.

resolve_trust_from_fl_client_name(...)

Resolve an FL client name (its FL kit slot) to its Trust.

validate_trust_ids(→ bool)

Validate that every trust id is associated with the model via ModelTrustIntersect.

get_metrics(...)

Get the metrics for a given model.

Module Contents

flip_api.model_services.services.model_service.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

Parameters:
  • model_id (UUID) – The ID of the model to be edited

  • model_details (IModelDetails) – The new details for the model

  • user_id (UUID) – The ID of the user making the changes

  • session (Session) – The database session

Raises:

ValueError – If no model exists with the given model_id.

flip_api.model_services.services.model_service._STATUS_AUDIT_MAP: dict[flip_api.domain.schemas.status.ModelStatus, flip_api.domain.schemas.actions.ModelAuditAction]
flip_api.model_services.services.model_service.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.

Parameters:
  • model_id (UUID) – The ID of the model.

  • status (ModelStatus | None) – The new status to be set.

  • session (Session) – The database session.

  • user_id (UUID | None) – Optional user who triggered the change; recorded on the audit row when present. Background transitions pass None.

Returns:

The updated status of the model, or None if the model does not exist.

Return type:

ModelStatus | None

flip_api.model_services.services.model_service.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

Parameters:
  • model_id (UUID) – The ID of the model.

  • log (str) – The log message to be added.

  • session (Session) – The database session.

  • transaction (Any | None) – Optional transaction to control commit behavior.

  • success (bool) – Indicates if the log entry is a success or failure.

  • trust (Trust | None) – The trust the log is attributed to, when the log was reported by an FL client. None for model-level (hub) logs.

  • fl_client_name (str | None) – The FL client name as reported by the FL server. None for model-level logs.

Returns:

None

Raises:

Exception – Re-raises any error encountered when persisting the log entry, after rolling back the session.

flip_api.model_services.services.model_service.delete_model(model_id: uuid.UUID, user_id: uuid.UUID, session: sqlmodel.Session) None

Delete a model by setting its ‘deleted’ attribute to True.

Parameters:
  • model_id (UUID) – The ID of the model to be deleted.

  • user_id (UUID) – The ID of the user performing the deletion.

  • session (Session) – The database session.

Raises:

ValueError – If the model with the given ID does not exist.

flip_api.model_services.services.model_service.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.

Parameters:
  • project_id (UUID) – The ID of the project whose models are to be deleted.

  • user_id (str) – The ID of the user performing the deletion.

  • session (Session) – The database session.

  • ensure_deletion (bool) – If True, raises an error if no models are found for deletion.

Returns:

The number of models deleted.

Return type:

int

Raises:

ValueError – If ensure_deletion is True and no non-deleted models exist for the given project.

flip_api.model_services.services.model_service.get_model_status(model_id: uuid.UUID, session: sqlmodel.Session) flip_api.domain.interfaces.model.IDetailedModelStatus | None

Get the status of a model.

Parameters:
  • model_id (UUID) – The ID of the model.

  • session (Session) – The database session.

Returns:

The model’s status and deleted flag, or None if the model does not exist.

Return type:

IDetailedModelStatus | None

flip_api.model_services.services.model_service.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.

Parameters:
  • fl_client_name (str) – The FL kit slot name reported by the FL server.

  • session (Session) – The database session.

Returns:

The resolved trust, or None when the slot name matches no

assigned slot (an unknown / unassigned FL kit slot).

Return type:

Trust | None

flip_api.model_services.services.model_service.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.

Parameters:
  • model_id (UUID) – The ID of the model.

  • trust_ids (list[UUID]) – Trust ids to validate.

  • session (Session) – The database session.

Returns:

True if every id is associated with the model, False otherwise.

Return type:

bool

flip_api.model_services.services.model_service.get_metrics(model_id: uuid.UUID, session: sqlmodel.Session) list[flip_api.domain.interfaces.model.IModelMetrics]

Get the metrics for a given model.

Parameters:
  • model_id (UUID) – The ID of the model.

  • session (Session) – The database session.

Returns:

A list of metrics associated with the model.

Return type:

list[IModelMetrics]