-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
AI admin settings #39567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
AI admin settings #39567
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fc9780a
First pass at ai admin settings
marcelklehr 4e33d04
AI Admin settings: Implement mt settings, stt settings and tp settings
marcelklehr 8ec1926
fix(TextProcessing): Inject L10N\IFactory instead of IL10N
marcelklehr a840e8c
AI admin settings: Add save mechanism
marcelklehr 2a3ef10
AI admin settings: Use config values in AI feature managers
marcelklehr 2d29413
AI admin settings: Add a draggable icon in UI for translation provide…
marcelklehr aa74d6f
AI admin settings: Update composer autoloaders
marcelklehr f72f3f7
AI admin settings: strict_types
marcelklehr 4ec150c
AI admin settings: cs:fix
marcelklehr 112268a
AI admin settings: lint:fix
marcelklehr a193458
AI admin settings: lint:fix
marcelklehr be7487b
AI admin settings: lint:fix
marcelklehr ad3f353
Migration: Drop llm_tasks table and add textprocessing_tasks
marcelklehr a0eaed0
Fix typo
marcelklehr 3ca4428
Update apps/settings/src/components/AdminAI.vue
marcelklehr ff39466
Update apps/settings/src/components/AdminAI.vue
marcelklehr 830692c
Admin AI settings: Improve a11y of machine translation precendence
marcelklehr 7adb2ce
Admin AI settings: Use ContainerInterface instead of IServerContainer
marcelklehr 5776406
move long click handlers into methods
julien-nc 601679b
use DB type constants
julien-nc 0ace67c
polish AI admin settings UI
julien-nc a877865
fix wrong NcSelect event in AI admin settings
julien-nc 8d6a6e5
fix composer autoload files
julien-nc b13ca86
compile assets
julien-nc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net> | ||
| * | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
| namespace OCA\Settings\Controller; | ||
|
|
||
| use OCP\AppFramework\Controller; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\IConfig; | ||
| use OCP\IL10N; | ||
| use OCP\IRequest; | ||
| use OCP\IURLGenerator; | ||
| use OCP\IUserSession; | ||
| use OCP\Mail\IMailer; | ||
| use function GuzzleHttp\Promise\queue; | ||
|
|
||
| class AISettingsController extends Controller { | ||
|
|
||
| /** | ||
| * @param string $appName | ||
| * @param IRequest $request | ||
| * @param IConfig $config | ||
| */ | ||
| public function __construct( | ||
| $appName, | ||
| IRequest $request, | ||
| private IConfig $config, | ||
| ) { | ||
| parent::__construct($appName, $request); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the email settings | ||
| * | ||
| * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\ArtificialIntelligence) | ||
| * | ||
| * @param array $settings | ||
| * @return DataResponse | ||
| */ | ||
| public function update($settings) { | ||
| $keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.translation_provider_preferences']; | ||
| foreach ($keys as $key) { | ||
| if (!isset($settings[$key])) { | ||
| continue; | ||
| } | ||
| $this->config->setAppValue('core', $key, json_encode($settings[$key])); | ||
| } | ||
|
|
||
| return new DataResponse(); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
apps/settings/lib/Sections/Admin/ArtificialIntelligence.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| namespace OCA\Settings\Sections\Admin; | ||
|
|
||
| use OCP\IL10N; | ||
| use OCP\IURLGenerator; | ||
| use OCP\Settings\IIconSection; | ||
|
|
||
| class ArtificialIntelligence implements IIconSection { | ||
|
|
||
| /** @var IL10N */ | ||
| private $l; | ||
|
|
||
| /** @var IURLGenerator */ | ||
| private $urlGenerator; | ||
|
|
||
| public function __construct(IL10N $l, IURLGenerator $urlGenerator) { | ||
| $this->l = $l; | ||
| $this->urlGenerator = $urlGenerator; | ||
| } | ||
|
|
||
| public function getIcon(): string { | ||
| return $this->urlGenerator->imagePath('settings', 'ai.svg'); | ||
| } | ||
|
|
||
| public function getID(): string { | ||
| return 'ai'; | ||
| } | ||
|
|
||
| public function getName(): string { | ||
| return $this->l->t('Artificial Intelligence'); | ||
| } | ||
|
|
||
| public function getPriority(): int { | ||
| return 40; | ||
| } | ||
| } |
166 changes: 166 additions & 0 deletions
166
apps/settings/lib/Settings/Admin/ArtificialIntelligence.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net> | ||
| * | ||
| * @author Marcel Klehr <mklehr@gmx.net> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
| namespace OCA\Settings\Settings\Admin; | ||
|
|
||
| use OCP\AppFramework\Http\TemplateResponse; | ||
| use OCP\AppFramework\Services\IInitialState; | ||
| use OCP\IConfig; | ||
| use OCP\IL10N; | ||
| use OCP\Settings\IDelegatedSettings; | ||
| use OCP\SpeechToText\ISpeechToTextManager; | ||
| use OCP\TextProcessing\IManager; | ||
| use OCP\TextProcessing\IProvider; | ||
| use OCP\TextProcessing\ITaskType; | ||
| use OCP\Translation\ITranslationManager; | ||
| use Psr\Container\ContainerExceptionInterface; | ||
| use Psr\Container\ContainerInterface; | ||
| use Psr\Container\NotFoundExceptionInterface; | ||
|
|
||
| class ArtificialIntelligence implements IDelegatedSettings { | ||
| public function __construct( | ||
| private IConfig $config, | ||
| private IL10N $l, | ||
| private IInitialState $initialState, | ||
| private ITranslationManager $translationManager, | ||
| private ISpeechToTextManager $sttManager, | ||
| private IManager $textProcessingManager, | ||
| private ContainerInterface $container, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @return TemplateResponse | ||
| */ | ||
| public function getForm() { | ||
| $translationProviders = []; | ||
| $translationPreferences = []; | ||
| foreach ($this->translationManager->getProviders() as $provider) { | ||
| $translationProviders[] = [ | ||
| 'class' => $provider::class, | ||
| 'name' => $provider->getName(), | ||
| ]; | ||
| $translationPreferences[] = $provider::class; | ||
| } | ||
|
|
||
| $sttProviders = []; | ||
| foreach ($this->sttManager->getProviders() as $provider) { | ||
| $sttProviders[] = [ | ||
| 'class' => $provider::class, | ||
| 'name' => $provider->getName(), | ||
| ]; | ||
| } | ||
|
|
||
| $textProcessingProviders = []; | ||
| /** @var array<class-string<ITaskType>, class-string<IProvider>> $textProcessingSettings */ | ||
| $textProcessingSettings = []; | ||
| foreach ($this->textProcessingManager->getProviders() as $provider) { | ||
| $textProcessingProviders[] = [ | ||
| 'class' => $provider::class, | ||
| 'name' => $provider->getName(), | ||
| 'taskType' => $provider->getTaskType(), | ||
| ]; | ||
| $textProcessingSettings[$provider->getTaskType()] = $provider::class; | ||
| } | ||
| $textProcessingTaskTypes = []; | ||
| foreach ($textProcessingSettings as $taskTypeClass => $providerClass) { | ||
| /** @var ITaskType $taskType */ | ||
| try { | ||
| $taskType = $this->container->get($taskTypeClass); | ||
| } catch (NotFoundExceptionInterface $e) { | ||
| continue; | ||
| } catch (ContainerExceptionInterface $e) { | ||
| continue; | ||
| } | ||
| $textProcessingTaskTypes[] = [ | ||
| 'class' => $taskTypeClass, | ||
| 'name' => $taskType->getName(), | ||
| 'description' => $taskType->getDescription(), | ||
| ]; | ||
| } | ||
|
|
||
| $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); | ||
|
|
||
| $settings = [ | ||
| 'ai.stt_provider' => count($sttProviders) > 0 ? $sttProviders[0]['class'] : null, | ||
| 'ai.textprocessing_provider_preferences' => $textProcessingSettings, | ||
| 'ai.translation_provider_preferences' => $translationPreferences, | ||
| ]; | ||
| foreach ($settings as $key => $defaultValue) { | ||
| $value = $defaultValue; | ||
| $json = $this->config->getAppValue('core', $key, ''); | ||
| if ($json !== '') { | ||
| $value = json_decode($json, true); | ||
| switch($key) { | ||
| case 'ai.textprocessing_provider_preferences': | ||
| // fill $value with $defaultValue values | ||
| $value = array_merge($defaultValue, $value); | ||
| break; | ||
| case 'ai.translation_provider_preferences': | ||
| $value += array_diff($defaultValue, $value); // Add entries from $defaultValue that are not in $value to the end of $value | ||
Check noticeCode scanning / Psalm PossiblyInvalidArgument
Argument 1 of array_diff expects array<array-key, mixed>, but possibly different type array<class-string<OCP\TextProcessing\ITaskType>|int<0, max>, class-string<OCP\TextProcessing\IProvider<OCP\TextProcessing\ITaskType>>|class-string<OCP\Translation\ITranslationProvider>>|class-string<OCP\SpeechToText\ISpeechToTextProvider>|null provided
|
||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| $settings[$key] = $value; | ||
| } | ||
|
|
||
| $this->initialState->provideInitialState('ai-settings', $settings); | ||
|
|
||
| return new TemplateResponse('settings', 'settings/admin/ai'); | ||
| } | ||
|
|
||
| /** | ||
| * @return string the section ID, e.g. 'sharing' | ||
| */ | ||
| public function getSection() { | ||
| return 'ai'; | ||
| } | ||
|
|
||
| /** | ||
| * @return int whether the form should be rather on the top or bottom of | ||
| * the admin section. The forms are arranged in ascending order of the | ||
| * priority values. It is required to return a value between 0 and 100. | ||
| * | ||
| * E.g.: 70 | ||
| */ | ||
| public function getPriority() { | ||
| return 10; | ||
| } | ||
|
|
||
| public function getName(): ?string { | ||
| return $this->l->t('Artificial Intelligence'); | ||
| } | ||
|
|
||
| public function getAuthorizedAppConfig(): array { | ||
| return [ | ||
| 'core' => ['/ai..*/'], | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Psalm
PossiblyInvalidArgument