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.
This exercise is part of the course
Deploying AI into Production with FastAPI
Exercise instructions
- Create a
GETendpoint using the/healthroute. - Check if the
sentiment_modelis loaded by verifying the model variable against None. - Mark status as
healthyandmodel_loadedasTruein the response when the model is successfully loaded otherwise, mark status asunhealthyandmodel_loadedasFalse. - Open a terminal and start the server by running
main.pyusing the commandpython3 main.py. - Open another terminal from the top right corner of the terminal to test the
healthendpoint using the curl command:curl -X GET "http://localhost:8080/health" -H "accept: application/json"
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
Start Exercise