Skip to content

Commit

Permalink
Revert use of celery task for Discord notifications (#3516)
Browse files Browse the repository at this point in the history
Should fix #3504
  • Loading branch information
olliestanley committed Jun 25, 2023
1 parent 4f1b1eb commit 3adb15b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions backend/oasst_backend/prompt_repository.py
Expand Up @@ -30,8 +30,8 @@
from oasst_backend.models.payload_column_type import PayloadContainer
from oasst_backend.task_repository import TaskRepository, validate_frontend_message_id
from oasst_backend.user_repository import UserRepository
from oasst_backend.utils import discord
from oasst_backend.utils.database_utils import CommitMode, db_lang_to_postgres_ts_lang, managed_tx_method
from oasst_backend.utils.discord import send_new_report_message
from oasst_shared.exceptions import OasstError, OasstErrorCode
from oasst_shared.schemas import protocol as protocol_schema
from oasst_shared.schemas.protocol import SystemStats
Expand Down Expand Up @@ -595,7 +595,7 @@ def store_text_labels(self, text_labels: protocol_schema.TextLabels) -> tuple[Te
message_id, protocol_schema.EmojiOp.add, protocol_schema.EmojiCode.red_flag
)

send_new_report_message.delay(message=message, label_text=text_labels.text, user_id=self.user_id)
discord.send_new_report_message(message=message, label_text=text_labels.text, user_id=self.user_id)

# update existing record for repeated updates (same user no task associated)
existing_text_label = self.fetch_non_task_text_labels(message_id, self.user_id)
Expand Down
3 changes: 0 additions & 3 deletions backend/oasst_backend/utils/discord.py
Expand Up @@ -2,18 +2,15 @@

import requests
from loguru import logger
from oasst_backend.celery_worker import app as celery_app
from oasst_backend.config import settings
from oasst_backend.models.message import Message

ROOT_ENDPOINT = "https://discord.com/api/v10"


@celery_app.task(name="send_new_report_message")
def send_new_report_message(message: Message, label_text: str, user_id: UUID):
"""
Send a message to the Discord channel when a new message is flagged.
Note: this is a Celery task.
Args:
message (Message): the flagged message
Expand Down
4 changes: 2 additions & 2 deletions backend/update_message_attributes.py
Expand Up @@ -2,7 +2,7 @@

from loguru import logger
from oasst_backend.models import ApiClient, Message
from oasst_backend.scheduled_tasks import check_toxicity, hf_feature_extraction
from oasst_backend.scheduled_tasks import hf_feature_extraction, toxicity
from oasst_backend.utils.database_utils import default_session_factory
from sqlmodel import text

Expand Down Expand Up @@ -71,7 +71,7 @@ def find_and_update_toxicity(message_ids):
text = result.payload.payload.text
api_client = session.query(ApiClient).filter(ApiClient.id == api_client_id).first()
if api_client is not None and text is not None:
check_toxicity(text=text, message_id=message_id, api_client=api_client.__dict__)
toxicity(text=text, message_id=message_id, api_client=api_client.__dict__)
# to not get rate limited from HF
time.sleep(10)
except Exception as e:
Expand Down

0 comments on commit 3adb15b

Please sign in to comment.