开始使用免费开始使用

处理数值请求数据

您正在构建一个内容审核系统。系统需要基于数值特征 —— lengthuser_reputationreport_count —— 为每条用户评论计算可信度分数。您将创建一个端点来处理这些特征,使其与审核模型兼容。

请注意,机器学习模型以及包含 length(int)、user_reputation(int) 和 report_count(int) 的 Pydantic 模型 CommentMetrics 已为您创建并加载。

本练习是课程的一部分

使用 FastAPI 在生产环境中部署 AI

查看课程

练习说明

  • main.py 中,将传入的评论 metrics 数据转换为 NumPy 2D 数组,并在传给模型之前提取 lengthuser_reputationreport_count

  • 通过将 features 数组传递给预加载的 model 来进行预测。

  • 通过命令 python3 main.py 运行 main.py 来启动服务器。

  • 从终端右上角打开另一个终端。

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

  • 使用以下 curl 命令测试 predict_trust 端点:

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

动手互动练习

通过我们的互动练习之一,将理论转化为实践

开始练习