diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-07-13 15:07:22 +0200 |
---|---|---|
committer | Julien Veyssier <julien-nc@posteo.net> | 2024-07-17 15:24:19 +0200 |
commit | 9dca5ae0e0b484e2dba360f47fa76d6f366d689a (patch) | |
tree | 35ebabd3c20f8087fb94ed1676b7158e79bbfc8d /lib/private/TaskProcessing | |
parent | e4368f6a9f37985ab4f5911b4ca50dba8109827e (diff) | |
download | nextcloud-server-9dca5ae0e0b484e2dba360f47fa76d6f366d689a.tar.gz nextcloud-server-9dca5ae0e0b484e2dba360f47fa76d6f366d689a.zip |
feat(settings/admin/ai): Add Task Processing API settings
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'lib/private/TaskProcessing')
-rw-r--r-- | lib/private/TaskProcessing/Manager.php | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index f0d1d4ba51a..834ca488033 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -24,6 +24,7 @@ use OCP\Files\IAppData; use OCP\Files\IRootFolder; use OCP\Files\NotPermittedException; use OCP\Files\SimpleFS\ISimpleFile; +use OCP\IConfig; use OCP\IL10N; use OCP\IServerContainer; use OCP\L10N\IFactory; @@ -66,6 +67,7 @@ class Manager implements IManager { private IAppData $appData; public function __construct( + private IConfig $config, private Coordinator $coordinator, private IServerContainer $serverContainer, private LoggerInterface $logger, @@ -497,11 +499,23 @@ class Manager implements IManager { } public function getPreferredProvider(string $taskType) { - $providers = $this->getProviders(); - foreach ($providers as $provider) { - if ($provider->getTaskTypeId() === $taskType) { - return $provider; + try { + $preferences = json_decode($this->config->getAppValue('core', 'ai.taskprocessing_provider_preferences', 'null'), associative: true, flags: JSON_THROW_ON_ERROR); + if (isset($preferences[$taskType])) { + $providers = $this->getProviders(); + $provider = current(array_values(array_filter($providers, fn ($provider) => $provider->getId() === $preferences[$taskType]))); + if ($provider !== false) { + return $provider; + } + } + // By default, use the first available provider + foreach ($providers as $provider) { + if ($provider->getTaskTypeId() === $taskType) { + return $provider; + } } + } catch (\JsonException $e) { + $this->logger->warning('Failed to parse provider preferences while getting preferred provider for task type ' . $taskType, ['exception' => $e]); } throw new \OCP\TaskProcessing\Exception\Exception('No matching provider found'); } |