@@ -473,7 +473,7 @@ if (SENTRY_URL := env.str('SENTRY_URL', '')) and RELEASE and ENVIRONMENT: transaction_style='url', middleware_spans=True, signals_spans=True, cache_spans=False ), ], - ignore_errors=['InsufficientBalance'] + ignore_errors=['InsufficientBalance', 'RequestBlocked'] ) CACHEOPS_REDIS = env.str('CACHEOPS_REDIS', CACHES['default']['LOCATION']) @@ -10,6 +10,7 @@ from django.conf import settings from django.core.files import File from messages.models import Message +from ml_model.exceptions import RequestBlocked from ml_model.services.base import SimpleService from poller.models import Proxy @@ -85,13 +86,15 @@ class Stablediffusion(SimpleService): result = client.post( f'https://api.replicate.com/v1/models/stability-ai/{model_name}/predictions', json={'input': callback_data}, - ) - while result.json()['status'] not in ('succeeded', 'failed', 'canceled'): - result = client.get(result.json()['urls']['get']) - if result.json()['status'] in ('failed', 'canceled'): - logger.error(result.json()['logs']) + ).json() + while result['status'] not in ('succeeded', 'failed', 'canceled'): + result = client.get(result['urls']['get']).json() + if result['status'] in ('failed', 'canceled'): + if 'E005' in result['logs']: + raise RequestBlocked + logger.error(result['logs']) raise Exception('No answer from Stable Diffusion, please retry later') - link = result.json()['output'] + link = result['output'] process_time = timedelta(seconds=(time.time() - start_time))