diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/settings/lib/Controller/AISettingsController.php | 2 | ||||
-rw-r--r-- | apps/settings/lib/Settings/Admin/ArtificialIntelligence.php | 23 | ||||
-rw-r--r-- | apps/settings/src/components/AdminAI.vue | 7 |
3 files changed, 28 insertions, 4 deletions
diff --git a/apps/settings/lib/Controller/AISettingsController.php b/apps/settings/lib/Controller/AISettingsController.php index 0586c652702..e08ec616e80 100644 --- a/apps/settings/lib/Controller/AISettingsController.php +++ b/apps/settings/lib/Controller/AISettingsController.php @@ -38,7 +38,7 @@ class AISettingsController extends Controller { */ #[AuthorizedAdminSetting(settings: ArtificialIntelligence::class)] public function update($settings) { - $keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider']; + $keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences','ai.taskprocessing_type_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider']; foreach ($keys as $key) { if (!isset($settings[$key])) { continue; diff --git a/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php b/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php index 4092acecab8..555d3c27313 100644 --- a/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php +++ b/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php @@ -24,6 +24,7 @@ use OCP\Translation\ITranslationProviderWithId; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; +use Psr\Log\LoggerInterface; class ArtificialIntelligence implements IDelegatedSettings { public function __construct( @@ -36,6 +37,7 @@ class ArtificialIntelligence implements IDelegatedSettings { private ContainerInterface $container, private \OCP\TextToImage\IManager $text2imageManager, private \OCP\TaskProcessing\IManager $taskProcessingManager, + private LoggerInterface $logger, ) { } @@ -113,12 +115,14 @@ class ArtificialIntelligence implements IDelegatedSettings { } } $taskProcessingTaskTypes = []; - foreach ($this->taskProcessingManager->getAvailableTaskTypes() as $taskTypeId => $taskTypeDefinition) { + $taskProcessingTypeSettings = []; + foreach ($this->taskProcessingManager->getAvailableTaskTypes(true) as $taskTypeId => $taskTypeDefinition) { $taskProcessingTaskTypes[] = [ 'id' => $taskTypeId, 'name' => $taskTypeDefinition['name'], 'description' => $taskTypeDefinition['description'], ]; + $taskProcessingTypeSettings[$taskTypeId] = true; } $this->initialState->provideInitialState('ai-stt-providers', $sttProviders); @@ -135,14 +139,29 @@ class ArtificialIntelligence implements IDelegatedSettings { 'ai.textprocessing_provider_preferences' => $textProcessingSettings, 'ai.text2image_provider' => count($text2imageProviders) > 0 ? $text2imageProviders[0]['id'] : null, 'ai.taskprocessing_provider_preferences' => $taskProcessingSettings, + 'ai.taskprocessing_type_preferences' => $taskProcessingTypeSettings, ]; foreach ($settings as $key => $defaultValue) { $value = $defaultValue; $json = $this->config->getAppValue('core', $key, ''); if ($json !== '') { - $value = json_decode($json, true); + try { + $value = json_decode($json, true, flags: JSON_THROW_ON_ERROR); + } catch (\JsonException $e) { + $this->logger->error('Failed to get settings. JSON Error in ' . $key, ['exception' => $e]); + if ($key === 'ai.taskprocessing_type_preferences') { + $value = []; + foreach ($taskProcessingTypeSettings as $taskTypeId => $taskTypeValue) { + $value[$taskTypeId] = false; + } + $settings[$key] = $value; + } + continue; + } + switch ($key) { case 'ai.taskprocessing_provider_preferences': + case 'ai.taskprocessing_type_preferences': case 'ai.textprocessing_provider_preferences': // fill $value with $defaultValue values $value = array_merge($defaultValue, $value); diff --git a/apps/settings/src/components/AdminAI.vue b/apps/settings/src/components/AdminAI.vue index 557b4e23067..b31e6fd9e7b 100644 --- a/apps/settings/src/components/AdminAI.vue +++ b/apps/settings/src/components/AdminAI.vue @@ -10,10 +10,15 @@ <div :key="type"> <h3>{{ t('settings', 'Task:') }} {{ type.name }}</h3> <p>{{ type.description }}</p> - <p> </p> + <NcCheckboxRadioSwitch v-model="settings['ai.taskprocessing_type_preferences'][type.id]" + type="switch" + @update:modelValue="saveChanges"> + {{ t('settings', 'Enable') }} + </NcCheckboxRadioSwitch> <NcSelect v-model="settings['ai.taskprocessing_provider_preferences'][type.id]" class="provider-select" :clearable="false" + :disabled="!settings['ai.taskprocessing_type_preferences'][type.id]" :options="taskProcessingProviders.filter(p => p.taskType === type.id).map(p => p.id)" @input="saveChanges"> <template #option="{label}"> |