IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Deploying AI into Production with FastAPI

Visualizza il corso

Istruzioni dell'esercizio

  • 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"

Esercizio pratico interattivo

Passa dalla teoria alla pratica con uno dei nostri esercizi interattivi

Inizia esercizio