diff options
author | Joas Schilling <coding@schilljs.com> | 2024-11-09 05:05:49 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-11-09 05:34:53 +0100 |
commit | 58bde73b92925431eebc175703a8dd3b09219242 (patch) | |
tree | f4b4240291334d3059c45a823408799a6c7ce522 /apps/testing/lib/TaskProcessing | |
parent | 56be31a436661e9948c7d4b64f82863d47d50e79 (diff) | |
download | nextcloud-server-58bde73b92925431eebc175703a8dd3b09219242.tar.gz nextcloud-server-58bde73b92925431eebc175703a8dd3b09219242.zip |
feat(testing): Add a fake summary task providerfeat/noid/add-fake-summary-provider
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/testing/lib/TaskProcessing')
-rw-r--r-- | apps/testing/lib/TaskProcessing/FakeTextToTextSummaryProvider.php | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/apps/testing/lib/TaskProcessing/FakeTextToTextSummaryProvider.php b/apps/testing/lib/TaskProcessing/FakeTextToTextSummaryProvider.php new file mode 100644 index 00000000000..8be1dc5a65e --- /dev/null +++ b/apps/testing/lib/TaskProcessing/FakeTextToTextSummaryProvider.php @@ -0,0 +1,114 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + + +namespace OCA\Testing\TaskProcessing; + +use OCA\Testing\AppInfo\Application; +use OCP\TaskProcessing\EShapeType; +use OCP\TaskProcessing\ISynchronousProvider; +use OCP\TaskProcessing\ShapeDescriptor; +use OCP\TaskProcessing\ShapeEnumValue; +use OCP\TaskProcessing\TaskTypes\TextToTextSummary; +use RuntimeException; + +class FakeTextToTextSummaryProvider implements ISynchronousProvider { + + public function __construct() { + } + + public function getId(): string { + return Application::APP_ID . '-text2text-summary'; + } + + public function getName(): string { + return 'Fake text2text summary task processing provider'; + } + + public function getTaskTypeId(): string { + return TextToTextSummary::ID; + } + + public function getExpectedRuntime(): int { + return 1; + } + + public function getInputShapeEnumValues(): array { + return []; + } + + public function getInputShapeDefaults(): array { + return []; + } + + public function getOptionalInputShape(): array { + return [ + 'max_tokens' => new ShapeDescriptor( + 'Maximum output words', + 'The maximum number of words/tokens that can be generated in the completion.', + EShapeType::Number + ), + 'model' => new ShapeDescriptor( + 'Model', + 'The model used to generate the completion', + EShapeType::Enum + ), + ]; + } + + public function getOptionalInputShapeEnumValues(): array { + return [ + 'model' => [ + new ShapeEnumValue('Model 1', 'model_1'), + new ShapeEnumValue('Model 2', 'model_2'), + new ShapeEnumValue('Model 3', 'model_3'), + ], + ]; + } + + public function getOptionalInputShapeDefaults(): array { + return [ + 'max_tokens' => 1234, + 'model' => 'model_2', + ]; + } + + public function getOptionalOutputShape(): array { + return []; + } + + public function getOutputShapeEnumValues(): array { + return []; + } + + public function getOptionalOutputShapeEnumValues(): array { + return []; + } + + public function process(?string $userId, array $input, callable $reportProgress): array { + if (isset($input['model']) && is_string($input['model'])) { + $model = $input['model']; + } else { + $model = 'unknown model'; + } + + if (!isset($input['input']) || !is_string($input['input'])) { + throw new RuntimeException('Invalid prompt'); + } + $prompt = $input['input']; + + $maxTokens = null; + if (isset($input['max_tokens']) && is_int($input['max_tokens'])) { + $maxTokens = $input['max_tokens']; + } + + return [ + 'output' => 'This is a fake summary: ',// . "\n\n- Prompt: " . $prompt . "\n- Model: " . $model . "\n- Maximum number of words: " . $maxTokens, + ]; + } +} |