]> source.dussan.org Git - nextcloud-server.git/commitdiff
test(fakeAI): Allow to specify whether the fake providers should fail bugfix/noid/allow-to-fail-fake-AI-providers 49357/head
authorJoas Schilling <coding@schilljs.com>
Mon, 18 Nov 2024 21:01:15 +0000 (22:01 +0100)
committerJoas Schilling <coding@schilljs.com>
Mon, 18 Nov 2024 21:01:15 +0000 (22:01 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/testing/lib/TaskProcessing/FakeContextWriteProvider.php
apps/testing/lib/TaskProcessing/FakeTextToImageProvider.php
apps/testing/lib/TaskProcessing/FakeTextToTextProvider.php
apps/testing/lib/TaskProcessing/FakeTextToTextSummaryProvider.php
apps/testing/lib/TaskProcessing/FakeTranscribeProvider.php
apps/testing/lib/TaskProcessing/FakeTranslateProvider.php

index 32aa1ebd7c97119e63a443d0c34fe31da79c97ea..41797f87d8b99f922c56c6c96182616d4a76a777 100644 (file)
@@ -9,7 +9,9 @@ declare(strict_types=1);
 namespace OCA\Testing\TaskProcessing;
 
 use OCA\Testing\AppInfo\Application;
+use OCP\AppFramework\Services\IAppConfig;
 use OCP\TaskProcessing\EShapeType;
+use OCP\TaskProcessing\Exception\ProcessingException;
 use OCP\TaskProcessing\ISynchronousProvider;
 use OCP\TaskProcessing\ShapeDescriptor;
 use OCP\TaskProcessing\ShapeEnumValue;
@@ -18,7 +20,9 @@ use RuntimeException;
 
 class FakeContextWriteProvider implements ISynchronousProvider {
 
-       public function __construct() {
+       public function __construct(
+               protected IAppConfig $appConfig,
+       ) {
        }
 
        public function getId(): string {
@@ -90,6 +94,10 @@ class FakeContextWriteProvider implements ISynchronousProvider {
        }
 
        public function process(?string $userId, array $input, callable $reportProgress): array {
+               if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
+                       throw new ProcessingException('Failing as set by AppConfig');
+               }
+
                if (
                        !isset($input['style_input']) || !is_string($input['style_input'])
                                || !isset($input['source_input']) || !is_string($input['source_input'])
index 429b3af9d574f2c66deb31379d4c770db3f85daf..cd508be9155b61f4bdb3e07947653be67f9c0981 100644 (file)
@@ -9,7 +9,9 @@ declare(strict_types=1);
 namespace OCA\Testing\TaskProcessing;
 
 use OCA\Testing\AppInfo\Application;
+use OCP\AppFramework\Services\IAppConfig;
 use OCP\TaskProcessing\EShapeType;
+use OCP\TaskProcessing\Exception\ProcessingException;
 use OCP\TaskProcessing\ISynchronousProvider;
 use OCP\TaskProcessing\ShapeDescriptor;
 use OCP\TaskProcessing\TaskTypes\TextToImage;
@@ -17,7 +19,9 @@ use RuntimeException;
 
 class FakeTextToImageProvider implements ISynchronousProvider {
 
-       public function __construct() {
+       public function __construct(
+               protected IAppConfig $appConfig,
+       ) {
        }
 
        public function getId(): string {
@@ -77,6 +81,10 @@ class FakeTextToImageProvider implements ISynchronousProvider {
        }
 
        public function process(?string $userId, array $input, callable $reportProgress): array {
+               if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
+                       throw new ProcessingException('Failing as set by AppConfig');
+               }
+
                if (!isset($input['input']) || !is_string($input['input'])) {
                        throw new RuntimeException('Invalid prompt');
                }
index 9854cd3e60923f6316e5df0807365246481c4c5f..6afa2539f10260a24e5472cfc3d7ba88f2c060c0 100644 (file)
@@ -9,7 +9,9 @@ declare(strict_types=1);
 namespace OCA\Testing\TaskProcessing;
 
 use OCA\Testing\AppInfo\Application;
+use OCP\AppFramework\Services\IAppConfig;
 use OCP\TaskProcessing\EShapeType;
+use OCP\TaskProcessing\Exception\ProcessingException;
 use OCP\TaskProcessing\ISynchronousProvider;
 use OCP\TaskProcessing\ShapeDescriptor;
 use OCP\TaskProcessing\ShapeEnumValue;
@@ -18,7 +20,9 @@ use RuntimeException;
 
 class FakeTextToTextProvider implements ISynchronousProvider {
 
-       public function __construct() {
+       public function __construct(
+               protected IAppConfig $appConfig,
+       ) {
        }
 
        public function getId(): string {
@@ -90,6 +94,10 @@ class FakeTextToTextProvider implements ISynchronousProvider {
        }
 
        public function process(?string $userId, array $input, callable $reportProgress): array {
+               if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
+                       throw new ProcessingException('Failing as set by AppConfig');
+               }
+
                if (isset($input['model']) && is_string($input['model'])) {
                        $model = $input['model'];
                } else {
index 8be1dc5a65e1c2dbd6763a5a47797058206e69a7..58816d8a0dfb61e1b489e04ea475d2337220a9a3 100644 (file)
@@ -10,7 +10,9 @@ declare(strict_types=1);
 namespace OCA\Testing\TaskProcessing;
 
 use OCA\Testing\AppInfo\Application;
+use OCP\AppFramework\Services\IAppConfig;
 use OCP\TaskProcessing\EShapeType;
+use OCP\TaskProcessing\Exception\ProcessingException;
 use OCP\TaskProcessing\ISynchronousProvider;
 use OCP\TaskProcessing\ShapeDescriptor;
 use OCP\TaskProcessing\ShapeEnumValue;
@@ -19,7 +21,9 @@ use RuntimeException;
 
 class FakeTextToTextSummaryProvider implements ISynchronousProvider {
 
-       public function __construct() {
+       public function __construct(
+               protected IAppConfig $appConfig,
+       ) {
        }
 
        public function getId(): string {
@@ -91,6 +95,10 @@ class FakeTextToTextSummaryProvider implements ISynchronousProvider {
        }
 
        public function process(?string $userId, array $input, callable $reportProgress): array {
+               if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
+                       throw new ProcessingException('Failing as set by AppConfig');
+               }
+
                if (isset($input['model']) && is_string($input['model'])) {
                        $model = $input['model'];
                } else {
index 5401c5e16f8d5335af2af8035ad134c96a503f24..933192c95c18cb42b5518df57f92d0b074b507f3 100644 (file)
@@ -9,7 +9,9 @@ declare(strict_types=1);
 namespace OCA\Testing\TaskProcessing;
 
 use OCA\Testing\AppInfo\Application;
+use OCP\AppFramework\Services\IAppConfig;
 use OCP\Files\File;
+use OCP\TaskProcessing\Exception\ProcessingException;
 use OCP\TaskProcessing\ISynchronousProvider;
 use OCP\TaskProcessing\TaskTypes\AudioToText;
 use RuntimeException;
@@ -17,6 +19,7 @@ use RuntimeException;
 class FakeTranscribeProvider implements ISynchronousProvider {
 
        public function __construct(
+               protected IAppConfig $appConfig,
        ) {
        }
 
@@ -72,6 +75,10 @@ class FakeTranscribeProvider implements ISynchronousProvider {
                if (!isset($input['input']) || !$input['input'] instanceof File || !$input['input']->isReadable()) {
                        throw new RuntimeException('Invalid input file');
                }
+               if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
+                       throw new ProcessingException('Failing as set by AppConfig');
+               }
+
                $inputFile = $input['input'];
                $transcription = 'Fake transcription result';
 
index 064f54f2650650017e0b9c95561e759ce522ab90..728932acdb3ff22aeef70152844691d1902578e9 100644 (file)
@@ -9,8 +9,10 @@ declare(strict_types=1);
 namespace OCA\Testing\TaskProcessing;
 
 use OCA\Testing\AppInfo\Application;
+use OCP\AppFramework\Services\IAppConfig;
 use OCP\L10N\IFactory;
 use OCP\TaskProcessing\EShapeType;
+use OCP\TaskProcessing\Exception\ProcessingException;
 use OCP\TaskProcessing\ISynchronousProvider;
 use OCP\TaskProcessing\ShapeDescriptor;
 use OCP\TaskProcessing\ShapeEnumValue;
@@ -21,6 +23,7 @@ class FakeTranslateProvider implements ISynchronousProvider {
 
        public function __construct(
                private IFactory $l10nFactory,
+               protected IAppConfig $appConfig,
        ) {
        }
 
@@ -113,6 +116,10 @@ class FakeTranslateProvider implements ISynchronousProvider {
        }
 
        public function process(?string $userId, array $input, callable $reportProgress): array {
+               if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
+                       throw new ProcessingException('Failing as set by AppConfig');
+               }
+
                if (isset($input['model']) && is_string($input['model'])) {
                        $model = $input['model'];
                } else {