FakeTextProcessingProviderSync.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Testing\Provider;
  7. use OCP\TextProcessing\FreePromptTaskType;
  8. use OCP\TextProcessing\IProviderWithExpectedRuntime;
  9. use OCP\TextProcessing\ITaskType;
  10. /**
  11. * @template-implements IProviderWithExpectedRuntime<FreePromptTaskType|ITaskType>
  12. */
  13. class FakeTextProcessingProviderSync implements IProviderWithExpectedRuntime {
  14. public function getName(): string {
  15. return 'Fake text processing provider (synchronous)';
  16. }
  17. public function process(string $prompt): string {
  18. return $this->mb_strrev($prompt) . ' (done with FakeTextProcessingProviderSync)';
  19. }
  20. public function getTaskType(): string {
  21. return FreePromptTaskType::class;
  22. }
  23. public function getExpectedRuntime(): int {
  24. return 1;
  25. }
  26. /**
  27. * Reverse a miltibyte string.
  28. *
  29. * @param string $string The string to be reversed.
  30. * @return string The reversed string
  31. */
  32. private function mb_strrev(string $string): string {
  33. $chars = mb_str_split($string, 1);
  34. return implode('', array_reverse($chars));
  35. }
  36. }