33 lines
770 B
Python
33 lines
770 B
Python
from celery import Celery
|
|
from app.core.config import settings
|
|
from app.handlers.toxicity_handler import ToxicityHandler
|
|
|
|
celery_app = Celery(
|
|
'tasks',
|
|
broker=settings.CELERY_BROKER_URL,
|
|
backend=settings.CELERY_RESULT_BACKEND
|
|
)
|
|
|
|
celery_app.conf.update(
|
|
task_serializer='json',
|
|
result_serializer='json',
|
|
accept_content=['json'],
|
|
timezone='UTC',
|
|
enable_utc=True,
|
|
)
|
|
|
|
toxicity_handler = ToxicityHandler()
|
|
|
|
@celery_app.task
|
|
def assess_toxicity_task(text: str) -> float:
|
|
"""
|
|
Задача для оценки токсичности текста.
|
|
|
|
Args:
|
|
text (str): Входной текст.
|
|
|
|
Returns:
|
|
float: Оценка токсичности.
|
|
"""
|
|
return toxicity_handler.text_to_toxicity(text)
|