Skip to content

Commit e0cadec

Browse files
Merge pull request #56618 from nextcloud/enh/noid/testing-chat-provider
Add core:text2text:chat fake provider in the testing app
2 parents c4da3cc + 9f78ccb commit e0cadec

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

apps/testing/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => $baseDir . '/../lib/Settings/DeclarativeSettingsForm.php',
2727
'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => $baseDir . '/../lib/TaskProcessing/FakeContextWriteProvider.php',
2828
'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToImageProvider.php',
29+
'OCA\\Testing\\TaskProcessing\\FakeTextToTextChatProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextChatProvider.php',
2930
'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextProvider.php',
3031
'OCA\\Testing\\TaskProcessing\\FakeTextToTextSummaryProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextSummaryProvider.php',
3132
'OCA\\Testing\\TaskProcessing\\FakeTranscribeProvider' => $baseDir . '/../lib/TaskProcessing/FakeTranscribeProvider.php',

apps/testing/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ComposerStaticInitTesting
4141
'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => __DIR__ . '/..' . '/../lib/Settings/DeclarativeSettingsForm.php',
4242
'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeContextWriteProvider.php',
4343
'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToImageProvider.php',
44+
'OCA\\Testing\\TaskProcessing\\FakeTextToTextChatProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextChatProvider.php',
4445
'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextProvider.php',
4546
'OCA\\Testing\\TaskProcessing\\FakeTextToTextSummaryProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextSummaryProvider.php',
4647
'OCA\\Testing\\TaskProcessing\\FakeTranscribeProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTranscribeProvider.php',

apps/testing/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use OCA\Testing\Settings\DeclarativeSettingsForm;
2121
use OCA\Testing\TaskProcessing\FakeContextWriteProvider;
2222
use OCA\Testing\TaskProcessing\FakeTextToImageProvider;
23+
use OCA\Testing\TaskProcessing\FakeTextToTextChatProvider;
2324
use OCA\Testing\TaskProcessing\FakeTextToTextProvider;
2425
use OCA\Testing\TaskProcessing\FakeTextToTextSummaryProvider;
2526
use OCA\Testing\TaskProcessing\FakeTranscribeProvider;
@@ -47,6 +48,7 @@ public function register(IRegistrationContext $context): void {
4748
$context->registerTextToImageProvider(FakeText2ImageProvider::class);
4849

4950
$context->registerTaskProcessingProvider(FakeTextToTextProvider::class);
51+
$context->registerTaskProcessingProvider(FakeTextToTextChatProvider::class);
5052
$context->registerTaskProcessingProvider(FakeTextToTextSummaryProvider::class);
5153
$context->registerTaskProcessingProvider(FakeTextToImageProvider::class);
5254
$context->registerTaskProcessingProvider(FakeTranslateProvider::class);
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OCA\Testing\TaskProcessing;
11+
12+
use OCA\Testing\AppInfo\Application;
13+
use OCP\AppFramework\Services\IAppConfig;
14+
use OCP\TaskProcessing\Exception\ProcessingException;
15+
use OCP\TaskProcessing\ISynchronousProvider;
16+
use OCP\TaskProcessing\TaskTypes\TextToTextChat;
17+
use RuntimeException;
18+
19+
class FakeTextToTextChatProvider implements ISynchronousProvider {
20+
21+
public function __construct(
22+
protected IAppConfig $appConfig,
23+
) {
24+
}
25+
26+
public function getId(): string {
27+
return Application::APP_ID . '-text2textchat';
28+
}
29+
30+
public function getName(): string {
31+
return 'Fake text2text chat task processing provider';
32+
}
33+
34+
public function getTaskTypeId(): string {
35+
return TextToTextChat::ID;
36+
}
37+
38+
public function getExpectedRuntime(): int {
39+
return 1;
40+
}
41+
42+
public function getInputShapeEnumValues(): array {
43+
return [];
44+
}
45+
46+
public function getInputShapeDefaults(): array {
47+
return [];
48+
}
49+
50+
public function getOptionalInputShape(): array {
51+
return [];
52+
}
53+
54+
public function getOptionalInputShapeEnumValues(): array {
55+
return [];
56+
}
57+
58+
public function getOptionalInputShapeDefaults(): array {
59+
return [];
60+
}
61+
62+
public function getOptionalOutputShape(): array {
63+
return [];
64+
}
65+
66+
public function getOutputShapeEnumValues(): array {
67+
return [];
68+
}
69+
70+
public function getOptionalOutputShapeEnumValues(): array {
71+
return [];
72+
}
73+
74+
public function process(?string $userId, array $input, callable $reportProgress): array {
75+
if ($this->appConfig->getAppValueBool('fail-' . $this->getId())) {
76+
throw new ProcessingException('Failing as set by AppConfig');
77+
}
78+
79+
if (!isset($input['system_prompt']) || !is_string($input['system_prompt'])) {
80+
throw new RuntimeException('Invalid system prompt');
81+
}
82+
83+
if (!isset($input['input']) || !is_string($input['input'])) {
84+
throw new RuntimeException('Invalid input message');
85+
}
86+
87+
if (!isset($input['history']) || !is_array($input['history'])) {
88+
throw new RuntimeException('Invalid message history');
89+
}
90+
91+
return [
92+
'output' => 'This is a fake response message: '
93+
. "\n\n- System prompt: " . $input['system_prompt']
94+
. "\n- Input message: " . $input['input']
95+
. "\n- Message history:\n" . count($input['history']) . ' messages',
96+
];
97+
}
98+
}

0 commit comments

Comments
 (0)