Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert use of celery task for Discord notifications #3516

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/oasst_backend/prompt_repository.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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