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
Exercise instructions
In
main.py
, convert the incoming commentmetrics
data into aNumPy
2D array and extractlength
,user_reputation
,report_count
before passing these to the model.Make the prediction using the pre-loaded
model
by passing thefeatures
array to it.Start the server by running
main.py
using the commandpython3 main.py
.Open another terminal from the top right corner of the terminal.
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
