Sonam

审核是那些“只需询问 LLM”听起来诱人,但并非总是最佳工作流的产品功能之一。

有些内容显而易见。已知的垃圾信息、重复的滥用模式和常见诈骗文本应被快速且一致地捕获。

其他内容则需要判断。它可能是上下文相关的、模糊的、讽刺的或边缘的。

我整理了一个 Python Flask 示例,使用 Telnyx AI Inference 来处理这两种路径:

https://github.com/team-telnyx/telnyx-code-examples/tree/main/moderation-classifier-python

该应用使用两阶段流程:

  1. 使用 embeddings 预过滤已知的坏内容黑名单。
  2. 当没有强黑名单匹配时,进行 LLM 审核判断。

流程

在审核内容之前,请构建黑名单索引:

curl -X POST http://localhost:5000/blocklist/index

Enter fullscreen mode Exit fullscreen mode

它通过以下方式嵌入捆绑的 sample_blocklist.json 条目:

POST /v2/ai/openai/embeddings

Enter fullscreen mode Exit fullscreen mode

然后您可以对单个内容进行分类:

curl -X POST http://localhost:5000/moderate \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Great product, really enjoyed using it.",
    "source": "review",
    "author_id": "user-123"
  }'

Enter fullscreen mode Exit fullscreen mode

该应用返回结构化字段:

{
  "category": "safe",
  "confidence": 1.0,
  "flags": [],
  "blocklist_match": false,
  "recommended_action": "allow",
  "reason": "Benign positive product review with no policy violations."
}

Enter fullscreen mode Exit fullscreen mode

如果内容与黑名单匹配度足够高,应用会跳过 LLM 并直接返回匹配的类别。

对于其他内容,它会调用:

POST /v2/ai/chat/completions

Enter fullscreen mode Exit fullscreen mode

默认模型为:

AI_MODEL=moonshotai/Kimi-K2.6
EMBEDDING_MODEL=thenlper/gte-large

Enter fullscreen mode Exit fullscreen mode

包含的端点

该示例包括:

  • POST /blocklist/index
  • POST /moderate
  • POST /moderate/batch
  • POST /blocklist
  • GET /blocklist
  • GET /moderations
  • GET /moderations/<id>
  • GET /stats
  • GET /health

批量审核最多支持 20 个项目:

curl -X POST http://localhost:5000/moderate/batch \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      {"content": "Great product!", "source": "review"},
      {"content": "Buy cheap followers now!", "source": "message"}
    ]
  }'

Enter fullscreen mode Exit fullscreen mode

为什么这种形式有用

重要的思路是将明显的审核案例与微妙的案例分开。

已知的坏模式可以用 embeddings 相似度处理。

模棱两可的内容可以交给 LLM 进行分类和推理。

响应结构化程度足以插入到产品逻辑中:

  • allow
  • flag
  • remove
  • escalate

对于生产环境,我会添加持久性、审计日志、人工审核队列、速率限制和反馈循环,以便审核者可以随着时间的推移调整黑名单和阈值。

资源: