AISettingsController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Settings\Controller;
  8. use OCA\Settings\Settings\Admin\ArtificialIntelligence;
  9. use OCP\AppFramework\Controller;
  10. use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
  11. use OCP\AppFramework\Http\DataResponse;
  12. use OCP\IConfig;
  13. use OCP\IRequest;
  14. class AISettingsController extends Controller {
  15. /**
  16. * @param string $appName
  17. * @param IRequest $request
  18. * @param IConfig $config
  19. */
  20. public function __construct(
  21. $appName,
  22. IRequest $request,
  23. private IConfig $config,
  24. ) {
  25. parent::__construct($appName, $request);
  26. }
  27. /**
  28. * Sets the email settings
  29. *
  30. * @param array $settings
  31. * @return DataResponse
  32. */
  33. #[AuthorizedAdminSetting(settings: ArtificialIntelligence::class)]
  34. public function update($settings) {
  35. $keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider'];
  36. foreach ($keys as $key) {
  37. if (!isset($settings[$key])) {
  38. continue;
  39. }
  40. $this->config->setAppValue('core', $key, json_encode($settings[$key]));
  41. }
  42. return new DataResponse();
  43. }
  44. }