@@ -639,6 +639,10 @@ msgid "The model is currently disabled. Please try again later." msgstr "" "Модель в настоящее время неактивна. Пожалуйста, повторите попытку позже." +#: ml_model/exceptions.py:119 +msgid "Service is currently unavailable due to high demand. Please try again later" +msgstr "Сервис временно недоступен из-за высокой нагрузки. Пожалуйста, попробуйте позже" + #: ml_model/exceptions.py:23 msgid "Your request was blocked by our moderation system" msgstr "Ваш запрос был заблокирован нашей системой модерации" @@ -9,7 +9,12 @@ from django.core.files import File from replicate.exceptions import ModelError from messages.models import Message -from ml_model.exceptions import ImageContentNotFound, GenerationException, RequestBlocked +from ml_model.exceptions import ( + ImageContentNotFound, + GenerationException, + RequestBlocked, + ServiceHighDemandError, +) from ml_model.services.base import SimpleService from ml_model.tasks import replicate_run @@ -65,6 +70,8 @@ class Nanobanana_2(SimpleService): raise ImageContentNotFound elif any(error in str(exc) for error in ('E005', 'E006', 'sexual')): raise RequestBlocked + elif 'E003' in str(exc): + raise ServiceHighDemandError from exc raise GenerationException from exc process_time = timedelta(seconds=(time.time() - start_time)) self.handle_invoice(input_message.content_object.model, resolution=resolution) @@ -111,3 +111,8 @@ class PromptLengthExceeded(Exception): return _('Prompt is too long. Maximum length is %(max_length)s characters.') % { 'max_length': self.max_length } + + +class ServiceHighDemandError(Exception): + def __str__(self) -> str: + return _('Service is currently unavailable due to high demand. Please try again later') @@ -19,6 +19,7 @@ from ml_model.exceptions import ( InvalidStyleCombinationError, PromptLengthExceeded, FileExtensionNotSupported, + ServiceHighDemandError, ) from ml_model.models import NeuronModel from ml_model.services.base import SimpleService @@ -183,6 +184,7 @@ class MediaAPIView(APIView): InvalidParameterError, PromptLengthExceeded, FileExtensionNotSupported, + ServiceHighDemandError, ), ): return Response({'detail': f'{exc}'}, status=HTTP_400_BAD_REQUEST)