|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +use Symfony\AI\Platform\Bridge\Albert\ApiClient; |
| 13 | +use Symfony\AI\Platform\Model; |
| 14 | +use Symfony\Component\Console\Command\Command; |
| 15 | +use Symfony\Component\Console\Input\InputInterface; |
| 16 | +use Symfony\Component\Console\Output\OutputInterface; |
| 17 | +use Symfony\Component\Console\SingleCommandApplication; |
| 18 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 19 | + |
| 20 | +require_once dirname(__DIR__).'/bootstrap.php'; |
| 21 | + |
| 22 | +$app = (new SingleCommandApplication('Albert API Model Listing')) |
| 23 | + ->setDescription('Lists all available models on Albert API') |
| 24 | + ->setCode(function (InputInterface $input, OutputInterface $output) { |
| 25 | + $io = new SymfonyStyle($input, $output); |
| 26 | + $io->title('Albert API Model Listing'); |
| 27 | + |
| 28 | + $apiClient = new ApiClient(env('ALBERT_API_URL'), env('ALBERT_API_KEY'), http_client()); |
| 29 | + $models = $apiClient->getModels(); |
| 30 | + |
| 31 | + if (0 === count($models)) { |
| 32 | + $io->error('No models found for this Albert API URL.'); |
| 33 | + |
| 34 | + return Command::FAILURE; |
| 35 | + } |
| 36 | + |
| 37 | + $io->listing( |
| 38 | + array_map(fn (Model $model) => $model->getName(), $models) |
| 39 | + ); |
| 40 | + |
| 41 | + return Command::SUCCESS; |
| 42 | + }) |
| 43 | + ->run(); |
0 commit comments