Skip to content

Commit 2a09fb0

Browse files
committed
feature #491 [Demo] Convert blog commands to invokable commands (OskarStark)
This PR was merged into the main branch. Discussion ---------- [Demo] Convert blog commands to invokable commands | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | -- | License | MIT Convert `EmbedCommand` and `QueryCommand` to use Symfony 7.3's invokable commands feature by removing `Command` inheritance and using `__invoke` method instead of `execute()`. Commits ------- f650b62 [Demo] Convert blog commands to invokable commands
2 parents a40908d + f650b62 commit 2a09fb0

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

demo/src/Blog/Command/EmbedCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,18 @@
1414
use App\Blog\Embedder;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17-
use Symfony\Component\Console\Input\InputInterface;
18-
use Symfony\Component\Console\Output\OutputInterface;
1917
use Symfony\Component\Console\Style\SymfonyStyle;
2018

2119
#[AsCommand('app:blog:embed', description: 'Create embeddings for Symfony blog and push to ChromaDB.')]
22-
final class EmbedCommand extends Command
20+
final class EmbedCommand
2321
{
2422
public function __construct(
2523
private readonly Embedder $embedder,
2624
) {
27-
parent::__construct();
2825
}
2926

30-
protected function execute(InputInterface $input, OutputInterface $output): int
27+
public function __invoke(SymfonyStyle $io): int
3128
{
32-
$io = new SymfonyStyle($input, $output);
3329
$io->title('Loading RSS of Symfony blog as embeddings into ChromaDB');
3430

3531
$this->embedder->embedBlog();

demo/src/Blog/Command/QueryCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,19 @@
1616
use Symfony\AI\Platform\PlatformInterface;
1717
use Symfony\Component\Console\Attribute\AsCommand;
1818
use Symfony\Component\Console\Command\Command;
19-
use Symfony\Component\Console\Input\InputInterface;
20-
use Symfony\Component\Console\Output\OutputInterface;
2119
use Symfony\Component\Console\Style\SymfonyStyle;
2220

2321
#[AsCommand('app:blog:query', description: 'Test command for querying the blog collection in Chroma DB.')]
24-
final class QueryCommand extends Command
22+
final class QueryCommand
2523
{
2624
public function __construct(
2725
private readonly Client $chromaClient,
2826
private readonly PlatformInterface $platform,
2927
) {
30-
parent::__construct();
3128
}
3229

33-
protected function execute(InputInterface $input, OutputInterface $output): int
30+
public function __invoke(SymfonyStyle $io): int
3431
{
35-
$io = new SymfonyStyle($input, $output);
3632
$io->title('Testing Chroma DB Connection');
3733

3834
$io->comment('Connecting to Chroma DB ...');

0 commit comments

Comments
 (0)