2023-06-15 04:30:04 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-06-15 04:30:04 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2023-07-14 09:59:50 -04:00
|
|
|
namespace OCP\TextProcessing;
|
2023-06-15 04:30:04 -04:00
|
|
|
|
2023-06-27 10:51:41 -04:00
|
|
|
use OCP\Common\Exception\NotFoundException;
|
2023-11-03 11:22:54 -04:00
|
|
|
use OCP\DB\Exception;
|
2023-06-15 04:30:04 -04:00
|
|
|
use OCP\PreConditionNotMetException;
|
2023-11-06 06:50:16 -05:00
|
|
|
use OCP\TextProcessing\Exception\TaskFailureException;
|
2023-06-15 04:30:04 -04:00
|
|
|
use RuntimeException;
|
|
|
|
|
|
2023-06-20 12:26:29 -04:00
|
|
|
/**
|
2023-06-28 09:16:21 -04:00
|
|
|
* API surface for apps interacting with and making use of LanguageModel providers
|
|
|
|
|
* without known which providers are installed
|
2023-07-07 07:46:03 -04:00
|
|
|
* @since 27.1.0
|
2024-07-26 05:20:46 -04:00
|
|
|
* @deprecated 30.0.0
|
2023-06-20 12:26:29 -04:00
|
|
|
*/
|
2023-07-14 09:59:50 -04:00
|
|
|
interface IManager {
|
2023-06-15 04:30:04 -04:00
|
|
|
/**
|
2023-07-07 07:46:03 -04:00
|
|
|
* @since 27.1.0
|
2023-06-15 04:30:04 -04:00
|
|
|
*/
|
|
|
|
|
public function hasProviders(): bool;
|
|
|
|
|
|
2023-07-24 06:12:06 -04:00
|
|
|
/**
|
|
|
|
|
* @return IProvider[]
|
|
|
|
|
* @since 27.1.0
|
|
|
|
|
*/
|
|
|
|
|
public function getProviders(): array;
|
|
|
|
|
|
2023-06-15 04:30:04 -04:00
|
|
|
/**
|
2023-10-24 09:34:51 -04:00
|
|
|
* @return string[]
|
2023-07-07 07:46:03 -04:00
|
|
|
* @since 27.1.0
|
2023-06-20 08:41:58 -04:00
|
|
|
*/
|
|
|
|
|
public function getAvailableTaskTypes(): array;
|
|
|
|
|
|
2023-06-15 04:30:04 -04:00
|
|
|
/**
|
2023-07-14 09:59:50 -04:00
|
|
|
* @param Task $task The task to run
|
2023-06-15 07:22:16 -04:00
|
|
|
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
|
2023-11-06 06:50:16 -05:00
|
|
|
* @throws TaskFailureException If running the task failed
|
2023-07-07 07:46:03 -04:00
|
|
|
* @since 27.1.0
|
2023-06-15 04:30:04 -04:00
|
|
|
*/
|
2023-07-14 09:59:50 -04:00
|
|
|
public function runTask(Task $task): string;
|
2023-06-15 04:30:04 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Will schedule an LLM inference process in the background. The result will become available
|
2023-07-07 06:37:01 -04:00
|
|
|
* with the \OCP\LanguageModel\Events\TaskSuccessfulEvent
|
|
|
|
|
* If inference fails a \OCP\LanguageModel\Events\TaskFailedEvent will be dispatched instead
|
2023-06-15 04:30:04 -04:00
|
|
|
*
|
2023-07-14 09:59:50 -04:00
|
|
|
* @param Task $task The task to schedule
|
2023-06-15 07:22:16 -04:00
|
|
|
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
|
2023-11-03 11:22:54 -04:00
|
|
|
* @throws Exception storing the task in the database failed
|
2023-07-07 07:46:03 -04:00
|
|
|
* @since 27.1.0
|
2023-06-15 04:30:04 -04:00
|
|
|
*/
|
2023-07-14 09:59:50 -04:00
|
|
|
public function scheduleTask(Task $task) : void;
|
2023-06-16 07:06:47 -04:00
|
|
|
|
2023-11-03 11:22:54 -04:00
|
|
|
/**
|
|
|
|
|
* If the designated provider for the passed task provides an expected average runtime, we check if the runtime fits into the
|
|
|
|
|
* max execution time of this php process and run it synchronously if it does, if it doesn't fit (or the provider doesn't provide that information)
|
|
|
|
|
* execution is deferred to a background job
|
|
|
|
|
*
|
|
|
|
|
* @param Task $task The task to schedule
|
|
|
|
|
* @returns bool A boolean indicating whether the task was run synchronously (`true`) or offloaded to a background job (`false`)
|
|
|
|
|
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
|
2023-11-06 06:50:16 -05:00
|
|
|
* @throws TaskFailureException If running the task failed
|
2023-11-03 11:22:54 -04:00
|
|
|
* @throws Exception storing the task in the database failed
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function runOrScheduleTask(Task $task): bool;
|
|
|
|
|
|
2023-08-04 09:41:35 -04:00
|
|
|
/**
|
|
|
|
|
* Delete a task that has been scheduled before
|
|
|
|
|
*
|
|
|
|
|
* @param Task $task The task to delete
|
|
|
|
|
* @since 27.1.0
|
|
|
|
|
*/
|
|
|
|
|
public function deleteTask(Task $task): void;
|
|
|
|
|
|
2023-06-20 08:41:58 -04:00
|
|
|
/**
|
|
|
|
|
* @param int $id The id of the task
|
2023-07-14 09:59:50 -04:00
|
|
|
* @return Task
|
2023-06-20 08:41:58 -04:00
|
|
|
* @throws RuntimeException If the query failed
|
2023-06-27 10:51:41 -04:00
|
|
|
* @throws NotFoundException If the task could not be found
|
2023-07-07 07:46:03 -04:00
|
|
|
* @since 27.1.0
|
2023-06-20 08:41:58 -04:00
|
|
|
*/
|
2023-07-14 09:59:50 -04:00
|
|
|
public function getTask(int $id): Task;
|
2023-08-02 10:47:41 -04:00
|
|
|
|
2023-08-03 17:11:29 -04:00
|
|
|
/**
|
|
|
|
|
* @param int $id The id of the task
|
|
|
|
|
* @param string|null $userId The user id that scheduled the task
|
|
|
|
|
* @return Task
|
|
|
|
|
* @throws RuntimeException If the query failed
|
|
|
|
|
* @throws NotFoundException If the task could not be found
|
|
|
|
|
* @since 27.1.0
|
|
|
|
|
*/
|
|
|
|
|
public function getUserTask(int $id, ?string $userId): Task;
|
|
|
|
|
|
2023-08-02 10:47:41 -04:00
|
|
|
/**
|
|
|
|
|
* @param string $userId
|
|
|
|
|
* @param string $appId
|
|
|
|
|
* @param string|null $identifier
|
|
|
|
|
* @return array
|
2023-08-03 17:11:29 -04:00
|
|
|
* @since 27.1.0
|
2023-08-02 10:47:41 -04:00
|
|
|
*/
|
2023-08-03 17:11:29 -04:00
|
|
|
public function getUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array;
|
2023-06-15 04:30:04 -04:00
|
|
|
}
|