@@ -36,7 +36,8 @@ class NeuronModelSelector: 'image': 'images', 'audio': 'audio', 'video': 'videos', - 'code': 'code' + 'code': 'code', + 'voice': 'voice' } models = NeuronModel.objects.prefetch_related( Prefetch( @@ -187,10 +187,33 @@ class MediaAPIView(APIView): ) try: output_messages = service(gallery).make(input_message) + except ( + UnsupportedSize, + RequestBlocked, + FileNotProvided, + ImageContentNotFound, + ModelCouldNotInterpretPrompt, + InvalidStyleCombinationError, + InvalidParameterError, + ModelVersionNotAvailable, + PromptLengthExceeded, + ExceededContextLengthError, + FileExtensionNotSupported, + ServiceHighDemandError, + CorruptedFileError, + FileTooLargeError, + ImageAnalysisError, + UnrecognizedFileError, + FaceNotFoundError, + RealPersonDetectedError, + ) as exc: + return Response({'detail': f'{exc}'}, status=HTTP_400_BAD_REQUEST) except Exception as exc: - logger.exception(exc) input_message.is_sent = False input_message.save() + if isinstance(exc, InsufficientBalance): + return Response({'detail': f'{exc}'}, status=HTTP_402_PAYMENT_REQUIRED) + logger.exception(exc) if any(phrase in str(exc) for phrase in ('Insufficient credit', 'Request was throttled')): return Response( { @@ -200,32 +223,6 @@ class MediaAPIView(APIView): }, status=HTTP_402_PAYMENT_REQUIRED, ) - if isinstance(exc, InsufficientBalance): - return Response({'detail': f'{exc}'}, status=HTTP_402_PAYMENT_REQUIRED) - if isinstance( - exc, - ( - UnsupportedSize, - RequestBlocked, - FileNotProvided, - ImageContentNotFound, - ModelCouldNotInterpretPrompt, - InvalidStyleCombinationError, - InvalidParameterError, - ModelVersionNotAvailable, - PromptLengthExceeded, - ExceededContextLengthError, - FileExtensionNotSupported, - ServiceHighDemandError, - CorruptedFileError, - FileTooLargeError, - ImageAnalysisError, - UnrecognizedFileError, - FaceNotFoundError, - RealPersonDetectedError, - ), - ): - return Response({'detail': f'{exc}'}, status=HTTP_400_BAD_REQUEST) return Response( { 'detail': _(