Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit aae92e6

Browse files
committed
refactor: follow up on example structure
1 parent 7cb6f6d commit aae92e6

27 files changed

+70
-86
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ docker compose exec app bin/console app:blog:embed -vv
7979
Now you should be able to run the test command and get some results:
8080

8181
```shell
82-
docker compose exec app bin/console app:chroma:test
82+
docker compose exec app bin/console app:blog:query
8383
```
8484

8585
**Don't forget to set up the project in your favorite IDE or editor.**
@@ -89,4 +89,4 @@ docker compose exec app bin/console app:chroma:test
8989
* The chatbot application is a simple and small Symfony 7.2 application.
9090
* The UI is coupled to a [Twig LiveComponent](https://symfony.com/bundles/ux-live-component/current/index.html), that integrates different `Chat` implementations on top of the user's session.
9191
* You can reset the chat context by hitting the `Reset` button in the top right corner.
92-
* You find three different usage scenarios in the upper navbar.
92+
* You find three different usage scenarios in the upper navbar.

assets/icons/entypo/chat.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

assets/icons/mdi/symfony.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/icons/mingcute/ai-fill.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

assets/styles/app.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
body {
22
min-height: 100vh;
3-
&.rag, .rag .card-img-top {
3+
&.blog, .blog .card-img-top {
44
background: rgb(220,139,110);
55
background: linear-gradient(0deg, rgba(220,139,110,1) 0%, rgba(244,233,115,1) 100%);
66
}
@@ -53,7 +53,7 @@ body {
5353
border-radius: 10px 10px 0 10px;
5454
color: #292929;
5555

56-
.rag & {
56+
.blog & {
5757
background: #f4e973;
5858
}
5959

@@ -70,7 +70,7 @@ body {
7070
.bot-message {
7171
border-radius: 10px 10px 10px 0;
7272

73-
.rag & {
73+
.blog & {
7474
background: #dc8b6e;
7575

7676
a {
@@ -103,12 +103,12 @@ body {
103103
height: 50px;
104104
border: 2px solid white;
105105

106-
.rag &.bot {
106+
.blog &.bot {
107107
outline: 1px solid #ffdacc;
108108
background: #ffdacc;
109109
}
110110

111-
.rag &.user {
111+
.blog &.user {
112112
outline: 1px solid #fffad1;
113113
background: #fffad1;
114114
}
@@ -141,7 +141,7 @@ body {
141141

142142
#welcome {
143143
h4 {
144-
.rag & {
144+
.blog & {
145145
color: #f97b62;
146146
}
147147

@@ -152,7 +152,7 @@ body {
152152
}
153153

154154
#chat-reset, #chat-submit {
155-
.rag &:hover {
155+
.blog &:hover {
156156
background: #f97b62;
157157
border-color: #f97b62;
158158
}

config/packages/llm_chain.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ llm_chain:
1616
openai:
1717
api_key: '%env(OPENAI_API_KEY)%'
1818
chain:
19-
rag:
19+
blog:
2020
# platform: 'llm_chain.platform.anthropic'
2121
model:
2222
name: 'GPT'

config/routes.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ index:
44
defaults:
55
template: 'index.html.twig'
66

7-
rag:
8-
path: '/rag'
7+
blog:
8+
path: '/blog'
99
controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController'
1010
defaults:
11-
template: 'chat/rag.html.twig'
11+
template: 'blog/chat.html.twig'
1212

1313
youtube:
1414
path: '/youtube'
1515
controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController'
1616
defaults:
17-
template: 'chat/youtube.html.twig'
17+
template: 'youtube/chat.html.twig'
1818

1919
wikipedia:
2020
path: '/wikipedia'
2121
controller: 'Symfony\Bundle\FrameworkBundle\Controller\TemplateController'
2222
defaults:
23-
template: 'chat/wikipedia.html.twig'
23+
template: 'wikipedia/chat.html.twig'

src/Blog/Chat/Blog.php renamed to src/Blog/Chat.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Blog\Chat;
5+
namespace App\Blog;
66

77
use PhpLlm\LlmChain\ChainInterface;
88
use PhpLlm\LlmChain\Model\Message\Message;
@@ -11,13 +11,13 @@
1111
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1212
use Symfony\Component\HttpFoundation\RequestStack;
1313

14-
final class Blog
14+
final class Chat
1515
{
16-
private const SESSION_KEY = 'rag-chat';
16+
private const SESSION_KEY = 'blog-chat';
1717

1818
public function __construct(
1919
private readonly RequestStack $requestStack,
20-
#[Autowire(service: 'llm_chain.chain.rag')]
20+
#[Autowire(service: 'llm_chain.chain.blog')]
2121
private readonly ChainInterface $chain,
2222
) {
2323
}

src/Blog/Command/BlogEmbedCommand.php renamed to src/Blog/Command/EmbedCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\Console\Style\SymfonyStyle;
1313

1414
#[AsCommand('app:blog:embed', description: 'Create embeddings for Symfony blog and push to ChromaDB.')]
15-
final class BlogEmbedCommand extends Command
15+
final class EmbedCommand extends Command
1616
{
1717
public function __construct(
1818
private readonly Embedder $embedder,

src/Command/ChromaTestCommand.php renamed to src/Blog/Command/QueryCommand.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Command;
5+
namespace App\Blog\Command;
66

77
use Codewithkyrian\ChromaDB\Client;
88
use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings;
@@ -15,8 +15,8 @@
1515
use Symfony\Component\Console\Output\OutputInterface;
1616
use Symfony\Component\Console\Style\SymfonyStyle;
1717

18-
#[AsCommand('app:chroma:test', description: 'Testing Chroma DB connection.')]
19-
final class ChromaTestCommand extends Command
18+
#[AsCommand('app:blog:query', description: 'Test command for querying the blog collection in Chroma DB.')]
19+
final class QueryCommand extends Command
2020
{
2121
public function __construct(
2222
private readonly Client $chromaClient,
@@ -31,23 +31,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3131
$io->title('Testing Chroma DB Connection');
3232

3333
$io->comment('Connecting to Chroma DB ...');
34-
35-
// Check current ChromaDB version
36-
$version = $this->chromaClient->version();
37-
38-
// Get WSC Collection
3934
$collection = $this->chromaClient->getOrCreateCollection('symfony_blog');
40-
4135
$io->table(['Key', 'Value'], [
42-
['ChromaDB Version', $version],
36+
['ChromaDB Version', $this->chromaClient->version()],
4337
['Collection Name', $collection->name],
4438
['Collection ID', $collection->id],
4539
['Total Documents', $collection->count()],
4640
]);
4741

48-
$io->comment('Searching for content about "New Symfony Features" ...');
42+
$search = $io->ask('What do you want to know about?', 'New Symfony Features');
43+
$io->comment(sprintf('Converting "%s" to vector & searching in Chroma DB ...', $search));
44+
$io->comment("Results are limited to 4 most similar documents.");
4945

50-
$platformResponse = $this->platform->request(new Embeddings(), 'New Symfony Features');
46+
$platformResponse = $this->platform->request(new Embeddings(), $search);
5147
assert($platformResponse instanceof AsyncResponse);
5248
$platformResponse = $platformResponse->unwrap();
5349
assert($platformResponse instanceof VectorResponse);
@@ -62,16 +58,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6258
return Command::FAILURE;
6359
}
6460

65-
$io->table(['ID', 'Title'], [
66-
/* @phpstan-ignore-next-line */
67-
[$queryResponse->ids[0][0], $queryResponse->metadatas[0][0]['title']],
68-
/* @phpstan-ignore-next-line */
69-
[$queryResponse->ids[0][1], $queryResponse->metadatas[0][1]['title']],
70-
/* @phpstan-ignore-next-line */
71-
[$queryResponse->ids[0][2], $queryResponse->metadatas[0][2]['title']],
72-
/* @phpstan-ignore-next-line */
73-
[$queryResponse->ids[0][3], $queryResponse->metadatas[0][3]['title']],
74-
]);
61+
foreach ($queryResponse->ids[0] as $i => $id) {
62+
$io->section($queryResponse->metadatas[0][$i]['title']);
63+
$io->block($queryResponse->metadatas[0][$i]['description']);
64+
}
7565

7666
$io->success('Chroma DB Connection & Similarity Search Test Successful!');
7767

0 commit comments

Comments
 (0)