use OC\LanguageModel\Db\Task;
/**
- * @since 28.0.0
+ * This is an abstract LanguageModel task that implements basic
+ * goodies for downstream tasks
+ * @since 28.0.
+ * @template T of ILanguageModelProvider
+ * @template-implements ILanguageModelTask<T>
*/
abstract class AbstractLanguageModelTask implements ILanguageModelTask {
protected ?int $id;
) {
}
- /**
- * @param ILanguageModelProvider $provider
- * @return string
- * @throws \RuntimeException
- * @since 28.0.0
- */
- abstract public function visitProvider(ILanguageModelProvider $provider): string;
-
- /**
- * @param ILanguageModelProvider $provider
- * @return bool
- * @since 28.0.0
- */
- abstract public function canUseProvider(ILanguageModelProvider $provider): bool;
-
/**
* @return string
* @since 28.0.0
/**
* @since 28.0.0
+ * @template-extends AbstractLanguageModelTask<ILanguageModelProvider>
*/
final class FreePromptTask extends AbstractLanguageModelTask {
/**
* @inheritDoc
* @since 28.0.0
*/
- public function visitProvider(ILanguageModelProvider $provider): string {
+ public function visitProvider($provider): string {
return $provider->prompt($this->getInput());
}
* @inheritDoc
* @since 28.0.0
*/
- public function canUseProvider(ILanguageModelProvider $provider): bool {
+ public function canUseProvider($provider): bool {
return true;
}
* This LanguageModel Task represents headline generation
* which generates a headline for the passed text
* @since 28.0.0
+ * @template-extends AbstractLanguageModelTask<IHeadlineProvider>
*/
final class HeadlineTask extends AbstractLanguageModelTask {
/**
* @inheritDoc
* @since 28.0.0
*/
- public function visitProvider(ILanguageModelProvider $provider): string {
- if (!$provider instanceof IHeadlineProvider) {
- throw new \RuntimeException('SummaryTask#visitProvider expects IHeadlineProvider');
+ public function visitProvider($provider): string {
+ if (!$this->canUseProvider($provider)) {
+ throw new \RuntimeException('HeadlineTask#visitProvider expects IHeadlineProvider');
}
return $provider->findHeadline($this->getInput());
}
* @inheritDoc
* @since 28.0.0
*/
- public function canUseProvider(ILanguageModelProvider $provider): bool {
+ public function canUseProvider($provider): bool {
return $provider instanceof IHeadlineProvider;
}
use RuntimeException;
/**
+ * This is the minimum interface is implemented by apps that
+ * implement a LanguageModel provider
* @since 28.0.0
*/
interface ILanguageModelProvider {
/**
* @since 28.0.0
+ * @template T of ILanguageModelProvider
*/
interface ILanguageModelTask extends \JsonSerializable {
/**
];
/**
- * @param ILanguageModelProvider $provider
+ * @param T $provider
* @return string
* @since 28.0.0
*/
- public function visitProvider(ILanguageModelProvider $provider): string;
+ public function visitProvider($provider): string;
/**
- * @param ILanguageModelProvider $provider
+ * @param T $provider
* @return bool
* @since 28.0.0
*/
- public function canUseProvider(ILanguageModelProvider $provider): bool;
+ public function canUseProvider($provider): bool;
/**
namespace OCP\LanguageModel;
/**
- * This LanguageModel Task represents summarization
+ * This is an absctract LanguageModel Task represents summarization
* which sums up the passed text.
* @since 28.0.0
+ * @template-extends AbstractLanguageModelTask<ISummaryProvider>
*/
final class SummaryTask extends AbstractLanguageModelTask {
/**
* @inheritDoc
* @since 28.0.0
*/
- public function visitProvider(ILanguageModelProvider $provider): string {
- if (!$provider instanceof ISummaryProvider) {
+ public function visitProvider($provider): string {
+ if (!$this->canUseProvider($provider)) {
throw new \RuntimeException('SummaryTask#visitProvider expects ISummaryProvider');
}
return $provider->summarize($this->getInput());
* @inheritDoc
* @since 28.0.0
*/
- public function canUseProvider(ILanguageModelProvider $provider): bool {
+ public function canUseProvider($provider): bool {
return $provider instanceof ISummaryProvider;
}
* This LanguageModel Task represents topics synthesis
* which outputs comma-separated topics for the passed text
* @since 28.0.0
+ * @template-extends AbstractLanguageModelTask<ITopicsProvider>
*/
final class TopicsTask extends AbstractLanguageModelTask {
/**
* @inheritDoc
* @since 28.0.0
*/
- public function visitProvider(ILanguageModelProvider $provider): string {
- if (!$provider instanceof ITopicsProvider) {
- throw new \RuntimeException('SummaryTask#visitProvider expects IHeadlineProvider');
+ public function visitProvider($provider): string {
+ if (!$this->canUseProvider($provider)) {
+ throw new \RuntimeException('TopicsTask#visitProvider expects ITopicsProvider');
}
return $provider->findTopics($this->getInput());
}
* @inheritDoc
* @since 28.0.0
*/
- public function canUseProvider(ILanguageModelProvider $provider): bool {
+ public function canUseProvider($provider): bool {
return $provider instanceof ITopicsProvider;
}