2023-06-15 07:22:16 -04:00
|
|
|
<?php
|
2023-06-27 10:44:15 -04:00
|
|
|
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/>.
|
|
|
|
|
*/
|
2023-06-15 07:22:16 -04:00
|
|
|
|
|
|
|
|
namespace OCP\LanguageModel;
|
|
|
|
|
|
2023-06-20 11:50:56 -04:00
|
|
|
/**
|
2023-06-27 10:43:54 -04:00
|
|
|
* This is an absctract LanguageModel Task represents summarization
|
2023-06-26 05:45:54 -04:00
|
|
|
* which sums up the passed text.
|
2023-06-20 11:50:56 -04:00
|
|
|
* @since 28.0.0
|
2023-06-27 10:43:54 -04:00
|
|
|
* @template-extends AbstractLanguageModelTask<ISummaryProvider>
|
2023-06-20 11:50:56 -04:00
|
|
|
*/
|
2023-06-16 07:06:47 -04:00
|
|
|
final class SummaryTask extends AbstractLanguageModelTask {
|
2023-06-20 11:50:56 -04:00
|
|
|
/**
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2023-06-16 07:06:47 -04:00
|
|
|
public const TYPE = 'summarize';
|
2023-06-15 07:22:16 -04:00
|
|
|
|
|
|
|
|
/**
|
2023-06-20 11:50:56 -04:00
|
|
|
* @inheritDoc
|
2023-06-20 12:26:29 -04:00
|
|
|
* @since 28.0.0
|
2023-06-15 07:22:16 -04:00
|
|
|
*/
|
2023-06-27 10:43:54 -04:00
|
|
|
public function visitProvider($provider): string {
|
|
|
|
|
if (!$this->canUseProvider($provider)) {
|
2023-06-15 07:22:16 -04:00
|
|
|
throw new \RuntimeException('SummaryTask#visitProvider expects ISummaryProvider');
|
|
|
|
|
}
|
2023-06-16 07:06:47 -04:00
|
|
|
return $provider->summarize($this->getInput());
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 11:50:56 -04:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2023-06-20 12:26:29 -04:00
|
|
|
* @since 28.0.0
|
2023-06-20 11:50:56 -04:00
|
|
|
*/
|
2023-06-27 10:43:54 -04:00
|
|
|
public function canUseProvider($provider): bool {
|
2023-06-16 07:06:47 -04:00
|
|
|
return $provider instanceof ISummaryProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 11:50:56 -04:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2023-06-20 12:26:29 -04:00
|
|
|
* @since 28.0.0
|
2023-06-20 11:50:56 -04:00
|
|
|
*/
|
2023-06-16 07:06:47 -04:00
|
|
|
public function getType(): string {
|
|
|
|
|
return self::TYPE;
|
2023-06-15 07:22:16 -04:00
|
|
|
}
|
|
|
|
|
}
|