* @method int getLastUpdated()
* @method setInput(string $type)
* @method string getInput()
+ * @method setOutput(string $type)
+ * @method string getOutput()
* @method setStatus(int $type)
* @method int getStatus()
* @method setUserId(string $type)
*/
class Task extends Entity {
protected $lastUpdated;
-
protected $type;
protected $input;
+ protected $output;
protected $status;
protected $userId;
protected $appId;
$this->addType('lastUpdated', 'integer');
$this->addType('type', 'string');
$this->addType('input', 'string');
+ $this->addType('output', 'string');
$this->addType('status', 'integer');
$this->addType('userId', 'string');
$this->addType('appId', 'string');
}
+ public function toRow(): array {
+ return array_combine(self::$columns, array_map(function ($field) {
+ return $this->{'get'.ucfirst($field)}();
+ }, self::$fields));
+ }
+
public static function fromLanguageModelTask(ILanguageModelTask $task): Task {
return Task::fromParams([
+ 'id' => $task->getId(),
'type' => $task->getType(),
'lastUpdated' => time(),
'status' => $task->getStatus(),
use OCP\IServerContainer;
use OCP\LanguageModel\AbstractLanguageModelTask;
use OCP\LanguageModel\FreePromptTask;
+use OCP\LanguageModel\HeadlineTask;
+use OCP\LanguageModel\IHeadlineProvider;
use OCP\LanguageModel\ILanguageModelManager;
use OCP\LanguageModel\ILanguageModelProvider;
use OCP\LanguageModel\ILanguageModelTask;
use OCP\LanguageModel\ISummaryProvider;
+use OCP\LanguageModel\ITopicsProvider;
use OCP\LanguageModel\SummaryTask;
+use OCP\LanguageModel\TopicsTask;
use OCP\PreConditionNotMetException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
if ($context === null) {
return false;
}
- return count($context->getSpeechToTextProviders()) > 0;
+ return count($context->getLanguageModelProviders()) > 0;
}
/**
if ($provider instanceof ISummaryProvider) {
$tasks[SummaryTask::class] = true;
}
+ if ($provider instanceof IHeadlineProvider) {
+ $tasks[HeadlineTask::class] = true;
+ }
+ if ($provider instanceof ITopicsProvider) {
+ $tasks[TopicsTask::class] = true;
+ }
}
return array_keys($tasks);
}
}
try {
$task->setStatus(ILanguageModelTask::STATUS_RUNNING);
- $this->taskMapper->update(Task::fromLanguageModelTask($task));
+ $taskEntity = $this->taskMapper->update(Task::fromLanguageModelTask($task));
+ $task->setId($taskEntity->getId());
$output = $task->visitProvider($provider);
$task->setOutput($output);
$task->setStatus(ILanguageModelTask::STATUS_SUCCESSFUL);
if (!$this->canHandleTask($task)) {
throw new PreConditionNotMetException('No LanguageModel provider is installed that can handle this task');
}
+ $task->setStatus(ILanguageModelTask::STATUS_SCHEDULED);
$taskEntity = Task::fromLanguageModelTask($task);
$this->taskMapper->insert($taskEntity);
$task->setId($taskEntity->getId());
- $task->setStatus(ILanguageModelTask::STATUS_SCHEDULED);
$this->jobList->add(TaskBackgroundJob::class, [
'taskId' => $task->getId()
]);
try {
$this->languageModelManager->runTask($task);
$event = new TaskSuccessfulEvent($task);
- } catch (\RuntimeException|PreConditionNotMetException $e) {
+ } catch (\RuntimeException|PreConditionNotMetException|\Throwable $e) {
$event = new TaskFailedEvent($task, $e->getMessage());
}
$this->eventDispatcher->dispatchTyped($event);
* @template-implements ILanguageModelTask<T>
*/
abstract class AbstractLanguageModelTask implements ILanguageModelTask {
- protected ?int $id;
- protected ?string $output;
+ protected ?int $id = null;
+ protected ?string $output = null;
protected int $status = ILanguageModelTask::STATUS_UNKNOWN;
/**
$task = self::factory($taskEntity->getType(), $taskEntity->getInput(), $taskEntity->getuserId(), $taskEntity->getAppId());
$task->setId($taskEntity->getId());
$task->setStatus($taskEntity->getStatus());
+ $task->setOutput($taskEntity->getOutput());
return $task;
}
* @since 28.0.0
*/
final public static function factory(string $type, string $input, ?string $userId, string $appId): ILanguageModelTask {
- if (!in_array($type, self::TYPES)) {
+ if (!in_array($type, array_keys(self::TYPES))) {
throw new \InvalidArgumentException('Unknown task type');
}
- return new (ILanguageModelTask::TYPES[$type])($input, $userId, $appId);
+ return new (ILanguageModelTask::TYPES[$type])($input, $appId, $userId);
}
}