Get startedGet started for free

Handle numerical request data

You're building a content moderation system. The system needs to calculate a trust score for each user comment based on numerical features - length, user_reputation, and report_count. You'll create an endpoint that processes these features to make them compatible for the moderation model.

Note that the ML model and CommentMetrics Pydantic model with length(int), user_reputation(int) and report_count(int) are already created and loaded for you.

This exercise is part of the course

Deploying AI into Production with FastAPI

View Course

Exercise instructions

  • In main.py, convert the incoming comment metrics data into a NumPy 2D array and extract length, user_reputation, report_count before passing these to the model.

  • Make the prediction using the pre-loaded model by passing the features array to it.

  • Start the server by running main.py using the command python3 main.py.

  • Open another terminal from the top right corner of the terminal.

    Terminal with arrow pointing to the "new terminal" button on top right.

  • Test the predict_trust endpoint using the curl command:

curl -X POST "http://localhost:8080/predict_trust" \
     -H "Content-Type: application/json" \
     -d '{
           "length": 150,
           "user_reputation": 100,
           "report_count": 0
         }'

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise