1
0

IManager.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\TextProcessing;
  8. use OCP\Common\Exception\NotFoundException;
  9. use OCP\DB\Exception;
  10. use OCP\PreConditionNotMetException;
  11. use OCP\TextProcessing\Exception\TaskFailureException;
  12. use RuntimeException;
  13. /**
  14. * API surface for apps interacting with and making use of LanguageModel providers
  15. * without known which providers are installed
  16. * @since 27.1.0
  17. * @deprecated 30.0.0
  18. */
  19. interface IManager {
  20. /**
  21. * @since 27.1.0
  22. */
  23. public function hasProviders(): bool;
  24. /**
  25. * @return IProvider[]
  26. * @since 27.1.0
  27. */
  28. public function getProviders(): array;
  29. /**
  30. * @return string[]
  31. * @since 27.1.0
  32. */
  33. public function getAvailableTaskTypes(): array;
  34. /**
  35. * @param Task $task The task to run
  36. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  37. * @throws TaskFailureException If running the task failed
  38. * @since 27.1.0
  39. */
  40. public function runTask(Task $task): string;
  41. /**
  42. * Will schedule an LLM inference process in the background. The result will become available
  43. * with the \OCP\LanguageModel\Events\TaskSuccessfulEvent
  44. * If inference fails a \OCP\LanguageModel\Events\TaskFailedEvent will be dispatched instead
  45. *
  46. * @param Task $task The task to schedule
  47. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  48. * @throws Exception storing the task in the database failed
  49. * @since 27.1.0
  50. */
  51. public function scheduleTask(Task $task) : void;
  52. /**
  53. * If the designated provider for the passed task provides an expected average runtime, we check if the runtime fits into the
  54. * 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)
  55. * execution is deferred to a background job
  56. *
  57. * @param Task $task The task to schedule
  58. * @returns bool A boolean indicating whether the task was run synchronously (`true`) or offloaded to a background job (`false`)
  59. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  60. * @throws TaskFailureException If running the task failed
  61. * @throws Exception storing the task in the database failed
  62. * @since 28.0.0
  63. */
  64. public function runOrScheduleTask(Task $task): bool;
  65. /**
  66. * Delete a task that has been scheduled before
  67. *
  68. * @param Task $task The task to delete
  69. * @since 27.1.0
  70. */
  71. public function deleteTask(Task $task): void;
  72. /**
  73. * @param int $id The id of the task
  74. * @return Task
  75. * @throws RuntimeException If the query failed
  76. * @throws NotFoundException If the task could not be found
  77. * @since 27.1.0
  78. */
  79. public function getTask(int $id): Task;
  80. /**
  81. * @param int $id The id of the task
  82. * @param string|null $userId The user id that scheduled the task
  83. * @return Task
  84. * @throws RuntimeException If the query failed
  85. * @throws NotFoundException If the task could not be found
  86. * @since 27.1.0
  87. */
  88. public function getUserTask(int $id, ?string $userId): Task;
  89. /**
  90. * @param string $userId
  91. * @param string $appId
  92. * @param string|null $identifier
  93. * @return array
  94. * @since 27.1.0
  95. */
  96. public function getUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array;
  97. }