Skip to content

Commit 54e13cb

Browse files
authored
refactor: add more output to example runner (#283)
1 parent bb02cef commit 54e13cb

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

example

+21-8
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ $app = (new SingleCommandApplication('LLM Chain Example Runner'))
3535
$process->start();
3636
}
3737

38-
$examplesRunning = fn () => array_reduce($exampleRuns, fn ($running, $example) => $running || $example['process']->isRunning(), false);
39-
$examplesSuccessful = fn () => array_reduce($exampleRuns, fn ($successful, $example) => $successful && $example['process']->isSuccessful(), true);
40-
4138
$section = $output->section();
4239
$renderTable = function () use ($exampleRuns, $section) {
4340
$section->clear();
@@ -64,21 +61,37 @@ $app = (new SingleCommandApplication('LLM Chain Example Runner'))
6461
$table->render();
6562
};
6663

64+
$examplesRunning = fn () => array_reduce($exampleRuns, fn ($running, $example) => $running || $example['process']->isRunning(), false);
6765
while ($examplesRunning()) {
6866
$renderTable();
6967
sleep(1);
7068
}
7169

7270
$renderTable();
73-
7471
$io->newLine();
75-
if (!$examplesSuccessful()) {
76-
$io->error('Some examples failed or were skipped!');
7772

78-
return Command::FAILURE;
73+
$successCount = array_reduce($exampleRuns, function ($count, $example) {
74+
if ($example['process']->isSuccessful() && strlen(trim($example['process']->getOutput())) > 0) {
75+
return $count + 1;
76+
}
77+
return $count;
78+
}, 0);
79+
80+
$totalCount = count($exampleRuns);
81+
82+
if ($successCount < $totalCount) {
83+
$io->warning(sprintf('%d out of %d examples ran successfully.', $successCount, $totalCount));
84+
} else {
85+
$io->success(sprintf('All %d examples ran successfully!', $totalCount));
7986
}
8087

81-
$io->success('All examples ran successfully!');
88+
foreach ($exampleRuns as $run) {
89+
if (!$run['process']->isSuccessful()) {
90+
$io->section('Error in ' . $run['example']->getFilename());
91+
$io->text($run['process']->getOutput());
92+
$io->text($run['process']->getErrorOutput());
93+
}
94+
}
8295

8396
return Command::SUCCESS;
8497
})

0 commit comments

Comments
 (0)