Merge pull request #49358 from nextcloud/backport/49357/stable30

[stable30] test(fakeAI): Allow to specify whether the fake providers should fail
This commit is contained in:
Joas Schilling 2024-11-19 17:02:08 +01:00 committed by GitHub
commit 03d7aa6fe4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 50 additions and 4 deletions

View 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'])

View 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');
}

View 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 {

View 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 {

View 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';

View 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 {