@@ -1257,3 +1257,7 @@ msgstr "Нейронная модель не существует" msgid "Email token not found. Please contact support" msgstr "E-mail токен не найден. Пожалуйста, свяжитесь со службой поддержки" + + +msgid "We are temporarily unable to process your request, please try again in 5 minutes" +msgstr "Временно не можем обработать ваш запрос, пожалуйста, повторите через 5 минут" @@ -11,7 +11,8 @@ from django.conf import settings from django.core.files import File from messages.models import Message -from ml_model.exceptions import ModelTimeoutError, RequestBlocked, UnsupportedSize +from ml_model.exceptions import (ModelTimeoutError, RequestBlocked, + UnsupportedSize, ResponseTimeoutError) from ml_model.services.base import SimpleService from poller.models import Proxy @@ -97,6 +98,8 @@ class Sora(SimpleService): if error_message == "Your request was blocked by our moderation system.": raise RequestBlocked raise Exception("Video generation failed") + if timedelta(seconds=(time.time() - start_time >= 150)): + raise ResponseTimeoutError time.sleep(1/3) video = client.get(f"videos/{video_id}/content").content process_time = timedelta(seconds=(time.time() - start_time)) @@ -43,6 +43,10 @@ class ModelTimeoutError(Exception): return _('The model is not responding') +class ResponseTimeoutError(Exception): + def __str__(self): + return _('We are temporarily unable to process your request, please try again in 5 minutes') + class FileExtensionNotSupported(Exception): def __init__(self, extensions: list[str]) -> None: self.extensions = extensions @@ -14,7 +14,7 @@ from messages.serializers import MessageSerializer from ml_model.models import NeuronModel from ml_model.services.base import SimpleService from payments.exceptions.insufficient_balance import InsufficientBalance -from ml_model.exceptions import UnsupportedSize +from ml_model.exceptions import UnsupportedSize, ResponseTimeoutError from .models import Audio, Image, Video @@ -156,6 +156,8 @@ class MediaAPIView(APIView): return Response({'detail': f'{exc}'}, status=HTTP_402_PAYMENT_REQUIRED) if isinstance(exc, UnsupportedSize): return Response({'detail': f'{exc}'}, status=HTTP_400_BAD_REQUEST) + if isinstance(exc, ResponseTimeoutError): + return Response({'detail': f'{exc}'}, status=HTTP_400_BAD_REQUEST) return Response( { 'detail': _(