2023-06-15 07:22:16 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|