Skip to content

Commit 021e995

Browse files
authored
Merge pull request #172 from nextcloud/feat/use-server-tasktype
Feat: use server tasktype for changing tone if available
2 parents 1143efd + 958c5e7 commit 021e995

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

lib/AppInfo/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ public function register(IRegistrationContext $context): void {
100100
$context->registerTaskProcessingProvider(TopicsProvider::class);
101101
$context->registerTaskProcessingProvider(ContextWriteProvider::class);
102102
$context->registerTaskProcessingProvider(ReformulateProvider::class);
103-
$context->registerTaskProcessingTaskType(ChangeToneTaskType::class);
103+
if (!class_exists('OCP\\TaskProcessing\\TaskTypes\\TextToTextChangeTone')) {
104+
$context->registerTaskProcessingTaskType(ChangeToneTaskType::class);
105+
}
104106
$context->registerTaskProcessingProvider(ChangeToneProvider::class);
105107
if (class_exists('OCP\\TaskProcessing\\TaskTypes\\TextToTextChatWithTools')) {
106108
$context->registerTaskProcessingProvider(\OCA\OpenAi\TaskProcessing\TextToTextChatWithToolsProvider::class);

lib/TaskProcessing/ChangeToneProvider.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function getName(): string {
3636
}
3737

3838
public function getTaskTypeId(): string {
39+
if (class_exists('OCP\\TaskProcessing\\TaskTypes\\TextToTextChangeTone')) {
40+
return \OCP\TaskProcessing\TaskTypes\TextToTextChangeTone::ID;
41+
}
3942
return ChangeToneTaskType::ID;
4043
}
4144

@@ -46,7 +49,7 @@ public function getExpectedRuntime(): int {
4649
public function getInputShapeEnumValues(): array {
4750
$toneInputEnumValue = new ShapeEnumValue($this->l->t('Detect language'), 'detect_language');
4851
return [
49-
'tone_input' => [
52+
'tone' => [
5053
new ShapeEnumValue($this->l->t('Friendlier'), 'friendler'),
5154
new ShapeEnumValue($this->l->t('More formal'), 'more formal'),
5255
new ShapeEnumValue($this->l->t('Funnier'), 'funnier'),
@@ -58,7 +61,7 @@ public function getInputShapeEnumValues(): array {
5861

5962
public function getInputShapeDefaults(): array {
6063
return [
61-
'tone_input' => 'friendler',
64+
'tone' => 'friendler',
6265
];
6366
}
6467

@@ -112,7 +115,7 @@ public function process(?string $userId, array $input, callable $reportProgress)
112115
throw new RuntimeException('Invalid input text');
113116
}
114117
$textInput = $input['input'];
115-
$toneInput = $input['tone_input'];
118+
$toneInput = $input['tone'];
116119
$prompt = "Reformulate the following text in a $toneInput tone in its original language. Output only the reformulation. Here is the text:" . "\n\n" . $textInput . "\n\n" . 'Do not mention the used language in your reformulation. Here is your reformulation in the same language:';
117120

118121
$maxTokens = null;

lib/TaskProcessing/ChangeToneTaskType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getInputShape(): array {
4949
$this->l->t('Write a text that you want the assistant to rewrite in another tone.'),
5050
EShapeType::Text,
5151
),
52-
'tone_input' => new ShapeDescriptor(
52+
'tone' => new ShapeDescriptor(
5353
$this->l->t('Desired tone'),
5454
$this->l->t('In which tone should your text be rewritten?'),
5555
EShapeType::Enum,

tests/unit/Providers/OpenAiProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function testChangeToneProvider(): void {
259259

260260
$this->iClient->expects($this->once())->method('post')->with($url, $options)->willReturn($iResponse);
261261

262-
$result = $changeToneProvider->process(self::TEST_USER1, ['input' => $textInput, 'tone_input' => $toneInput ], fn () => null);
262+
$result = $changeToneProvider->process(self::TEST_USER1, ['input' => $textInput, 'tone' => $toneInput ], fn () => null);
263263
$this->assertEquals('This is a test response.', $result['output']);
264264

265265
// Check that token usage is logged properly

0 commit comments

Comments
 (0)