IManager.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
  5. *
  6. * @author Marcel Klehr <mklehr@gmx.net>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. namespace OCP\TextProcessing;
  24. use OCP\Common\Exception\NotFoundException;
  25. use OCP\PreConditionNotMetException;
  26. use RuntimeException;
  27. /**
  28. * API surface for apps interacting with and making use of LanguageModel providers
  29. * without known which providers are installed
  30. * @since 27.1.0
  31. */
  32. interface IManager {
  33. /**
  34. * @since 27.1.0
  35. */
  36. public function hasProviders(): bool;
  37. /**
  38. * @return IProvider[]
  39. * @since 27.1.0
  40. */
  41. public function getProviders(): array;
  42. /**
  43. * @return class-string<ITaskType>[]
  44. * @since 27.1.0
  45. */
  46. public function getAvailableTaskTypes(): array;
  47. /**
  48. * @param Task $task The task to run
  49. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  50. * @throws RuntimeException If something else failed
  51. * @since 27.1.0
  52. */
  53. public function runTask(Task $task): string;
  54. /**
  55. * Will schedule an LLM inference process in the background. The result will become available
  56. * with the \OCP\LanguageModel\Events\TaskSuccessfulEvent
  57. * If inference fails a \OCP\LanguageModel\Events\TaskFailedEvent will be dispatched instead
  58. *
  59. * @param Task $task The task to schedule
  60. * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
  61. * @since 27.1.0
  62. */
  63. public function scheduleTask(Task $task) : void;
  64. /**
  65. * Delete a task that has been scheduled before
  66. *
  67. * @param Task $task The task to delete
  68. * @since 27.1.0
  69. */
  70. public function deleteTask(Task $task): void;
  71. /**
  72. * @param int $id The id of the task
  73. * @return Task
  74. * @throws RuntimeException If the query failed
  75. * @throws NotFoundException If the task could not be found
  76. * @since 27.1.0
  77. */
  78. public function getTask(int $id): Task;
  79. /**
  80. * @param int $id The id of the task
  81. * @param string|null $userId The user id that scheduled the task
  82. * @return Task
  83. * @throws RuntimeException If the query failed
  84. * @throws NotFoundException If the task could not be found
  85. * @since 27.1.0
  86. */
  87. public function getUserTask(int $id, ?string $userId): Task;
  88. /**
  89. * @param string $userId
  90. * @param string $appId
  91. * @param string|null $identifier
  92. * @return array
  93. * @since 27.1.0
  94. */
  95. public function getUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array;
  96. }