|
| 1 | +<?php |
| 2 | + |
| 3 | +use PhpLlm\LlmChain\Bridge\HuggingFace\ApiClient; |
| 4 | +use PhpLlm\LlmChain\Bridge\HuggingFace\Model; |
| 5 | +use Symfony\Component\Console\Command\Command; |
| 6 | +use Symfony\Component\Console\Input\InputInterface; |
| 7 | +use Symfony\Component\Console\Input\InputOption; |
| 8 | +use Symfony\Component\Console\Output\ConsoleOutput; |
| 9 | +use Symfony\Component\Console\SingleCommandApplication; |
| 10 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 11 | + |
| 12 | +require_once dirname(__DIR__, 2).'/vendor/autoload.php'; |
| 13 | + |
| 14 | +$app = (new SingleCommandApplication('HuggingFace Model Listing')) |
| 15 | + ->setDescription('Lists all available models on HuggingFace') |
| 16 | + ->addOption('provider', 'p', InputOption::VALUE_REQUIRED, 'Name of the inference provider to filter models by') |
| 17 | + ->addOption('task', 't', InputOption::VALUE_REQUIRED, 'Name of the task to filter models by') |
| 18 | + ->setCode(function (InputInterface $input, ConsoleOutput $output) { |
| 19 | + $io = new SymfonyStyle($input, $output); |
| 20 | + $io->title('HuggingFace Model Listing'); |
| 21 | + |
| 22 | + $provider = $input->getOption('provider'); |
| 23 | + $task = $input->getOption('task'); |
| 24 | + |
| 25 | + $models = (new ApiClient())->models($provider, $task); |
| 26 | + |
| 27 | + if (0 === count($models)) { |
| 28 | + $io->error('No models found for the given provider and task.'); |
| 29 | + |
| 30 | + return Command::FAILURE; |
| 31 | + } |
| 32 | + |
| 33 | + $io->listing( |
| 34 | + array_map(fn (Model $model) => $model->getName(), $models) |
| 35 | + ); |
| 36 | + |
| 37 | + return Command::SUCCESS; |
| 38 | + }) |
| 39 | + ->run(); |
0 commit comments