From 9dca5ae0e0b484e2dba360f47fa76d6f366d689a Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sat, 13 Jul 2024 15:07:22 +0200 Subject: feat(settings/admin/ai): Add Task Processing API settings Signed-off-by: Marcel Klehr --- .../lib/Settings/Admin/ArtificialIntelligence.php | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'apps/settings/lib/Settings/Admin/ArtificialIntelligence.php') diff --git a/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php b/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php index ac4badc2434..9a291243949 100644 --- a/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php +++ b/apps/settings/lib/Settings/Admin/ArtificialIntelligence.php @@ -35,6 +35,7 @@ class ArtificialIntelligence implements IDelegatedSettings { private IManager $textProcessingManager, private ContainerInterface $container, private \OCP\TextToImage\IManager $text2imageManager, + private \OCP\TaskProcessing\IManager $taskProcessingManager, ) { } @@ -98,17 +99,42 @@ class ArtificialIntelligence implements IDelegatedSettings { ]; } + $taskProcessingProviders = []; + /** @var array, string|class-string> $taskProcessingSettings */ + $taskProcessingSettings = []; + foreach ($this->taskProcessingManager->getProviders() as $provider) { + $taskProcessingProviders[] = [ + 'id' => $provider->getId(), + 'name' => $provider->getName(), + 'taskType' => $provider->getTaskTypeId(), + ]; + if (!isset($taskProcessingSettings[$provider->getTaskTypeId()])) { + $taskProcessingSettings[$provider->getTaskTypeId()] = $provider->getId(); + } + } + $taskProcessingTaskTypes = []; + foreach ($this->taskProcessingManager->getAvailableTaskTypes() as $taskTypeId => $taskTypeDefinition) { + $taskProcessingTaskTypes[] = [ + 'id' => $taskTypeId, + 'name' => $taskTypeDefinition['name'], + 'description' => $taskTypeDefinition['description'], + ]; + } + $this->initialState->provideInitialState('ai-stt-providers', $sttProviders); $this->initialState->provideInitialState('ai-translation-providers', $translationProviders); $this->initialState->provideInitialState('ai-text-processing-providers', $textProcessingProviders); $this->initialState->provideInitialState('ai-text-processing-task-types', $textProcessingTaskTypes); $this->initialState->provideInitialState('ai-text2image-providers', $text2imageProviders); + $this->initialState->provideInitialState('ai-task-processing-providers', $taskProcessingProviders); + $this->initialState->provideInitialState('ai-task-processing-task-types', $taskProcessingTaskTypes); $settings = [ 'ai.stt_provider' => count($sttProviders) > 0 ? $sttProviders[0]['class'] : null, - 'ai.textprocessing_provider_preferences' => $textProcessingSettings, 'ai.translation_provider_preferences' => $translationPreferences, + 'ai.textprocessing_provider_preferences' => $textProcessingSettings, 'ai.text2image_provider' => count($text2imageProviders) > 0 ? $text2imageProviders[0]['id'] : null, + 'ai.taskprocessing_provider_preferences' => $taskProcessingSettings, ]; foreach ($settings as $key => $defaultValue) { $value = $defaultValue; @@ -116,6 +142,7 @@ class ArtificialIntelligence implements IDelegatedSettings { if ($json !== '') { $value = json_decode($json, true); switch($key) { + case 'ai.taskprocessing_provider_preferences': case 'ai.textprocessing_provider_preferences': // fill $value with $defaultValue values $value = array_merge($defaultValue, $value); -- cgit v1.2.3