モデレーションは「LLMに聞くだけでいい」と一見思える機能ですが、常に最適なワークフローとは限りません。
一部のコンテンツは明白です。既知のスパム、繰り返される不正使用パターン、一般的な詐欺テキストは、迅速かつ一貫して検出する必要があります。
その他のコンテンツは判断が必要です。文脈依存、曖昧、皮肉、または境界線上の場合があります。
Telnyx AI Inferenceを利用したPython Flaskの例を作成しました:
https://github.com/team-telnyx/telnyx-code-examples/tree/main/moderation-classifier-python
このアプリは2段階のパイプラインを使用します:
- 既知の不正ブロックリストに対する埋め込み事前フィルタリング。
- ブロックリストに強い一致がない場合のLLMモデレーション判断。
フロー
コンテンツをモデレートする前に、ブロックリストインデックスを構築します:
curl -X POST http://localhost:5000/blocklist/index
フルスクリーンモードに入る フルスクリーンモードを終了
これにより、sample_blocklist.jsonのエントリが以下を通じて埋め込まれます:
POST /v2/ai/openai/embeddings
フルスクリーンモードに入る フルスクリーンモードを終了
次に、単一のコンテンツを分類できます:
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"
}'
フルスクリーンモードに入る フルスクリーンモードを終了
アプリは構造化フィールドを返します:
{
"category": "safe",
"confidence": 1.0,
"flags": [],
"blocklist_match": false,
"recommended_action": "allow",
"reason": "Benign positive product review with no policy violations."
}
フルスクリーンモードに入る フルスクリーンモードを終了
コンテンツがブロックリストに十分一致する場合、アプリはLLMをスキップし、一致したカテゴリを直接返します。
それ以外の場合は以下を呼び出します:
POST /v2/ai/chat/completions
フルスクリーンモードに入る フルスクリーンモードを終了
デフォルトのモデルは以下の通りです:
AI_MODEL=moonshotai/Kimi-K2.6
EMBEDDING_MODEL=thenlper/gte-large
フルスクリーンモードに入る フルスクリーンモードを終了
含まれるエンドポイント
この例には以下が含まれます:
POST /blocklist/indexPOST /moderatePOST /moderate/batchPOST /blocklistGET /blocklistGET /moderationsGET /moderations/<id>GET /statsGET /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"}
]
}'
フルスクリーンモードに入る フルスクリーンモードを終了
この形状が有用な理由
重要な考え方は、明白なモデレーションケースと微妙なケースを分離することです。
既知の不正パターンは埋め込み類似度で処理できます。
曖昧なコンテンツは分類と推論のためにLLMに送ることができます。
レスポンスは製品ロジックに組み込めるほど構造化されています:
allowflagremoveescalate
本番環境では、永続化、監査ログ、人間によるレビューのキュー、レート制限、レビュアーが時間とともにブロックリストと閾値を調整できるフィードバックループを追加することをお勧めします。
リソース:
- コード: https://github.com/team-telnyx/telnyx-code-examples/tree/main/moderation-classifier-python
- Telnyx AI Inference ドキュメント: https://developers.telnyx.com/docs/inference
- Embeddings API: https://developers.telnyx.com/api/inference/create-embeddings
- Chat Completions API: https://developers.telnyx.com/api/inference/chat-completions
- Telnyx AI skills and toolkits: https://github.com/team-telnyx/ai
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.