SIENTIAPDE-1241: Refactor: Improve documentation, exception handling, and configuration in model manager. This commit enhances clarity and robustness by adding detailed docstrings to methods, standardizing exception handling with custom types, and simplifying MLflow configuration.

This commit is contained in:
Bruno Domingues
2025-10-22 21:48:12 -03:00
parent 758ffb10b6
commit 94697215aa
8 changed files with 84 additions and 42 deletions

View File

@@ -66,8 +66,8 @@ class ModelServing:
Returns:
pandas.DataFrame: A DataFrame containing run information.
Raise:
SientiaMlException if unable to search runs
Raises:
SientiaMlException: If unable to search runs.
"""
try:
runs = mlflow.search_runs(experiment_names=experiment_names, order_by=order_by)
@@ -82,6 +82,9 @@ class ModelServing:
Args:
experiment_identifier (str): name or id of the experiment to be setted
Raises:
Exception: If setting the experiment fails.
"""
mlflow.set_experiment(experiment_identifier)
@@ -99,6 +102,9 @@ class ModelServing:
Security Warning:
The GitHub token is hardcoded. Consider moving to environment variable
or using a secure secret management solution (e.g., K8s secrets).
Raises:
Exception: If logging the model fails.
"""
mlflow.sklearn.log_model(
sk_model,
@@ -117,6 +123,9 @@ class ModelServing:
Returns:
None
Raises:
Exception: If logging the parameter fails.
"""
mlflow.log_param(key, value)
@@ -130,6 +139,9 @@ class ModelServing:
Returns:
None
Raises:
Exception: If logging the metric fails.
"""
mlflow.log_metric(key, value)
@@ -146,6 +158,9 @@ class ModelServing:
Returns:
None
Raises:
Exception: If logging the artifact fails.
"""
mlflow.log_artifact(local_path=local_path, artifact_path=artifact_path, run_id=run_id)
@@ -178,11 +193,8 @@ class ModelServing:
Yields:
ActiveRun: object that acts as a context manager wrapping the run's state.
Example:
with model_serving.save_experiment(run_name="my_run") as run:
model_serving.log_param("param1", value1)
model_serving.log_metric("metric1", value2)
# Run is automatically closed here, even if an exception occurs
Raises:
Exception: If starting or ending the MLflow run fails.
"""
run = mlflow.start_run(
run_id=run_id,