Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/testing/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'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',
Expand Down
1 change: 1 addition & 0 deletions apps/testing/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions apps/testing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -47,6 +48,7 @@ public function register(IRegistrationContext $context): void {
$context->registerTextToImageProvider(FakeText2ImageProvider::class);

$context->registerTaskProcessingProvider(FakeTextToTextProvider::class);
$context->registerTaskProcessingProvider(FakeTextToTextChatProvider::class);
$context->registerTaskProcessingProvider(FakeTextToTextSummaryProvider::class);
$context->registerTaskProcessingProvider(FakeTextToImageProvider::class);
$context->registerTaskProcessingProvider(FakeTranslateProvider::class);
Expand Down
103 changes: 103 additions & 0 deletions apps/testing/lib/TaskProcessing/FakeTextToTextChatProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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');
}

$formattedHistory = array_map(static function (string $historyItem) {

Check failure on line 91 in apps/testing/lib/TaskProcessing/FakeTextToTextChatProvider.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

apps/testing/lib/TaskProcessing/FakeTextToTextChatProvider.php:91:33: InvalidScalarArgument: Parameter 1 of closure passed to function array_map expects string, but OCP\Files\File|numeric|string provided (see https://psalm.dev/012)
return "\t" . $historyItem;
}, $input['history']);
$formattedHistory = implode("\n", $formattedHistory);

return [
'output' => 'This is a fake response message: '
. "\n\n- System prompt: " . $input['system_prompt']
. "\n- Input message: " . $input['input']
. "\n- Message history:\n" . $formattedHistory,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may cause confusion, perhaps simply count the number of history elements?

];
}
}
Loading