Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/SK-916 | Get active model id #645

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions fedn/network/api/v1/model_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ def get_ancestors(id: str):


@bp.route("/<string:id>/download", methods=["GET"])
@jwt_auth_required(role="admin")
def download(id: str):
"""Download
Downloads the model file of the provided id.
Expand Down Expand Up @@ -646,6 +647,7 @@ def download(id: str):


@bp.route("/<string:id>/parameters", methods=["GET"])
@jwt_auth_required(role="admin")
def get_parameters(id: str):
"""Download
Downloads parameters of the model of the provided id.
Expand Down Expand Up @@ -707,3 +709,36 @@ def get_parameters(id: str):
return jsonify({"message": f"Entity with id: {id} not found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500


@bp.route("/active", methods=["GET"])
@jwt_auth_required(role="admin")
def get_active_model():
"""Get active model
Retrieves the active model (id).
---
tags:
- Models
responses:
200:
description: The active model id
schema:
type: string
500:
description: An error occurred
schema:
type: object
properties:
message:
type: string
"""
try:
active_model = model_store.get_active()

response = active_model

return jsonify(response), 200
except EntityNotFound:
return jsonify({"message": "No active model found"}), 404
except Exception:
return jsonify({"message": "An unexpected error occurred"}), 500
11 changes: 11 additions & 0 deletions fedn/network/storage/statestore/stores/model_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,14 @@ def count(self, **kwargs) -> int:
"""
kwargs["key"] = "models"
return super().count(**kwargs)

def get_active(self) -> str:
"""Get the active model
return: The active model id (str)
"""
active_model = self.database[self.collection].find_one({"key": "current_model"})

if active_model is None:
raise EntityNotFound("Active model not found")

return active_model["model"]
Loading