Skip to content

chore: extend example runner to target subdirs only #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\SingleCommandApplication;
Expand All @@ -15,12 +16,23 @@ require_once __DIR__.'/vendor/autoload.php';

$app = (new SingleCommandApplication('LLM Chain Example Runner'))
->setDescription('Runs all LLM Chain examples in folder examples/')
->addArgument('subdirectory', InputArgument::OPTIONAL, 'Subdirectory to run examples from, e.g. "anthropic" or "huggingface".')
->setCode(function (InputInterface $input, ConsoleOutput $output) {
$io = new SymfonyStyle($input, $output);
$io->title('LLM Chain Examples');

$directory = __DIR__.'/examples';

if ($subdirectory = $input->getArgument('subdirectory')) {
$directory .= '/'.$subdirectory;
if (!is_dir($directory)) {
$io->error(sprintf('Subdirectory "%s" does not exist.', $subdirectory));
return Command::FAILURE;
}
}

$examples = (new Finder())
->in(__DIR__.'/examples')
->in($directory)
->name('*.php')
->sortByName()
->files();
Expand Down