mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
LLM OCP API: ADd topics and headline tasks
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
parent
9e9fc1d99b
commit
9d5717d239
6 changed files with 159 additions and 3 deletions
29
lib/public/LanguageModel/HeadlineTask.php
Normal file
29
lib/public/LanguageModel/HeadlineTask.php
Normal 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;
|
||||
}
|
||||
}
|
||||
43
lib/public/LanguageModel/IHeadlineProvider.php
Normal file
43
lib/public/LanguageModel/IHeadlineProvider.php
Normal 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;
|
||||
}
|
||||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
43
lib/public/LanguageModel/ITopicsProvider.php
Normal file
43
lib/public/LanguageModel/ITopicsProvider.php
Normal 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;
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ final class SummaryTask extends AbstractLanguageModelTask {
|
|||
public const TYPE = 'summarize';
|
||||
|
||||
/**
|
||||
* @param ILanguageModelProvider&ISummaryProvider $provider
|
||||
* @param ILanguageModelProvider $provider
|
||||
* @throws RuntimeException
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
|||
29
lib/public/LanguageModel/TopicsTask.php
Normal file
29
lib/public/LanguageModel/TopicsTask.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue