flip_api.model_services.services.model_service

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.

validate_trusts(→ bool)

Validate whether the trusts are associated with the model.

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.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

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

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

  • session (Session) – The database session

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) 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.

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.validate_trusts(model_id: uuid.UUID, trusts: list[str], session: sqlmodel.Session) bool

Validate whether the trusts are associated with the model.

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

  • trusts (list[str]) – A list of trust names to validate.

  • session (Session) – The database session.

Returns:

True if all trusts are 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]