Skip to content

Commit c0085f1

Browse files
committed
fix(TextToImage): Use user-facing error messages
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent afda84d commit c0085f1

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/TaskProcessing/TextToImageProvider.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCP\Http\Client\IClientService;
1313
use OCP\IL10N;
1414
use OCP\TaskProcessing\Exception\ProcessingException;
15+
use OCP\TaskProcessing\Exception\UserFacingProcessingException;
1516
use OCP\TaskProcessing\ISynchronousWatermarkingProvider;
1617
use OCP\TaskProcessing\TaskTypes\TextToImage;
1718
use Psr\Log\LoggerInterface;
@@ -44,6 +45,14 @@ public function process(?string $userId, array $input, callable $reportProgress,
4445
$nbOutputs = $input['numberOfImages'];
4546
$waitingForAlready = 0;
4647
$maxWaitTime = 60 * 60;
48+
49+
if ($nbOutputs > 12) {
50+
throw new UserFacingProcessingException('numberOfImages is out of bounds', userFacingMessage: $this->l->t('Cannot generate more then 12 images'));
51+
}
52+
if ($nbOutputs < 1) {
53+
throw new UserFacingProcessingException('numberOfImages is out of bounds', userFacingMessage: $this->l->t('Cannot generate less then 1 image'));
54+
}
55+
4756
try {
4857
$prediction = $this->replicateAPIService->createImagePrediction($prompt, $nbOutputs);
4958

0 commit comments

Comments
 (0)