Skip to content

Commit

Permalink
get_models added to api
Browse files Browse the repository at this point in the history
  • Loading branch information
niklastheman committed Oct 18, 2023
1 parent edf9f57 commit a064506
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 136 deletions.
19 changes: 18 additions & 1 deletion fedn/fedn/network/api/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def get_all_sessions(self, limit=None, skip=None):
result = {"result": payload, "count": sessions_object["count"]}

return jsonify(result)
return jsonify(payload)

def get_session(self, session_id):
"""Get a session from the statestore.
Expand Down Expand Up @@ -632,6 +631,24 @@ def get_latest_model(self):
{"success": False, "message": "No initial model set."}
)

def get_models(self, session_id=None, limit=None, skip=None):
result = self.statestore.list_models(session_id, limit, skip)

if result is None:
return (
jsonify({"success": False, "message": "No models found."}),
404,
)

json_docs = []
for doc in result["result"]:
json_doc = json.dumps(doc, default=json_util.default)
json_docs.append(json_doc)

json_docs.reverse()

return jsonify({"result": json_docs, "count": result["count"]})

def get_model_trail(self):
"""Get the model trail for a given session.
Expand Down
20 changes: 20 additions & 0 deletions fedn/fedn/network/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ def get_model_trail():
return api.get_model_trail()


@app.route("/list_models", methods=["GET"])
def list_models():
"""Get models from the statestore.
param:
session_id: The session id to get the model trail for.
limit: The maximum number of models to return.
type: limit: int
param: skip: The number of models to skip.
type: skip: int
Returns:
_type_: json
"""

session_id = request.args.get("session_id", None)
limit = request.args.get("limit", None)
skip = request.args.get("skip", None)

return api.get_models(session_id, limit, skip)


@app.route("/delete_model_trail", methods=["GET", "POST"])
def delete_model_trail():
"""Delete the model trail for a given session.
Expand Down
Loading

0 comments on commit a064506

Please sign in to comment.