LLM OCP API: ADd topics and headline tasks

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2023-06-20 14:41:28 +02:00
parent 9e9fc1d99b
commit 9d5717d239
6 changed files with 159 additions and 3 deletions

View file

@ -0,0 +1,29 @@
<?php
namespace OCP\LanguageModel;
use RuntimeException;
final class HeadlineTask extends AbstractLanguageModelTask {
public const TYPE = 'headline';
/**
* @param ILanguageModelProvider $provider
* @throws RuntimeException
* @return string
*/
public function visitProvider(ILanguageModelProvider $provider): string {
if (!$provider instanceof IHeadlineProvider) {
throw new \RuntimeException('SummaryTask#visitProvider expects IHeadlineProvider');
}
return $provider->findHeadline($this->getInput());
}
public function canUseProvider(ILanguageModelProvider $provider): bool {
return $provider instanceof IHeadlineProvider;
}
public function getType(): string {
return self::TYPE;
}
}

View file

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 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\LanguageModel;
use RuntimeException;
/**
* @since 28.0.0
*/
interface IHeadlineProvider extends ILanguageModelProvider {
/**
* @param string $text The text to find headline for
* @returns string the headline
* @since 28.0.0
* @throws RuntimeException If the text could not be transcribed
*/
public function findHeadline(string $text): string;
}

View file

@ -2,7 +2,7 @@
namespace OCP\LanguageModel;
interface ILanguageModelTask {
interface ILanguageModelTask extends \JsonSerializable {
public const STATUS_FAILED = 4;
public const STATUS_SUCCESSFUL = 3;
public const STATUS_RUNNING = 2;
@ -10,8 +10,10 @@ interface ILanguageModelTask {
public const STATUS_UNKNOWN = 0;
public const TYPES = [
SummaryTask::TYPE => SummaryTask::class,
FreePromptTask::TYPE => FreePromptTask::class,
SummaryTask::TYPE => SummaryTask::class,
HeadlineTask::TYPE => HeadlineTask::class,
TopicsTask::TYPE => TopicsTask::class,
];
/**
@ -44,6 +46,16 @@ interface ILanguageModelTask {
*/
public function getInput(): string;
/**
* @param string $output
*/
public function setOutput(string $output): void;
/**
* @return string
*/
public function getOutput(): string;
/**
* @return string
*/

View file

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 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\LanguageModel;
use RuntimeException;
/**
* @since 28.0.0
*/
interface ITopicsProvider extends ILanguageModelProvider {
/**
* @param string $text The text to find topics for
* @returns string the topics, comma separated
* @since 28.0.0
* @throws RuntimeException If the text could not be transcribed
*/
public function findTopics(string $text): string;
}

View file

@ -8,7 +8,7 @@ final class SummaryTask extends AbstractLanguageModelTask {
public const TYPE = 'summarize';
/**
* @param ILanguageModelProvider&ISummaryProvider $provider
* @param ILanguageModelProvider $provider
* @throws RuntimeException
* @return string
*/

View file

@ -0,0 +1,29 @@
<?php
namespace OCP\LanguageModel;
use RuntimeException;
final class TopicsTask extends AbstractLanguageModelTask {
public const TYPE = 'topics';
/**
* @param ILanguageModelProvider $provider
* @throws RuntimeException
* @return string
*/
public function visitProvider(ILanguageModelProvider $provider): string {
if (!$provider instanceof ITopicsProvider) {
throw new \RuntimeException('SummaryTask#visitProvider expects IHeadlineProvider');
}
return $provider->findTopics($this->getInput());
}
public function canUseProvider(ILanguageModelProvider $provider): bool {
return $provider instanceof ITopicsProvider;
}
public function getType(): string {
return self::TYPE;
}
}