Skip to content
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

[stable27] fix: missing argument for TextProcessing Manager #39774

Closed
wants to merge 101 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
2e9dea2
Initial work on lm OCP API
marcelklehr Jun 15, 2023
457f1eb
LLM OCP API: Rework to use Task objects
marcelklehr Jun 15, 2023
d20ee42
LLM OCP API: Implement private backend code + add ILanguageModelTask
marcelklehr Jun 16, 2023
7031072
LLM OCP API: Add db migration
marcelklehr Jun 16, 2023
ed3672a
LLM OCP API: Add to RegistrationContext
marcelklehr Jun 16, 2023
33f3379
Fix Copyright
marcelklehr Jun 19, 2023
5807c43
LLM OCP API: ADd topics and headline tasks
marcelklehr Jun 20, 2023
236c32b
LLM OCP API: Implement ocs API
marcelklehr Jun 20, 2023
76a5db8
LLM OCP API: cs:fix
marcelklehr Jun 20, 2023
01db2cf
LLM OCP API: Make linters happy
marcelklehr Jun 20, 2023
dbd9420
LLM OCP API: Fix type errors
marcelklehr Jun 20, 2023
0024f0d
LLM OCP API: Add @since
marcelklehr Jun 20, 2023
02c78be
LLM OCP API: Fix static analysis
marcelklehr Jun 20, 2023
612af73
LLM OCP API: cs:fix
marcelklehr Jun 20, 2023
dd7eafa
LLM OCP API: Fix coding style and psalm
marcelklehr Jun 20, 2023
6320c68
Update lib/public/LanguageModel/ITopicsProvider.php
marcelklehr Jun 26, 2023
ecda18b
LLM OCP API: Add task definitions
marcelklehr Jun 26, 2023
1ac86d2
LLM OCP API: Commit autoloaders
marcelklehr Jun 26, 2023
4e3ca11
Update lib/public/AppFramework/Bootstrap/IRegistrationContext.php
marcelklehr Jun 27, 2023
4405027
Apply suggestions from code review
marcelklehr Jun 27, 2023
c8bbe8f
LLM OCP API: Type shenanigans for Visitor pattern
marcelklehr Jun 27, 2023
ddeaaea
LLM OCP API: strict types and copyright
marcelklehr Jun 27, 2023
d203e3a
OCP: Introduce OCP\Common\Exception\NotFoundException
marcelklehr Jun 27, 2023
fb9262e
LLM OCP API: Use OCP\Common\Exception\NotFoundException
marcelklehr Jun 27, 2023
e90dd4a
LLM OCP API: Fix copyright
marcelklehr Jun 27, 2023
44ce285
cs:fix
marcelklehr Jun 27, 2023
91325ef
Add tasks::last_updated column and vacate tasks after a week
marcelklehr Jun 28, 2023
2234497
TaskMapper#update: Use time factory
marcelklehr Jun 28, 2023
970d688
ILanguageModelManager: Add docblock description
marcelklehr Jun 28, 2023
c1085bf
ILanguageModelTask: Use php type checking along with psalm parameteri…
marcelklehr Jun 28, 2023
a462750
Add preliminary tests
marcelklehr Jun 28, 2023
d21f7bf
Fix tests
marcelklehr Jun 29, 2023
e717959
Make tests pass
marcelklehr Jun 29, 2023
09a8541
Add test for task cleanup
marcelklehr Jun 30, 2023
8197403
Fix LanguageModelManager#runTask: Insert task into db if it doesn't e…
marcelklehr Jun 30, 2023
4447d59
cs:fix
marcelklehr Jun 30, 2023
97a4a06
Apply suggestions from code review
marcelklehr Jul 6, 2023
ffedceb
LLM OCP API: Add identifier param
marcelklehr Jul 6, 2023
8f0618d
LLM OCP API: Fix psalm error
marcelklehr Jul 6, 2023
445b72a
LLM OCP API: Fix security issue
marcelklehr Jul 6, 2023
7320011
LLM OCP API: Fix psam errors
marcelklehr Jul 6, 2023
d9f2aaf
LLM OCP API: Fix psam error
marcelklehr Jul 6, 2023
8567315
LLM OCS API: s/tasks/tasktypes/
marcelklehr Jul 7, 2023
e312b2b
LLM OCS API: Add OpenAPI docs
marcelklehr Jul 7, 2023
22a93bf
Apply suggestions from code review
marcelklehr Jul 7, 2023
7a423e4
Update lib/public/LanguageModel/ILanguageModelProvider.php
marcelklehr Jul 7, 2023
9a36bb4
Update lib/public/LanguageModel/Events/TaskFailedEvent.php
marcelklehr Jul 7, 2023
b0cb5a4
LLM Migration: Return null if nothing changed
marcelklehr Jul 7, 2023
3350811
LLM OCP API: Add missing copyright and strict types
marcelklehr Jul 7, 2023
70e65ff
LLM OCP API: s/getAvailableTasks/getAvailableTaskClasses/
marcelklehr Jul 7, 2023
39bc710
LLM OCP API: Simplify LanguageModelManager#canHandleTask
marcelklehr Jul 7, 2023
ddb2726
LLM OCP API: Don't lose trace of wrapped exceptions
marcelklehr Jul 7, 2023
4ce77b9
LLM OCP API: Explain TaskBackgroundJob#setAllowParallelRuns
marcelklehr Jul 7, 2023
d578974
LLM OCP API: Simplify TaskBackgroundJob#run catch block
marcelklehr Jul 7, 2023
413a4f6
OCP\Common\NotFoundException: Add param type
marcelklehr Jul 7, 2023
5e86054
LLM OCP API: Avoid using OC in OCP
marcelklehr Jul 7, 2023
17351b6
LLM OCP API: Fix psalm issues
marcelklehr Jul 7, 2023
39d59a1
LLM OCP API: Fix OpenApi docs
marcelklehr Jul 7, 2023
15f08a7
LLM OCP API: Improve scheduleTask docblock
marcelklehr Jul 7, 2023
6b2687e
LLM OCP API: Change Tests to use EventDispatcher mock
marcelklehr Jul 7, 2023
a39e3c9
cs:fix
marcelklehr Jul 7, 2023
1ad0a29
LanguageModelApiController: Use jsonSerialize method to help psalm
marcelklehr Jul 7, 2023
8acb1dc
Since 27.1.0
marcelklehr Jul 7, 2023
fbd178a
Update core/Controller/LanguageModelApiController.php
marcelklehr Jul 11, 2023
6f5119c
Fix openapi docs
marcelklehr Jul 11, 2023
5d975b9
Update core/Controller/LanguageModelApiController.php
marcelklehr Jul 11, 2023
696a45d
Update core/Controller/LanguageModelApiController.php
marcelklehr Jul 11, 2023
cf2c42a
Massive refactoring: Turn LanguageModel OCP API into TextProcessing API
marcelklehr Jul 14, 2023
d8c44da
Fix psalm errors
marcelklehr Jul 14, 2023
87ac995
Fix psalm errors
marcelklehr Jul 14, 2023
322bb97
Apply suggestions from code review
marcelklehr Jul 17, 2023
4118baa
Update autoloaders
marcelklehr Jul 17, 2023
2d296ce
cs:fix
marcelklehr Jul 17, 2023
96ec6ff
Fix psalm errors
marcelklehr Jul 17, 2023
00e3fb1
Remove Task::factory method
marcelklehr Jul 19, 2023
cac5171
Fix tests: Adjust constructor signature
marcelklehr Jul 19, 2023
ad645c9
Fix tests: Adjust constructor signature
marcelklehr Jul 19, 2023
cc5818f
First pass at ai admin settings
marcelklehr Jul 24, 2023
43926a2
AI Admin settings: Implement mt settings, stt settings and tp settings
marcelklehr Jul 24, 2023
d4b2012
fix(TextProcessing): Inject L10N\IFactory instead of IL10N
marcelklehr Jul 24, 2023
674fd35
AI admin settings: Add save mechanism
marcelklehr Jul 24, 2023
7fd0b1b
AI admin settings: Use config values in AI feature managers
marcelklehr Jul 25, 2023
850a92e
AI admin settings: Add a draggable icon in UI for translation provide…
marcelklehr Jul 25, 2023
40d4da1
AI admin settings: Update composer autoloaders
marcelklehr Jul 25, 2023
6c8c047
AI admin settings: strict_types
marcelklehr Jul 25, 2023
832e0d3
AI admin settings: cs:fix
marcelklehr Jul 25, 2023
8507112
AI admin settings: lint:fix
marcelklehr Jul 25, 2023
9e6a864
AI admin settings: lint:fix
marcelklehr Jul 25, 2023
4b97ec7
AI admin settings: lint:fix
marcelklehr Jul 25, 2023
50adc8c
Migration: Drop llm_tasks table and add textprocessing_tasks
marcelklehr Jul 28, 2023
f4160e0
Fix typo
marcelklehr Jul 28, 2023
d13ceb3
Update apps/settings/src/components/AdminAI.vue
marcelklehr Jul 28, 2023
dbcfef1
Update apps/settings/src/components/AdminAI.vue
marcelklehr Jul 28, 2023
3d9a588
Admin AI settings: Improve a11y of machine translation precendence
marcelklehr Jul 28, 2023
8dee7d0
Admin AI settings: Use ContainerInterface instead of IServerContainer
marcelklehr Jul 28, 2023
52a1748
move long click handlers into methods
julien-nc Aug 1, 2023
f95cf63
use DB type constants
julien-nc Aug 1, 2023
67fa798
polish AI admin settings UI
julien-nc Aug 1, 2023
0029171
fix wrong NcSelect event in AI admin settings
julien-nc Aug 1, 2023
2d9a064
fix composer autoload files
julien-nc Aug 1, 2023
4bae251
fix: missing argument for TextProcessing Manager
kesselb Aug 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/settings/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<settings>
<admin>OCA\Settings\Settings\Admin\Mail</admin>
<admin>OCA\Settings\Settings\Admin\Overview</admin>
<admin>OCA\Settings\Settings\Admin\ArtificialIntelligence</admin>
<admin>OCA\Settings\Settings\Admin\Server</admin>
<admin>OCA\Settings\Settings\Admin\Sharing</admin>
<admin>OCA\Settings\Settings\Admin\Security</admin>
Expand All @@ -27,6 +28,7 @@
<admin-section>OCA\Settings\Sections\Admin\Delegation</admin-section>
<admin-section>OCA\Settings\Sections\Admin\Groupware</admin-section>
<admin-section>OCA\Settings\Sections\Admin\Overview</admin-section>
<admin-section>OCA\Settings\Sections\Admin\ArtificialIntelligence</admin-section>
<admin-section>OCA\Settings\Sections\Admin\Security</admin-section>
<admin-section>OCA\Settings\Sections\Admin\Server</admin-section>
<admin-section>OCA\Settings\Sections\Admin\Sharing</admin-section>
Expand Down
1 change: 1 addition & 0 deletions apps/settings/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST' , 'root' => ''],
['name' => 'TwoFactorSettings#index', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'GET' , 'root' => ''],
['name' => 'TwoFactorSettings#update', 'url' => '/settings/api/admin/twofactorauth', 'verb' => 'PUT' , 'root' => ''],
['name' => 'AISettings#update', 'url' => '/settings/api/admin/ai', 'verb' => 'PUT' , 'root' => ''],

