Files
jev-decision-hub/examples/spam_moderation.py
T

33 lines
1.8 KiB
Python

"""Пример: спам-модерация постов/сообщений через Jev.
Порог по noul + действие через choice. Один вызов на пост, ~1 кредит."""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from jev_client import decide
SPAM_THRESHOLD = 0.7
def moderate(post_text: str, author_meta: str = '') -> dict:
state = f"Post: {post_text}\nAuthor: {author_meta or 'unknown'}"
r = decide(state=state, questions={
'spam': {'type': 'noul', 'instructions': 'Is this post spam/scam/ads for grey services?'},
'nsfw': {'type': 'noul', 'instructions': 'Does this contain NSFW content?'},
'action': {'type': 'choice', 'instructions': 'Choose moderation action',
'criteria': {'ban': 'ban author and delete', 'delete': 'delete post only',
'flag': 'flag for human review', 'keep': 'leave as is'}},
})
a = r['answers']
verdict = 'BLOCK' if a['spam']['noul'] >= SPAM_THRESHOLD or a['nsfw']['noul'] >= SPAM_THRESHOLD else 'PASS'
return {'verdict': verdict, 'spam': a['spam']['noul'], 'nsfw': a['nsfw']['noul'],
'action': a['action']['choice'], 'confidence': a['action'].get('confidence')}
if __name__ == '__main__':
samples = [
'Продаю аккаунты Telegram с историей, дешево, писать в лс @spamlord',
'Кто-нибудь пробовал jev-ai.pro? Как вам качество решений по сравнению с GPT?',
'СКАЧАЙ КРЯК БЕЗ СМС >>> http://bit.ly/fr3e-win',
]
for s in samples:
res = moderate(s)
print(f"{res['verdict']:5} spam={res['spam']:.2f} action={res['action']:7} | {s[:60]}")