Skip to content

Commit

Permalink
Merge pull request #49357 from nextcloud/bugfix/noid/allow-to-fail-fa…
Browse files Browse the repository at this point in the history
…ke-AI-providers

test(fakeAI): Allow to specify whether the fake providers should fail
  • Loading branch information
miaulalala authored Nov 19, 2024
2 parents bb2e8e0 + 5e5a53c commit 935f0d2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
10 changes: 9 additions & 1 deletion apps/testing/lib/TaskProcessing/FakeContextWriteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
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;
Expand All @@ -18,7 +20,9 @@

class FakeContextWriteProvider implements ISynchronousProvider {

public function __construct() {
public function __construct(
protected IAppConfig $appConfig,
) {
}

public function getId(): string {
Expand Down Expand Up @@ -90,6 +94,10 @@ public function getOptionalOutputShapeEnumValues(): array {
}

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'])
Expand Down
10 changes: 9 additions & 1 deletion apps/testing/lib/TaskProcessing/FakeTextToImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
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;
use RuntimeException;

class FakeTextToImageProvider implements ISynchronousProvider {

public function __construct() {
public function __construct(
protected IAppConfig $appConfig,
) {
}

public function getId(): string {
Expand Down Expand Up @@ -77,6 +81,10 @@ public function getOptionalOutputShapeEnumValues(): array {
}

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');
}
Expand Down
10 changes: 9 additions & 1 deletion apps/testing/lib/TaskProcessing/FakeTextToTextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
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;
Expand All @@ -18,7 +20,9 @@

class FakeTextToTextProvider implements ISynchronousProvider {

public function __construct() {
public function __construct(
protected IAppConfig $appConfig,
) {
}

public function getId(): string {
Expand Down Expand Up @@ -90,6 +94,10 @@ public function getOptionalOutputShapeEnumValues(): array {
}

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
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;
Expand All @@ -19,7 +21,9 @@

class FakeTextToTextSummaryProvider implements ISynchronousProvider {

public function __construct() {
public function __construct(
protected IAppConfig $appConfig,
) {
}

public function getId(): string {
Expand Down Expand Up @@ -91,6 +95,10 @@ public function getOptionalOutputShapeEnumValues(): array {
}

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 {
Expand Down
7 changes: 7 additions & 0 deletions apps/testing/lib/TaskProcessing/FakeTranscribeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
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;

class FakeTranscribeProvider implements ISynchronousProvider {

public function __construct(
protected IAppConfig $appConfig,
) {
}

Expand Down Expand Up @@ -72,6 +75,10 @@ public function process(?string $userId, array $input, callable $reportProgress)
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';

Expand Down
7 changes: 7 additions & 0 deletions apps/testing/lib/TaskProcessing/FakeTranslateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
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;
Expand All @@ -21,6 +23,7 @@ class FakeTranslateProvider implements ISynchronousProvider {

public function __construct(
private IFactory $l10nFactory,
protected IAppConfig $appConfig,
) {
}

Expand Down Expand Up @@ -113,6 +116,10 @@ private function getCoreLanguagesByCode(): array {
}

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 {
Expand Down

0 comments on commit 935f0d2

Please sign in to comment.