2023-06-20 08:41:28 -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-20 08:41:28 -04:00
|
|
|
|
|
|
|
|
namespace OCP\LanguageModel;
|
|
|
|
|
|
2023-06-20 11:50:56 -04:00
|
|
|
/**
|
2023-06-26 05:45:54 -04:00
|
|
|
* This LanguageModel Task represents topics synthesis
|
|
|
|
|
* which outputs comma-separated topics for 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<ITopicsProvider>
|
2023-06-20 11:50:56 -04:00
|
|
|
*/
|
2023-06-20 08:41:28 -04:00
|
|
|
final class TopicsTask extends AbstractLanguageModelTask {
|
2023-06-20 11:50:56 -04:00
|
|
|
/**
|
|
|
|
|
* @since 28.0.0
|
|
|
|
|
*/
|
2023-06-20 08:41:28 -04:00
|
|
|
public const TYPE = 'topics';
|
|
|
|
|
|
|
|
|
|
/**
|
2023-06-20 11:50:56 -04:00
|
|
|
* @inheritDoc
|
2023-06-20 12:26:29 -04:00
|
|
|
* @since 28.0.0
|
2023-06-20 08:41:28 -04:00
|
|
|
*/
|
2023-06-27 10:43:54 -04:00
|
|
|
public function visitProvider($provider): string {
|
|
|
|
|
if (!$this->canUseProvider($provider)) {
|
|
|
|
|
throw new \RuntimeException('TopicsTask#visitProvider expects ITopicsProvider');
|
2023-06-20 08:41:28 -04:00
|
|
|
}
|
|
|
|
|
return $provider->findTopics($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-20 08:41:28 -04:00
|
|
|
return $provider instanceof ITopicsProvider;
|
|
|
|
|
}
|
|
|
|
|
|
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-20 08:41:28 -04:00
|
|
|
public function getType(): string {
|
|
|
|
|
return self::TYPE;
|
|
|
|
|
}
|
|
|
|
|
}
|