diff options
author | Marcel Klehr <mklehr@gmx.net> | 2023-07-25 14:17:57 +0200 |
---|---|---|
committer | Julien Veyssier <julien-nc@posteo.net> | 2023-08-02 12:37:35 +0200 |
commit | 2a3ef102f7527041609ad96bc59d6b21f42980d4 (patch) | |
tree | 2ca08e6288ff471de9f0c7664e990c25dd81c725 /lib/private/TextProcessing | |
parent | a840e8c6e5a0d7b7c3a371776fd395976b2c2fdf (diff) | |
download | nextcloud-server-2a3ef102f7527041609ad96bc59d6b21f42980d4.tar.gz nextcloud-server-2a3ef102f7527041609ad96bc59d6b21f42980d4.zip |
AI admin settings: Use config values in AI feature managers
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/private/TextProcessing')
-rw-r--r-- | lib/private/TextProcessing/Manager.php | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index f52482bbb32..05e046a0049 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -27,6 +27,7 @@ namespace OC\TextProcessing; use OC\AppFramework\Bootstrap\Coordinator; use OC\TextProcessing\Db\Task as DbTask; +use OCP\IConfig; use OCP\TextProcessing\Task as OCPTask; use OC\TextProcessing\Db\TaskMapper; use OCP\AppFramework\Db\DoesNotExistException; @@ -52,6 +53,7 @@ class Manager implements IManager { private LoggerInterface $logger, private IJobList $jobList, private TaskMapper $taskMapper, + private IConfig $config, ) { } @@ -111,7 +113,21 @@ class Manager implements IManager { if (!$this->canHandleTask($task)) { throw new PreConditionNotMetException('No text processing provider is installed that can handle this task'); } - foreach ($this->getProviders() as $provider) { + $providers = $this->getProviders(); + $json = $this->config->getAppValue('core', 'ai.textprocessing_provider_preferences', ''); + if ($json !== '') { + $preferences = json_decode($json, true); + if (isset($preferences[$task->getType()])) { + // If a preference for this task type is set, move the preferred provider to the start + $provider = current(array_filter($providers, fn ($provider) => $provider::class === $preferences[$task->getType()])); + if ($provider !== false) { + $providers = array_filter($providers, fn ($p) => $p !== $provider); + array_unshift($providers, $provider); + } + } + } + + foreach ($providers as $provider) { if (!$task->canUseProvider($provider)) { continue; } |