['name' => 'Help#help', 'url' => '/settings/help/{mode}', 'verb' => 'GET', 'defaults' => ['mode' => ''] , 'root' => ''],

Expand Down
3 changes: 3 additions & 0 deletions apps/settings/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'OCA\\Settings\\Activity\\Setting' => $baseDir . '/../lib/Activity/Setting.php',
'OCA\\Settings\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Settings\\BackgroundJobs\\VerifyUserData' => $baseDir . '/../lib/BackgroundJobs/VerifyUserData.php',
'OCA\\Settings\\Controller\\AISettingsController' => $baseDir . '/../lib/Controller/AISettingsController.php',
'OCA\\Settings\\Controller\\AdminSettingsController' => $baseDir . '/../lib/Controller/AdminSettingsController.php',
'OCA\\Settings\\Controller\\AppSettingsController' => $baseDir . '/../lib/Controller/AppSettingsController.php',
'OCA\\Settings\\Controller\\AuthSettingsController' => $baseDir . '/../lib/Controller/AuthSettingsController.php',
Expand All @@ -42,6 +43,7 @@
'OCA\\Settings\\Search\\AppSearch' => $baseDir . '/../lib/Search/AppSearch.php',
'OCA\\Settings\\Search\\SectionSearch' => $baseDir . '/../lib/Search/SectionSearch.php',
'OCA\\Settings\\Sections\\Admin\\Additional' => $baseDir . '/../lib/Sections/Admin/Additional.php',
'OCA\\Settings\\Sections\\Admin\\ArtificialIntelligence' => $baseDir . '/../lib/Sections/Admin/ArtificialIntelligence.php',
'OCA\\Settings\\Sections\\Admin\\Delegation' => $baseDir . '/../lib/Sections/Admin/Delegation.php',
'OCA\\Settings\\Sections\\Admin\\Groupware' => $baseDir . '/../lib/Sections/Admin/Groupware.php',
'OCA\\Settings\\Sections\\Admin\\Overview' => $baseDir . '/../lib/Sections/Admin/Overview.php',
Expand All @@ -56,6 +58,7 @@
'OCA\\Settings\\Service\\AuthorizedGroupService' => $baseDir . '/../lib/Service/AuthorizedGroupService.php',
'OCA\\Settings\\Service\\NotFoundException' => $baseDir . '/../lib/Service/NotFoundException.php',
'OCA\\Settings\\Service\\ServiceException' => $baseDir . '/../lib/Service/ServiceException.php',
'OCA\\Settings\\Settings\\Admin\\ArtificialIntelligence' => $baseDir . '/../lib/Settings/Admin/ArtificialIntelligence.php',
'OCA\\Settings\\Settings\\Admin\\Delegation' => $baseDir . '/../lib/Settings/Admin/Delegation.php',
'OCA\\Settings\\Settings\\Admin\\Mail' => $baseDir . '/../lib/Settings/Admin/Mail.php',
'OCA\\Settings\\Settings\\Admin\\Overview' => $baseDir . '/../lib/Settings/Admin/Overview.php',
Expand Down
3 changes: 3 additions & 0 deletions apps/settings/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\Activity\\Setting' => __DIR__ . '/..' . '/../lib/Activity/Setting.php',
'OCA\\Settings\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Settings\\BackgroundJobs\\VerifyUserData' => __DIR__ . '/..' . '/../lib/BackgroundJobs/VerifyUserData.php',
'OCA\\Settings\\Controller\\AISettingsController' => __DIR__ . '/..' . '/../lib/Controller/AISettingsController.php',
'OCA\\Settings\\Controller\\AdminSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AdminSettingsController.php',
'OCA\\Settings\\Controller\\AppSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AppSettingsController.php',
'OCA\\Settings\\Controller\\AuthSettingsController' => __DIR__ . '/..' . '/../lib/Controller/AuthSettingsController.php',
Expand All @@ -57,6 +58,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\Search\\AppSearch' => __DIR__ . '/..' . '/../lib/Search/AppSearch.php',
'OCA\\Settings\\Search\\SectionSearch' => __DIR__ . '/..' . '/../lib/Search/SectionSearch.php',
'OCA\\Settings\\Sections\\Admin\\Additional' => __DIR__ . '/..' . '/../lib/Sections/Admin/Additional.php',
'OCA\\Settings\\Sections\\Admin\\ArtificialIntelligence' => __DIR__ . '/..' . '/../lib/Sections/Admin/ArtificialIntelligence.php',
'OCA\\Settings\\Sections\\Admin\\Delegation' => __DIR__ . '/..' . '/../lib/Sections/Admin/Delegation.php',
'OCA\\Settings\\Sections\\Admin\\Groupware' => __DIR__ . '/..' . '/../lib/Sections/Admin/Groupware.php',
'OCA\\Settings\\Sections\\Admin\\Overview' => __DIR__ . '/..' . '/../lib/Sections/Admin/Overview.php',
Expand All @@ -71,6 +73,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\Service\\AuthorizedGroupService' => __DIR__ . '/..' . '/../lib/Service/AuthorizedGroupService.php',
'OCA\\Settings\\Service\\NotFoundException' => __DIR__ . '/..' . '/../lib/Service/NotFoundException.php',
'OCA\\Settings\\Service\\ServiceException' => __DIR__ . '/..' . '/../lib/Service/ServiceException.php',
'OCA\\Settings\\Settings\\Admin\\ArtificialIntelligence' => __DIR__ . '/..' . '/../lib/Settings/Admin/ArtificialIntelligence.php',
'OCA\\Settings\\Settings\\Admin\\Delegation' => __DIR__ . '/..' . '/../lib/Settings/Admin/Delegation.php',
'OCA\\Settings\\Settings\\Admin\\Mail' => __DIR__ . '/..' . '/../lib/Settings/Admin/Mail.php',
'OCA\\Settings\\Settings\\Admin\\Overview' => __DIR__ . '/..' . '/../lib/Settings/Admin/Overview.php',
Expand Down
1 change: 1 addition & 0 deletions apps/settings/img/ai.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 70 additions & 0 deletions apps/settings/lib/Controller/AISettingsController.php
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 apps/settings/lib/Sections/Admin/ArtificialIntelligence.php
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 apps/settings/lib/Settings/Admin/ArtificialIntelligence.php
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);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument Note

Argument 1 of array_merge 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;
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 notice

Code scanning / Psalm

PossiblyInvalidArgument Note

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..*/'],
];
}
}
2 changes: 1 addition & 1 deletion apps/settings/src/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ window.addEventListener('DOMContentLoaded', () => {
OC.SetupChecks.checkSetup(),
OC.SetupChecks.checkGeneric(),
OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/NotoSans-Regular-latin.woff2'), OC.theme.docPlaceholderUrl),
OC.SetupChecks.checkDataProtected()
OC.SetupChecks.checkDataProtected(),
).then((check1, check2, check3, check4, check5, check6, check7, check8, check9, check10, check11) => {
const messages = [].concat(check1, check2, check3, check4, check5, check6, check7, check8, check9, check10, check11)
const $el = $('#postsetupchecks')
Expand Down
Loading
Loading