summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2023-06-20 14:41:58 +0200
committerMarcel Klehr <mklehr@gmx.net>2023-08-09 09:59:58 +0200
commit236c32b13f190f49fa369e4eb20ec4a85a76ba04 (patch)
tree4fea77e1e266efd327b5585e652da1495d8c1c01 /lib/private
parent5807c431b854cca5e46fda4222782cd488137222 (diff)
downloadnextcloud-server-236c32b13f190f49fa369e4eb20ec4a85a76ba04.tar.gz
nextcloud-server-236c32b13f190f49fa369e4eb20ec4a85a76ba04.zip
LLM OCP API: Implement ocs API
Signed-off-by: Marcel Klehr <mklehr@gmx.net> (cherry picked from commit 795b097122a8dd70b4d6b9ebe044440396be9104)
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/LanguageModel/Db/Task.php7
-rw-r--r--lib/private/LanguageModel/LanguageModelManager.php11
-rw-r--r--lib/private/LanguageModel/TaskBackgroundJob.php4
-rw-r--r--lib/private/Server.php4
4 files changed, 19 insertions, 7 deletions
diff --git a/lib/private/LanguageModel/Db/Task.php b/lib/private/LanguageModel/Db/Task.php
index cee6c2fd8b9..e5d2f79e453 100644
--- a/lib/private/LanguageModel/Db/Task.php
+++ b/lib/private/LanguageModel/Db/Task.php
@@ -28,12 +28,12 @@ class Task extends Entity {
/**
* @var string[]
*/
- public static array $columns = ['id', 'type', 'input', 'status', 'user_id', 'app_id'];
+ public static array $columns = ['id', 'type', 'input', 'output', 'status', 'user_id', 'app_id'];
/**
* @var string[]
*/
- public static array $fields = ['id', 'type', 'input', 'status', 'userId', 'appId'];
+ public static array $fields = ['id', 'type', 'input', 'output', 'status', 'userId', 'appId'];
public function __construct() {
@@ -49,8 +49,9 @@ class Task extends Entity {
public static function fromLanguageModelTask(ILanguageModelTask $task): Task {
return Task::fromParams([
'type' => $task->getType(),
- 'status' => ILanguageModelTask::STATUS_UNKNOWN,
+ 'status' => $task->getStatus(),
'input' => $task->getInput(),
+ 'output' => $task->getOutput(),
'userId' => $task->getUserId(),
'appId' => $task->getAppId(),
]);
diff --git a/lib/private/LanguageModel/LanguageModelManager.php b/lib/private/LanguageModel/LanguageModelManager.php
index b0e45f5812a..7db2e656a0a 100644
--- a/lib/private/LanguageModel/LanguageModelManager.php
+++ b/lib/private/LanguageModel/LanguageModelManager.php
@@ -86,6 +86,13 @@ class LanguageModelManager implements ILanguageModelManager {
return array_keys($tasks);
}
+ /**
+ * @inheritDoc
+ */
+ public function getAvailableTaskTypes(): array {
+ return array_map(fn ($taskClass) => $taskClass::TYPE, $this->getAvailableTasks());
+ }
+
public function canHandleTask(ILanguageModelTask $task): bool {
return !empty(array_filter($this->getAvailableTasks(), fn ($class) => $task instanceof $class));
}
@@ -104,10 +111,10 @@ class LanguageModelManager implements ILanguageModelManager {
try {
$task->setStatus(ILanguageModelTask::STATUS_RUNNING);
$this->taskMapper->update(Task::fromLanguageModelTask($task));
- $output = $task->visitProvider($provider);
+ $task->setOutput($task->visitProvider($provider));
$task->setStatus(ILanguageModelTask::STATUS_SUCCESSFUL);
$this->taskMapper->update(Task::fromLanguageModelTask($task));
- return $output;
+ return $task->getOutput();
} catch (\RuntimeException $e) {
$this->logger->info('LanguageModel call using provider ' . $provider->getName() . ' failed', ['exception' => $e]);
$task->setStatus(ILanguageModelTask::STATUS_FAILED);
diff --git a/lib/private/LanguageModel/TaskBackgroundJob.php b/lib/private/LanguageModel/TaskBackgroundJob.php
index 55413ba3714..3c18ff03102 100644
--- a/lib/private/LanguageModel/TaskBackgroundJob.php
+++ b/lib/private/LanguageModel/TaskBackgroundJob.php
@@ -61,8 +61,8 @@ class TaskBackgroundJob extends QueuedJob {
$taskId = $argument['taskId'];
$task = $this->languageModelManager->getTask($taskId);
try {
- $output = $this->languageModelManager->runTask($task);
- $event = new TaskSuccessfulEvent($task, $output);
+ $this->languageModelManager->runTask($task);
+ $event = new TaskSuccessfulEvent($task);
} catch (\RuntimeException|PreConditionNotMetException $e) {
$event = new TaskFailedEvent($task, $e->getMessage());
diff --git a/lib/private/Server.php b/lib/private/Server.php
index bb4e217efa3..d1f18a1235f 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -110,6 +110,7 @@ use OC\IntegrityCheck\Checker;
use OC\IntegrityCheck\Helpers\AppLocator;
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
use OC\IntegrityCheck\Helpers\FileAccessHelper;
+use OC\LanguageModel\LanguageModelManager;
use OC\LDAP\NullLDAPProviderFactory;
use OC\KnownUser\KnownUserService;
use OC\Lock\DBLockingProvider;
@@ -228,6 +229,7 @@ use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
+use OCP\LanguageModel\ILanguageModelManager;
use OCP\LDAP\ILDAPProvider;
use OCP\LDAP\ILDAPProviderFactory;
use OCP\Lock\ILockingProvider;
@@ -1461,6 +1463,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class);
+ $this->registerAlias(ILanguageModelManager::class, LanguageModelManager::class);
+
$this->connectDispatcher();
}