Aan de slagGa gratis aan de slag

Health-check API for model loading

After loading the model at server startup, you need to develop a testing endpoint to build a monitoring system that can detect if the model is ready to analyze user comments.

In this exercise, you'll create a health check endpoint that allows you to verify your API's status and trigger alerts if the sentiment_model isn't available.

Note: sentiment_model is already pre-loaded for you.

Deze oefening maakt deel uit van de cursus

Deploying AI into Production with FastAPI

Cursus bekijken

Oefeninstructies

  • Create a GET endpoint using the /health route.
  • Check if the sentiment_model is loaded by verifying the model variable against None.
  • Mark status as healthy and model_loaded as True in the response when the model is successfully loaded otherwise, mark status as unhealthy and model_loaded as False.
  • Open a terminal and start the server by running main.py using the command python3 main.py.
  • Open another terminal from the top right corner of the terminal to test the health endpoint using the curl command: curl -X GET "http://localhost:8080/health" -H "accept: application/json"

Praktische interactieve oefening

Zet theorie om in actie met een van onze interactieve oefeningen.

Begin met trainen