migrate therinaldos.com data
Build & Deploy to DigitalOcean Space / build (push) Failing after 2m38s

This commit is contained in:
2024-05-05 15:50:45 -04:00
commit ef1ff240d4
23182 changed files with 3801898 additions and 0 deletions
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCP\TextProcessing\Events;
use OCP\EventDispatcher\Event;
use OCP\TextProcessing\Task;
/**
* @since 27.1.0
*/
abstract class AbstractTextProcessingEvent extends Event {
/**
* @since 27.1.0
*/
public function __construct(
private Task $task
) {
parent::__construct();
}
/**
* @return Task
* @since 27.1.0
*/
public function getTask(): Task {
return $this->task;
}
}
@@ -0,0 +1,30 @@
<?php
namespace OCP\TextProcessing\Events;
use OCP\TextProcessing\Task;
/**
* @since 27.1.0
*/
class TaskFailedEvent extends AbstractTextProcessingEvent {
/**
* @param Task $task
* @param string $errorMessage
* @since 27.1.0
*/
public function __construct(
Task $task,
private string $errorMessage,
) {
parent::__construct($task);
}
/**
* @return string
* @since 27.1.0
*/
public function getErrorMessage(): string {
return $this->errorMessage;
}
}
@@ -0,0 +1,9 @@
<?php
namespace OCP\TextProcessing\Events;
/**
* @since 27.1.0
*/
class TaskSuccessfulEvent extends AbstractTextProcessingEvent {
}
@@ -0,0 +1,10 @@
<?php
namespace OCP\TextProcessing\Exception;
/**
* Exception thrown when a task failed
* @since 28.0.0
*/
class TaskFailureException extends \RuntimeException {
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
use OCP\IL10N;
use OCP\L10N\IFactory;
/**
* This is the text processing task type for free prompting
* @since 27.1.0
*/
class FreePromptTaskType implements ITaskType {
private IL10N $l;
/**
* Constructor for FreePromptTaskType
*
* @param IFactory $l10nFactory
* @since 27.1.0
*/
public function __construct(
IFactory $l10nFactory,
) {
$this->l = $l10nFactory->get('core');
}
/**
* @inheritDoc
* @since 27.1.0
*/
public function getName(): string {
return $this->l->t('Free prompt');
}
/**
* @inheritDoc
* @since 27.1.0
*/
public function getDescription(): string {
return $this->l->t('Runs an arbitrary prompt through the language model.');
}
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
use OCP\IL10N;
use OCP\L10N\IFactory;
/**
* This is the text processing task type for creating headline
* @since 27.1.0
*/
class HeadlineTaskType implements ITaskType {
private IL10N $l;
/**
* Constructor for HeadlineTaskType
*
* @param IFactory $l10nFactory
* @since 27.1.0
*/
public function __construct(
IFactory $l10nFactory,
) {
$this->l = $l10nFactory->get('core');
}
/**
* @inheritDoc
* @since 27.1.0
*/
public function getName(): string {
return $this->l->t('Generate headline');
}
/**
* @inheritDoc
* @since 27.1.0
*/
public function getDescription(): string {
return $this->l->t('Generates a possible headline for a text.');
}
}
@@ -0,0 +1,127 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
use OCP\Common\Exception\NotFoundException;
use OCP\DB\Exception;
use OCP\PreConditionNotMetException;
use OCP\TextProcessing\Exception\TaskFailureException;
use RuntimeException;
/**
* API surface for apps interacting with and making use of LanguageModel providers
* without known which providers are installed
* @since 27.1.0
*/
interface IManager {
/**
* @since 27.1.0
*/
public function hasProviders(): bool;
/**
* @return IProvider[]
* @since 27.1.0
*/
public function getProviders(): array;
/**
* @return class-string<ITaskType>[]
* @since 27.1.0
*/
public function getAvailableTaskTypes(): array;
/**
* @param Task $task The task to run
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
* @throws TaskFailureException If running the task failed
* @since 27.1.0
*/
public function runTask(Task $task): string;
/**
* Will schedule an LLM inference process in the background. The result will become available
* with the \OCP\LanguageModel\Events\TaskSuccessfulEvent
* If inference fails a \OCP\LanguageModel\Events\TaskFailedEvent will be dispatched instead
*
* @param Task $task The task to schedule
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
* @throws Exception storing the task in the database failed
* @since 27.1.0
*/
public function scheduleTask(Task $task) : void;
/**
* 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
* @throws TaskFailureException If running the task failed
* @throws Exception storing the task in the database failed
* @since 28.0.0
*/
public function runOrScheduleTask(Task $task): bool;
/**
* 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;
/**
* @param int $id The id of 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 getTask(int $id): Task;
/**
* @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;
/**
* @param string $userId
* @param string $appId
* @param string|null $identifier
* @return array
* @since 27.1.0
*/
public function getUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array;
}
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
use RuntimeException;
/**
* This is the interface that is implemented by apps that
* implement a text processing provider
* @psalm-template-covariant T of ITaskType
* @since 27.1.0
*/
interface IProvider {
/**
* The localized name of this provider
* @since 27.1.0
*/
public function getName(): string;
/**
* Processes a text
*
* @param string $prompt The input text
* @return string the output text
* @since 27.1.0
* @throws RuntimeException If the text could not be processed
*/
public function process(string $prompt): string;
/**
* Returns the task type class string of the task type, that this
* provider handles
*
* @since 27.1.0
* @return class-string<T>
*/
public function getTaskType(): string;
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
/**
* This interface allows the system to learn the provider's expected runtime
* @since 28.0.0
* @template T of ITaskType
* @template-extends IProvider<T>
*/
interface IProviderWithExpectedRuntime extends IProvider {
/**
* @return int The expected average runtime of a task in seconds
* @since 28.0.0
*/
public function getExpectedRuntime(): int;
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
/**
* This interface allows providers to access the user that initiated the task being run.
* @since 28.0.0
* @template T of ITaskType
* @template-extends IProvider<T>
*/
interface IProviderWithUserId extends IProvider {
/**
* @param ?string $userId the current user's id
* @since 28.0.0
*/
public function setUserId(?string $userId): void;
}
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
/**
* This is a task type interface that is implemented by text processing
* task types
* @since 27.1.0
*/
interface ITaskType {
/**
* Returns the localized name of this task type
*
* @since 27.1.0
* @return string
*/
public function getName(): string;
/**
* Returns the localized description of this task type
*
* @since 27.1.0
* @return string
*/
public function getDescription(): string;
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
use OCP\IL10N;
use OCP\L10N\IFactory;
/**
* This is the text processing task type for summaries
* @since 27.1.0
*/
class SummaryTaskType implements ITaskType {
private IL10N $l;
/**
* Constructor for SummaryTaskType
*
* @param IFactory $l10nFactory
* @since 27.1.0
*/
public function __construct(
IFactory $l10nFactory,
) {
$this->l = $l10nFactory->get('core');
}
/**
* @inheritDoc
* @since 27.1.0
*/
public function getName(): string {
return $this->l->t('Summarize');
}
/**
* @inheritDoc
* @since 27.1.0
*/
public function getDescription(): string {
return $this->l->t('Summarizes text by reducing its length without losing key information.');
}
}
@@ -0,0 +1,241 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
/**
* This is a text processing task
* @since 27.1.0
* @psalm-template-covariant T of ITaskType
*/
final class Task implements \JsonSerializable {
protected ?int $id = null;
protected ?string $output = null;
private ?\DateTime $completionExpectedAt = null;
/**
* @since 27.1.0
*/
public const TYPES = [
FreePromptTaskType::class,
SummaryTaskType::class,
HeadlineTaskType::class,
TopicsTaskType::class,
];
/**
* @since 27.1.0
*/
public const STATUS_FAILED = 4;
/**
* @since 27.1.0
*/
public const STATUS_SUCCESSFUL = 3;
/**
* @since 27.1.0
*/
public const STATUS_RUNNING = 2;
/**
* @since 27.1.0
*/
public const STATUS_SCHEDULED = 1;
/**
* @since 27.1.0
*/
public const STATUS_UNKNOWN = 0;
/**
* @psalm-var self::STATUS_*
*/
protected int $status = self::STATUS_UNKNOWN;
/**
* @psalm-param class-string<T> $type
* @param string $type
* @param string $input
* @param string $appId
* @param string|null $userId
* @param string $identifier An arbitrary identifier for this task. max length: 255 chars
* @since 27.1.0
*/
final public function __construct(
protected string $type,
protected string $input,
protected string $appId,
protected ?string $userId,
protected string $identifier = '',
) {
}
/**
* @psalm-param IProvider<T> $provider
* @param IProvider $provider
* @return string
* @since 27.1.0
*/
public function visitProvider(IProvider $provider): string {
if ($this->canUseProvider($provider)) {
if ($provider instanceof IProviderWithUserId) {
$provider->setUserId($this->getUserId());
}
return $provider->process($this->getInput());
} else {
throw new \RuntimeException('Task of type ' . $this->getType() . ' cannot visit provider with task type ' . $provider->getTaskType());
}
}
/**
* @psalm-param IProvider<T> $provider
* @param IProvider $provider
* @return bool
* @since 27.1.0
*/
public function canUseProvider(IProvider $provider): bool {
return $provider->getTaskType() === $this->getType();
}
/**
* @psalm-return class-string<T>
* @since 27.1.0
*/
final public function getType(): string {
return $this->type;
}
/**
* @return string|null
* @since 27.1.0
*/
final public function getOutput(): ?string {
return $this->output;
}
/**
* @param string|null $output
* @since 27.1.0
*/
final public function setOutput(?string $output): void {
$this->output = $output;
}
/**
* @psalm-return self::STATUS_*
* @since 27.1.0
*/
final public function getStatus(): int {
return $this->status;
}
/**
* @psalm-param self::STATUS_* $status
* @since 27.1.0
*/
final public function setStatus(int $status): void {
$this->status = $status;
}
/**
* @return int|null
* @since 27.1.0
*/
final public function getId(): ?int {
return $this->id;
}
/**
* @param int|null $id
* @since 27.1.0
*/
final public function setId(?int $id): void {
$this->id = $id;
}
/**
* @return string
* @since 27.1.0
*/
final public function getInput(): string {
return $this->input;
}
/**
* @return string
* @since 27.1.0
*/
final public function getAppId(): string {
return $this->appId;
}
/**
* @return string
* @since 27.1.0
*/
final public function getIdentifier(): string {
return $this->identifier;
}
/**
* @return string|null
* @since 27.1.0
*/
final public function getUserId(): ?string {
return $this->userId;
}
/**
* @psalm-return array{id: ?int, type: class-string<T>, status: 0|1|2|3|4, userId: ?string, appId: string, input: string, output: ?string, identifier: string, completionExpectedAt: ?int}
* @since 27.1.0
*/
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'type' => $this->getType(),
'status' => $this->getStatus(),
'userId' => $this->getUserId(),
'appId' => $this->getAppId(),
'input' => $this->getInput(),
'output' => $this->getOutput(),
'identifier' => $this->getIdentifier(),
'completionExpectedAt' => $this->getCompletionExpectedAt()?->getTimestamp(),
];
}
/**
* @param null|\DateTime $completionExpectedAt
* @return void
* @since 28.0.0
*/
final public function setCompletionExpectedAt(?\DateTime $completionExpectedAt): void {
$this->completionExpectedAt = $completionExpectedAt;
}
/**
* @return \DateTime|null
* @since 28.0.0
*/
final public function getCompletionExpectedAt(): ?\DateTime {
return $this->completionExpectedAt;
}
}
@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net>
*
* @author Marcel Klehr <mklehr@gmx.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCP\TextProcessing;
use OCP\IL10N;
use OCP\L10N\IFactory;
/**
* This is the text processing task type for topics extraction
* @since 27.1.0
*/
class TopicsTaskType implements ITaskType {
private IL10N $l;
/**
* Constructor for TopicsTaskType
*
* @param IFactory $l10nFactory
* @since 27.1.0
*/
public function __construct(
IFactory $l10nFactory,
) {
$this->l = $l10nFactory->get('core');
}
/**
* @inheritDoc
* @since 27.1.0
*/
public function getName(): string {
return $this->l->t('Extract topics');
}
/**
* @inheritDoc
* @since 27.1.0
*/
public function getDescription(): string {
return $this->l->t('Extracts topics from a text and outputs them separated by commas.');
}
}