diff options
Diffstat (limited to 'apps/testing/lib/Provider')
4 files changed, 146 insertions, 0 deletions
diff --git a/apps/testing/lib/Provider/FakeText2ImageProvider.php b/apps/testing/lib/Provider/FakeText2ImageProvider.php new file mode 100644 index 00000000000..6b607f23347 --- /dev/null +++ b/apps/testing/lib/Provider/FakeText2ImageProvider.php @@ -0,0 +1,33 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\Testing\Provider; + +use OCP\TextToImage\IProvider; + +class FakeText2ImageProvider implements IProvider { + + public function getName(): string { + return 'Fake Text2Image provider'; + } + + public function generate(string $prompt, array $resources): void { + foreach ($resources as $resource) { + $read = fopen(__DIR__ . '/../../img/logo.png', 'r'); + stream_copy_to_stream($read, $resource); + fclose($read); + } + } + + public function getExpectedRuntime(): int { + return 1; + } + + public function getId(): string { + return 'testing-fake-text2image-provider'; + } +} diff --git a/apps/testing/lib/Provider/FakeTextProcessingProvider.php b/apps/testing/lib/Provider/FakeTextProcessingProvider.php new file mode 100644 index 00000000000..d3b16c55c67 --- /dev/null +++ b/apps/testing/lib/Provider/FakeTextProcessingProvider.php @@ -0,0 +1,39 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\Testing\Provider; + +use OCP\TextProcessing\FreePromptTaskType; +use OCP\TextProcessing\IProvider; +use OCP\TextProcessing\ITaskType; + +/** @template-implements IProvider<FreePromptTaskType|ITaskType> */ +class FakeTextProcessingProvider implements IProvider { + + public function getName(): string { + return 'Fake text processing provider (asynchronous)'; + } + + public function process(string $prompt): string { + return $this->mb_strrev($prompt) . ' (done with FakeTextProcessingProvider)'; + } + + public function getTaskType(): string { + return FreePromptTaskType::class; + } + + /** + * Reverse a miltibyte string. + * + * @param string $string The string to be reversed. + * @return string The reversed string + */ + private function mb_strrev(string $string): string { + $chars = mb_str_split($string, 1); + return implode('', array_reverse($chars)); + } +} diff --git a/apps/testing/lib/Provider/FakeTextProcessingProviderSync.php b/apps/testing/lib/Provider/FakeTextProcessingProviderSync.php new file mode 100644 index 00000000000..ea822199109 --- /dev/null +++ b/apps/testing/lib/Provider/FakeTextProcessingProviderSync.php @@ -0,0 +1,45 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\Testing\Provider; + +use OCP\TextProcessing\FreePromptTaskType; +use OCP\TextProcessing\IProviderWithExpectedRuntime; +use OCP\TextProcessing\ITaskType; + +/** + * @template-implements IProviderWithExpectedRuntime<FreePromptTaskType|ITaskType> + */ +class FakeTextProcessingProviderSync implements IProviderWithExpectedRuntime { + + public function getName(): string { + return 'Fake text processing provider (synchronous)'; + } + + public function process(string $prompt): string { + return $this->mb_strrev($prompt) . ' (done with FakeTextProcessingProviderSync)'; + } + + public function getTaskType(): string { + return FreePromptTaskType::class; + } + + public function getExpectedRuntime(): int { + return 1; + } + + /** + * Reverse a miltibyte string. + * + * @param string $string The string to be reversed. + * @return string The reversed string + */ + private function mb_strrev(string $string): string { + $chars = mb_str_split($string, 1); + return implode('', array_reverse($chars)); + } +} diff --git a/apps/testing/lib/Provider/FakeTranslationProvider.php b/apps/testing/lib/Provider/FakeTranslationProvider.php new file mode 100644 index 00000000000..cc2d13db646 --- /dev/null +++ b/apps/testing/lib/Provider/FakeTranslationProvider.php @@ -0,0 +1,29 @@ +<?php + +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\Testing\Provider; + +use OCP\Translation\ITranslationProvider; +use OCP\Translation\LanguageTuple; + +class FakeTranslationProvider implements ITranslationProvider { + + public function getName(): string { + return 'Fake translation'; + } + + public function getAvailableLanguages(): array { + return [ + new LanguageTuple('de', 'German', 'en', 'English'), + new LanguageTuple('en', 'English', 'de', 'German'), + ]; + } + + public function translate(?string $fromLanguage, string $toLanguage, string $text): string { + return strrev($text); + } +} |