Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8eff740
commit 6876967
Showing
4 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace App\Command; | ||
|
||
use App\Enum\AiModel; | ||
use App\Service\AiHorde\AiHorde; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\Question; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
#[AsCommand('app:debug-ai')] | ||
final class DebugAiResponseCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly AiHorde $aiHorde, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->addOption('model', 'm', InputOption::VALUE_REQUIRED, 'Model name') | ||
->addArgument('prompt', InputArgument::OPTIONAL) | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$question = new Question('Prompt'); | ||
$question->setMultiline(true); | ||
$prompt = $input->getArgument('prompt') ?? $io->askQuestion($question); | ||
$requestedModel = $input->getOption('model'); | ||
|
||
if (!$prompt) { | ||
$io->error('No prompt'); | ||
return Command::FAILURE; | ||
} | ||
|
||
$models = array_filter(AiModel::cases(), function (AiModel $model) use ($requestedModel) { | ||
return !$requestedModel || $model->value === $requestedModel; | ||
}); | ||
$models = array_filter($models, function (AiModel $model) { | ||
return count($this->aiHorde->findModels($model)) > 0; | ||
}); | ||
shuffle($models); | ||
|
||
if (!count($models)) { | ||
$io->error("No available worker for given model"); | ||
return Command::FAILURE; | ||
} | ||
$model = $models[array_key_first($models)]; | ||
|
||
$io->comment("Prompt: {$prompt}"); | ||
$io->comment("Using model: {$model->value}"); | ||
|
||
$io->success($this->aiHorde->getResponse( | ||
$prompt, | ||
$model, | ||
)); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters