Skip to content

Commit f6d0af3

Browse files
committed
Create task type if task type doesn't exist
Signed-off-by: Lukas Schaefer <[email protected]>
1 parent 9015d7b commit f6d0af3

File tree

4 files changed

+141
-80
lines changed

4 files changed

+141
-80
lines changed

lib/AppInfo/Application.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCA\OpenAi\TaskProcessing\ReformulateProvider;
1919
use OCA\OpenAi\TaskProcessing\SummaryProvider;
2020
use OCA\OpenAi\TaskProcessing\TextToImageProvider;
21+
use OCA\OpenAi\TaskProcessing\TextToSpeechProvider;
2122
use OCA\OpenAi\TaskProcessing\TextToTextChatProvider;
2223
use OCA\OpenAi\TaskProcessing\TextToTextProvider;
2324
use OCA\OpenAi\TaskProcessing\TopicsProvider;
@@ -118,9 +119,10 @@ public function register(IRegistrationContext $context): void {
118119
$context->registerTaskProcessingProvider(\OCA\OpenAi\TaskProcessing\ProofreadProvider::class);
119120
}
120121
}
121-
if (class_exists('OCP\\TaskProcessing\\TaskTypes\\TextToSpeech') && $this->appConfig->getValueString(Application::APP_ID, 'tts_provider_enabled', '1') === '1') {
122-
$context->registerTaskProcessingProvider(\OCA\OpenAi\TaskProcessing\TextToSpeechProvider::class);
122+
if (!class_exists('OCP\\TaskProcessing\\TaskTypes\\TextToSpeech')) {
123+
$context->registerTaskProcessingTaskType(\OCA\OpenAi\TaskProcessing\TextToSpeechTaskType::class);
123124
}
125+
$context->registerTaskProcessingProvider(TextToSpeechProvider::class);
124126
if ($this->appConfig->getValueString(Application::APP_ID, 't2i_provider_enabled', '1') === '1') {
125127
$context->registerTaskProcessingProvider(TextToImageProvider::class);
126128
}

lib/Service/OpenAiSettingsService.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class OpenAiSettingsService {
3939
'llm_provider_enabled' => 'boolean',
4040
't2i_provider_enabled' => 'boolean',
4141
'stt_provider_enabled' => 'boolean',
42-
'tts_provider_exists' => 'boolean',
4342
'tts_provider_enabled' => 'boolean',
4443
'chat_endpoint_enabled' => 'boolean',
4544
'basic_user' => 'string',
@@ -321,7 +320,6 @@ public function getAdminConfig(): array {
321320
'llm_provider_enabled' => $this->getLlmProviderEnabled(),
322321
't2i_provider_enabled' => $this->getT2iProviderEnabled(),
323322
'stt_provider_enabled' => $this->getSttProviderEnabled(),
324-
'tts_provider_exists' => $this->getTtsProviderExists(),
325323
'tts_provider_enabled' => $this->getTtsProviderEnabled(),
326324
'chat_endpoint_enabled' => $this->getChatEndpointEnabled(),
327325
'basic_user' => $this->getAdminBasicUser(),
@@ -399,14 +397,7 @@ public function getSttProviderEnabled(): bool {
399397
* @return bool
400398
*/
401399
public function getTtsProviderEnabled(): bool {
402-
return $this->getTtsProviderExists() && $this->appConfig->getValueString(Application::APP_ID, 'tts_provider_enabled', '1') === '1';
403-
}
404-
405-
/**
406-
* @return bool
407-
*/
408-
public function getTtsProviderExists(): bool {
409-
return class_exists('OCP\\TaskProcessing\\TaskTypes\\TextToSpeech');
400+
return $this->appConfig->getValueString(Application::APP_ID, 'tts_provider_enabled', '1') === '1';
410401
}
411402

412403
////////////////////////////////////////////
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\OpenAi\TaskProcessing;
11+
12+
use OCA\OpenAi\AppInfo\Application;
13+
use OCP\IL10N;
14+
use OCP\TaskProcessing\EShapeType;
15+
use OCP\TaskProcessing\ITaskType;
16+
use OCP\TaskProcessing\ShapeDescriptor;
17+
18+
class TextToSpeechTaskType implements ITaskType {
19+
public const ID = Application::APP_ID . ':text2speech';
20+
21+
public function __construct(
22+
private IL10N $l,
23+
) {
24+
}
25+
26+
/**
27+
* @inheritDoc
28+
*/
29+
public function getName(): string {
30+
return $this->l->t('Generate speech');
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
public function getDescription(): string {
37+
return $this->l->t('Generate speech from a transcript');
38+
}
39+
40+
/**
41+
* @return string
42+
*/
43+
public function getId(): string {
44+
return self::ID;
45+
}
46+
47+
/**
48+
* @return ShapeDescriptor[]
49+
*/
50+
public function getInputShape(): array {
51+
return [
52+
'input' => new ShapeDescriptor(
53+
$this->l->t('Prompt'),
54+
$this->l->t('Write transcript that you want the assistant to generate speech from'),
55+
EShapeType::Text,
56+
),
57+
];
58+
}
59+
60+
/**
61+
* @return ShapeDescriptor[]
62+
*/
63+
public function getOutputShape(): array {
64+
return [
65+
'speech' => new ShapeDescriptor(
66+
$this->l->t('Output speech'),
67+
$this->l->t('The generated speech'),
68+
EShapeType::Audio
69+
),
70+
];
71+
}
72+
}

src/components/AdminSettings.vue

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -388,72 +388,70 @@
388388
{{ t('integration_openai', 'No models to list') }}
389389
</NcNoteCard>
390390
</div>
391-
<div v-if="state.tts_provider_exists">
392-
<h2>
393-
{{ t('integration_openai', 'Text to speech') }}
394-
</h2>
395-
<div v-if="models"
396-
class="line line-select">
397-
<NcSelect
398-
v-model="selectedModel.tts"
399-
class="model-select"
400-
:clearable="state.default_tts_model_id !== DEFAULT_MODEL_ITEM.id"
401-
:options="formattedModels"
402-
:input-label="t('integration_openai', 'Default speech generation model to use')"
403-
:no-wrap="true"
404-
input-id="openai-tts-model-select"
405-
@input="onModelSelected('tts', $event)" />
406-
<a v-if="state.url === ''"
407-
:title="t('integration_openai', 'More information about OpenAI models')"
408-
href="https://beta.openai.com/docs/models"
409-
target="_blank">
410-
<NcButton type="tertiary" aria-label="openai-info">
411-
<template #icon>
412-
<HelpCircleIcon />
413-
</template>
414-
</NcButton>
415-
</a>
416-
<a v-else
417-
:title="t('integration_openai', 'More information about LocalAI models')"
418-
href="https://localai.io/model-compatibility/index.html"
419-
target="_blank">
420-
<NcButton type="tertiary" aria-label="localai-info">
421-
<template #icon>
422-
<HelpCircleIcon />
423-
</template>
424-
</NcButton>
425-
</a>
426-
</div>
427-
<NcNoteCard v-else type="info">
428-
{{ t('integration_openai', 'No models to list') }}
429-
</NcNoteCard>
430-
<div class="line column">
431-
<label>{{ t('integration_openai', 'TTS Voices') }}
432-
<NcButton
433-
:title="t('integration_openai', 'A list of voices supported by the endpoint you are using. Defaults to openai\'s list.')"
434-
type="tertiary"
435-
aria-label="voices-info">
436-
<template #icon>
437-
<HelpCircleIcon />
438-
</template>
439-
</NcButton>
440-
</label>
441-
<NcSelect v-model="state.tts_voices"
442-
:label-outside="true"
443-
multiple
444-
taggable
445-
style="width: 350px;"
446-
@input="onInput()" />
447-
</div>
391+
<h2>
392+
{{ t('integration_openai', 'Text to speech') }}
393+
</h2>
394+
<div v-if="models"
395+
class="line line-select">
448396
<NcSelect
449-
v-model="state.default_tts_voice"
397+
v-model="selectedModel.tts"
450398
class="model-select"
451-
:options="state.tts_voices"
452-
:input-label="t('integration_openai', 'Default voice to use')"
399+
:clearable="state.default_tts_model_id !== DEFAULT_MODEL_ITEM.id"
400+
:options="formattedModels"
401+
:input-label="t('integration_openai', 'Default speech generation model to use')"
453402
:no-wrap="true"
454-
input-id="openai-tts-voices-select"
403+
input-id="openai-tts-model-select"
404+
@input="onModelSelected('tts', $event)" />
405+
<a v-if="state.url === ''"
406+
:title="t('integration_openai', 'More information about OpenAI models')"
407+
href="https://beta.openai.com/docs/models"
408+
target="_blank">
409+
<NcButton type="tertiary" aria-label="openai-info">
410+
<template #icon>
411+
<HelpCircleIcon />
412+
</template>
413+
</NcButton>
414+
</a>
415+
<a v-else
416+
:title="t('integration_openai', 'More information about LocalAI models')"
417+
href="https://localai.io/model-compatibility/index.html"
418+
target="_blank">
419+
<NcButton type="tertiary" aria-label="localai-info">
420+
<template #icon>
421+
<HelpCircleIcon />
422+
</template>
423+
</NcButton>
424+
</a>
425+
</div>
426+
<NcNoteCard v-else type="info">
427+
{{ t('integration_openai', 'No models to list') }}
428+
</NcNoteCard>
429+
<div class="line column">
430+
<label>{{ t('integration_openai', 'TTS Voices') }}
431+
<NcButton
432+
:title="t('integration_openai', 'A list of voices supported by the endpoint you are using. Defaults to openai\'s list.')"
433+
type="tertiary"
434+
aria-label="voices-info">
435+
<template #icon>
436+
<HelpCircleIcon />
437+
</template>
438+
</NcButton>
439+
</label>
440+
<NcSelect v-model="state.tts_voices"
441+
:label-outside="true"
442+
multiple
443+
taggable
444+
style="width: 350px;"
455445
@input="onInput()" />
456446
</div>
447+
<NcSelect
448+
v-model="state.default_tts_voice"
449+
class="model-select"
450+
:options="state.tts_voices"
451+
:input-label="t('integration_openai', 'Default voice to use')"
452+
:no-wrap="true"
453+
input-id="openai-tts-voices-select"
454+
@input="onInput()" />
457455
<div>
458456
<h2>
459457
{{ t('integration_openai', 'Usage limits') }}
@@ -565,13 +563,11 @@
565563
@update:checked="onCheckboxChanged($event, 'stt_provider_enabled', false)">
566564
{{ t('integration_openai', 'Speech-to-text provider (to transcribe Talk recordings for example)') }}
567565
</NcCheckboxRadioSwitch>
568-
<div v-if="state.tts_provider_exists">
569-
<NcCheckboxRadioSwitch
570-
:checked="state.tts_provider_enabled"
571-
@update:checked="onCheckboxChanged($event, 'tts_provider_enabled', false)">
572-
{{ t('integration_openai', 'Text-to-speech provider') }}
573-
</NcCheckboxRadioSwitch>
574-
</div>
566+
<NcCheckboxRadioSwitch
567+
:checked="state.tts_provider_enabled"
568+
@update:checked="onCheckboxChanged($event, 'tts_provider_enabled', false)">
569+
{{ t('integration_openai', 'Text-to-speech provider') }}
570+
</NcCheckboxRadioSwitch>
575571
</div>
576572
</div>
577573
</div>

0 commit comments

Comments
 (0)