aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulien Veyssier <julien-nc@posteo.net>2024-10-24 12:18:03 +0200
committerJulien Veyssier <julien-nc@posteo.net>2024-10-24 12:34:33 +0200
commit5362486ca910a8fb8c6a7756b6d778a2440accd6 (patch)
tree51edc0a054232d5a12a03e3edc63d2fc72cb8088 /lib
parent54cebc213695ca07e7fdd830d2ba99e8526991b3 (diff)
downloadnextcloud-server-5362486ca910a8fb8c6a7756b6d778a2440accd6.tar.gz
nextcloud-server-5362486ca910a8fb8c6a7756b6d778a2440accd6.zip
feat(textprocessing): factorize taskProcessingCompatibleTaskTypes
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/TextProcessing/Manager.php33
1 files changed, 11 insertions, 22 deletions
diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php
index db759cf224c..fcb5fb31d74 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()],