Skip to content

Commit

Permalink
LLM OCP API: Fix static analysis
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Jul 7, 2023
1 parent 9935034 commit fac83ce
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/private/LanguageModel/LanguageModelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ public function runTask(ILanguageModelTask $task): string {
try {
$task->setStatus(ILanguageModelTask::STATUS_RUNNING);
$this->taskMapper->update(Task::fromLanguageModelTask($task));
$task->setOutput($task->visitProvider($provider));
$output = $task->visitProvider($provider);
$task->setOutput($output);
$task->setStatus(ILanguageModelTask::STATUS_SUCCESSFUL);
$this->taskMapper->update(Task::fromLanguageModelTask($task));
return $task->getOutput();
return $output;
} catch (\RuntimeException $e) {
$this->logger->info('LanguageModel call using provider ' . $provider->getName() . ' failed', ['exception' => $e]);
$task->setStatus(ILanguageModelTask::STATUS_FAILED);
Expand Down
6 changes: 6 additions & 0 deletions lib/public/LanguageModel/FreePromptTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ public function visitProvider(ILanguageModelProvider $provider): string {
return $provider->prompt($this->getInput());
}

/**
* @inheritDoc
*/
public function canUseProvider(ILanguageModelProvider $provider): bool {
return true;
}

/**
* @inheritDoc
*/
public function getType(): string {
return self::TYPE;
}
Expand Down
16 changes: 13 additions & 3 deletions lib/public/LanguageModel/SummaryTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

use RuntimeException;

/**
* @since 28.0.0
*/
final class SummaryTask extends AbstractLanguageModelTask {
/**
* @since 28.0.0
*/
public const TYPE = 'summarize';

/**
* @param ILanguageModelProvider $provider
* @throws RuntimeException
* @return string
* @inheritDoc
*/
public function visitProvider(ILanguageModelProvider $provider): string {
if (!$provider instanceof ISummaryProvider) {
Expand All @@ -19,10 +23,16 @@ public function visitProvider(ILanguageModelProvider $provider): string {
return $provider->summarize($this->getInput());
}

/**
* @inheritDoc
*/
public function canUseProvider(ILanguageModelProvider $provider): bool {
return $provider instanceof ISummaryProvider;
}

/**
* @inheritDoc
*/
public function getType(): string {
return self::TYPE;
}
Expand Down
16 changes: 13 additions & 3 deletions lib/public/LanguageModel/TopicsTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

use RuntimeException;

/**
* @since 28.0.0
*/
final class TopicsTask extends AbstractLanguageModelTask {
/**
* @since 28.0.0
*/
public const TYPE = 'topics';

/**
* @param ILanguageModelProvider $provider
* @throws RuntimeException
* @return string
* @inheritDoc
*/
public function visitProvider(ILanguageModelProvider $provider): string {
if (!$provider instanceof ITopicsProvider) {
Expand All @@ -19,10 +23,16 @@ public function visitProvider(ILanguageModelProvider $provider): string {
return $provider->findTopics($this->getInput());
}

/**
* @inheritDoc
*/
public function canUseProvider(ILanguageModelProvider $provider): bool {
return $provider instanceof ITopicsProvider;
}

/**
* @inheritDoc
*/
public function getType(): string {
return self::TYPE;
}
Expand Down

0 comments on commit fac83ce

Please sign in to comment.