審核是一項產品功能,「直接問 LLM」聽起來很誘人,但不總是最佳工作流程。
有些內容很明顯。已知垃圾訊息、重複濫用模式,以及常見詐騙文字應該要快速且一致地攔截。
其他內容則需要判斷。它可能是情境相關、模糊、諷刺或介於邊緣。
我整理了一個 Python Flask 範例,使用 Telnyx AI Inference 來處理這兩條路徑:
https://github.com/team-telnyx/telnyx-code-examples/tree/main/moderation-classifier-python
此應用程式使用兩階段管線:
- 使用 Embeddings 預先過濾已知不良的封鎖清單。
- 當沒有強烈的封鎖清單匹配時,使用 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/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"}
]
}'
Enter fullscreen mode Exit fullscreen mode
為什麼這種形式很有用
重要的概念是將明顯的審核案例與需要細微判斷的案例分開。
已知的不良模式可以使用 embeddings 相似度處理。
模稜兩可的內容可以交給 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 技能與工具包:https://github.com/team-telnyx/ai
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.