1
0

FakeTextProcessingProvider.php 998 B

1234567891011121314151617181920212223242526272829303132333435363738
  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\IProvider;
  9. use OCP\TextProcessing\ITaskType;
  10. /** @template-implements IProvider<FreePromptTaskType|ITaskType> */
  11. class FakeTextProcessingProvider implements IProvider {
  12. public function getName(): string {
  13. return 'Fake text processing provider (asynchronous)';
  14. }
  15. public function process(string $prompt): string {
  16. return $this->mb_strrev($prompt) . ' (done with FakeTextProcessingProvider)';
  17. }
  18. public function getTaskType(): string {
  19. return FreePromptTaskType::class;
  20. }
  21. /**
  22. * Reverse a miltibyte string.
  23. *
  24. * @param string $string The string to be reversed.
  25. * @return string The reversed string
  26. */
  27. private function mb_strrev(string $string): string {
  28. $chars = mb_str_split($string, 1);
  29. return implode('', array_reverse($chars));
  30. }
  31. }