Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions lib/TaskProcessing/AnalyzeImagesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ public function process(
}
// Maximum file count for openai is 500. Seems reasonable enough to enforce for all apis though (https://platform.openai.com/docs/guides/images-vision?api-mode=responses&format=url#image-input-requirements)
if (count($input['images']) > 500) {
throw new ProcessingException('Too many files given. Max is 500');
throw new UserFacingProcessingException(
'Too many files given. Max is 500',
0,
null,
$this->l->t('Too many files given. A maximum of 500 files is allowed.'),
);
}
$fileSize = 0;
foreach ($input['images'] as $image) {
Expand All @@ -129,12 +134,22 @@ public function process(
$fileSize += intval($image->getSize());
// Maximum file size for openai is 50MB. Seems reasonable enough to enforce for all apis though. (https://platform.openai.com/docs/guides/images-vision?api-mode=responses&format=url#image-input-requirements)
if ($fileSize > 50 * 1000 * 1000) {
throw new ProcessingException('Filesize of input files too large. Max is 50MB');
throw new UserFacingProcessingException(
'Filesize of input files too large. Max is 50MB',
0,
null,
$this->l->t('The total size of the input files is too large. A maximum of 50MB is allowed.'),
);
}
$inputFile = base64_encode(stream_get_contents($image->fopen('rb')));
$fileType = $image->getMimeType();
if (!str_starts_with($fileType, 'image/')) {
throw new ProcessingException('Invalid input file type ' . $fileType);
throw new UserFacingProcessingException(
'Invalid input file type ' . $fileType,
0,
null,
$this->l->t('Invalid input file type "%1$s". Only image files are supported.', [$fileType]),
);
}
if ($this->openAiAPIService->isUsingOpenAi()) {
$validFileTypes = [
Expand All @@ -144,7 +159,12 @@ public function process(
'image/webp',
];
if (!in_array($fileType, $validFileTypes)) {
throw new ProcessingException('Invalid input file type for OpenAI ' . $fileType);
throw new UserFacingProcessingException(
'Invalid input file type for OpenAI ' . $fileType,
0,
null,
$this->l->t('Invalid input file type "%1$s". Only JPEG, PNG, GIF and WebP images are supported.', [$fileType]),
);
}
}
$history[] = json_encode([
Expand Down
7 changes: 7 additions & 0 deletions lib/TaskProcessing/AudioToAudioTranslateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OCP\L10N\IFactory;
use OCP\TaskProcessing\EShapeType;
use OCP\TaskProcessing\Exception\ProcessingException;
use OCP\TaskProcessing\Exception\UserFacingProcessingException;
use OCP\TaskProcessing\IProvider;
use OCP\TaskProcessing\ISynchronousOptionsAwareProvider;
use OCP\TaskProcessing\ShapeDescriptor;
Expand Down Expand Up @@ -162,6 +163,8 @@ public function process(
$sttModel = $this->appConfig->getValueString(Application::APP_ID, 'default_stt_model_id', Application::DEFAULT_MODEL_ID, lazy: true) ?: Application::DEFAULT_MODEL_ID;
try {
$transcription = $this->openAiAPIService->transcribeFile($userId, $inputFile, false, $sttModel, $input['origin_language']);
} catch (UserFacingProcessingException $e) {
throw $e;
} catch (Exception $e) {
$this->logger->warning('Transcription failed with: ' . $e->getMessage(), ['exception' => $e]);
throw new ProcessingException(
Expand Down Expand Up @@ -222,6 +225,8 @@ public function process(
if (empty($translatedText)) {
throw new ProcessingException("Empty translation result from {$input['origin_language']} to {$input['target_language']}");
}
} catch (UserFacingProcessingException $e) {
throw $e;
} catch (Exception $e) {
throw new ProcessingException(
"Failed to translate from {$input['origin_language']} to {$input['target_language']}: {$e->getMessage()}",
Expand Down Expand Up @@ -267,6 +272,8 @@ public function process(
throw new ProcessingException('Text to speech generation failed: no speech returned');
}
$translatedAudio = $includeWatermark ? $this->watermarkingService->markAudio($apiResponse['body']) : $apiResponse['body'];
} catch (UserFacingProcessingException $e) {
throw $e;
} catch (Exception $e) {
$this->logger->warning('Text to speech generation failed with: ' . $e->getMessage(), ['exception' => $e]);
throw new ProcessingException(
Expand Down
Loading