diff options
author | Julien Veyssier <julien-nc@posteo.net> | 2024-10-24 12:18:03 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-10-24 10:53:43 +0000 |
commit | 70db4f51db3100fec4391af1c1599ac102ded443 (patch) | |
tree | a831d12b6625f4a141b9b1832b3adb286daca266 /lib | |
parent | 67437d03252a09268a8293758429011c3af6ee7c (diff) | |
download | nextcloud-server-70db4f51db3100fec4391af1c1599ac102ded443.tar.gz nextcloud-server-70db4f51db3100fec4391af1c1599ac102ded443.zip |
feat(textprocessing): factorize taskProcessingCompatibleTaskTypesbackport/48863/stable30
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/TextProcessing/Manager.php | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index 617f57c6ba2..17778d31091 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -44,6 +44,13 @@ class Manager implements IManager { /** @var ?IProvider[] */ private ?array $providers = null; + private static array $taskProcessingCompatibleTaskTypes = [ + FreePromptTaskType::class => TextToText::ID, + HeadlineTaskType::class => TextToTextHeadline::ID, + SummaryTaskType::class => TextToTextSummary::ID, + TopicsTaskType::class => TextToTextTopics::ID, + ]; + public function __construct( private IServerContainer $serverContainer, private Coordinator $coordinator, @@ -84,13 +91,7 @@ class Manager implements IManager { public function hasProviders(): bool { // check if task processing equivalent types are available $taskTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); - $taskProcessingCompatibleTaskTypes = [ - FreePromptTaskType::class => TextToText::ID, - HeadlineTaskType::class => TextToTextHeadline::ID, - SummaryTaskType::class => TextToTextSummary::ID, - TopicsTaskType::class => TextToTextTopics::ID, - ]; - foreach ($taskProcessingCompatibleTaskTypes as $textTaskTypeClass => $taskTaskTypeId) { + foreach (self::$taskProcessingCompatibleTaskTypes as $textTaskTypeClass => $taskTaskTypeId) { if (isset($taskTaskTypes[$taskTaskTypeId])) { return true; } @@ -114,13 +115,7 @@ class Manager implements IManager { // check if task processing equivalent types are available $taskTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); - $taskProcessingCompatibleTaskTypes = [ - FreePromptTaskType::class => TextToText::ID, - HeadlineTaskType::class => TextToTextHeadline::ID, - SummaryTaskType::class => TextToTextSummary::ID, - TopicsTaskType::class => TextToTextTopics::ID, - ]; - foreach ($taskProcessingCompatibleTaskTypes as $textTaskTypeClass => $taskTaskTypeId) { + foreach (self::$taskProcessingCompatibleTaskTypes as $textTaskTypeClass => $taskTaskTypeId) { if (isset($taskTaskTypes[$taskTaskTypeId])) { $tasks[$textTaskTypeClass] = true; } @@ -139,15 +134,9 @@ class Manager implements IManager { public function runTask(OCPTask $task): string { // try to run a task processing task if possible $taskTypeClass = $task->getType(); - $taskProcessingCompatibleTaskTypes = [ - FreePromptTaskType::class => TextToText::ID, - HeadlineTaskType::class => TextToTextHeadline::ID, - SummaryTaskType::class => TextToTextSummary::ID, - TopicsTaskType::class => TextToTextTopics::ID, - ]; - if (isset($taskProcessingCompatibleTaskTypes[$taskTypeClass]) && isset($this->taskProcessingManager->getAvailableTaskTypes()[$taskProcessingCompatibleTaskTypes[$taskTypeClass]])) { + if (isset(self::$taskProcessingCompatibleTaskTypes[$taskTypeClass]) && isset($this->taskProcessingManager->getAvailableTaskTypes()[self::$taskProcessingCompatibleTaskTypes[$taskTypeClass]])) { try { - $taskProcessingTaskTypeId = $taskProcessingCompatibleTaskTypes[$taskTypeClass]; + $taskProcessingTaskTypeId = self::$taskProcessingCompatibleTaskTypes[$taskTypeClass]; $taskProcessingTask = new \OCP\TaskProcessing\Task( $taskProcessingTaskTypeId, ['input' => $task->getInput()], |