mirror of
https://github.com/nextcloud/server.git
synced 2026-04-24 15:53:36 -04:00
feat(testing): add core:text2text:chat fake provider in the testing app
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
parent
c4da3cca34
commit
9f78ccbfd0
4 changed files with 102 additions and 0 deletions
|
|
@ -26,6 +26,7 @@ return array(
|
|||
'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => $baseDir . '/../lib/Settings/DeclarativeSettingsForm.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => $baseDir . '/../lib/TaskProcessing/FakeContextWriteProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToImageProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextChatProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextChatProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextSummaryProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextSummaryProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTranscribeProvider' => $baseDir . '/../lib/TaskProcessing/FakeTranscribeProvider.php',
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class ComposerStaticInitTesting
|
|||
'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => __DIR__ . '/..' . '/../lib/Settings/DeclarativeSettingsForm.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeContextWriteProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToImageProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextChatProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextChatProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTextToTextSummaryProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextSummaryProvider.php',
|
||||
'OCA\\Testing\\TaskProcessing\\FakeTranscribeProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTranscribeProvider.php',
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use OCA\Testing\Provider\FakeTranslationProvider;
|
|||
use OCA\Testing\Settings\DeclarativeSettingsForm;
|
||||
use OCA\Testing\TaskProcessing\FakeContextWriteProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeTextToImageProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeTextToTextChatProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeTextToTextProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeTextToTextSummaryProvider;
|
||||
use OCA\Testing\TaskProcessing\FakeTranscribeProvider;
|
||||
|
|
@ -47,6 +48,7 @@ class Application extends App implements IBootstrap {
|
|||
$context->registerTextToImageProvider(FakeText2ImageProvider::class);
|
||||
|
||||
$context->registerTaskProcessingProvider(FakeTextToTextProvider::class);
|
||||
$context->registerTaskProcessingProvider(FakeTextToTextChatProvider::class);
|
||||
$context->registerTaskProcessingProvider(FakeTextToTextSummaryProvider::class);
|
||||
$context->registerTaskProcessingProvider(FakeTextToImageProvider::class);
|
||||
$context->registerTaskProcessingProvider(FakeTranslateProvider::class);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\Testing\TaskProcessing;
|
||||
|
||||
use OCA\Testing\AppInfo\Application;
|
||||
use OCP\AppFramework\Services\IAppConfig;
|
||||
use OCP\TaskProcessing\Exception\ProcessingException;
|
||||
use OCP\TaskProcessing\ISynchronousProvider;
|
||||
use OCP\TaskProcessing\TaskTypes\TextToTextChat;
|
||||
use RuntimeException;
|
||||
|
||||
class FakeTextToTextChatProvider implements ISynchronousProvider {
|
||||
|
||||
public function __construct(
|
||||
protected IAppConfig $appConfig,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): string {
|
||||
return Application::APP_ID . '-text2textchat';
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return 'Fake text2text chat task processing provider';
|
||||
}
|
||||
|
||||
public function getTaskTypeId(): string {
|
||||
return TextToTextChat::ID;
|
||||
}
|
||||
|
||||
public function getExpectedRuntime(): int {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getInputShapeEnumValues(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getInputShapeDefaults(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOptionalInputShape(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOptionalInputShapeEnumValues(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getOptionalInputShapeDefaults(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
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 ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
|
||||
throw new ProcessingException('Failing as set by AppConfig');
|
||||
}
|
||||
|
||||
if (!isset($input['system_prompt']) || !is_string($input['system_prompt'])) {
|
||||
throw new RuntimeException('Invalid system prompt');
|
||||
}
|
||||
|
||||
if (!isset($input['input']) || !is_string($input['input'])) {
|
||||
throw new RuntimeException('Invalid input message');
|
||||
}
|
||||
|
||||
if (!isset($input['history']) || !is_array($input['history'])) {
|
||||
throw new RuntimeException('Invalid message history');
|
||||
}
|
||||
|
||||
return [
|
||||
'output' => 'This is a fake response message: '
|
||||
. "\n\n- System prompt: " . $input['system_prompt']
|
||||
. "\n- Input message: " . $input['input']
|
||||
. "\n- Message history:\n" . count($input['history']) . ' messages',
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue