Skip to content

Commit 8c096f0

Browse files
authored
chore: clean up after bundle 0.9 release (#7)
1 parent f259ab5 commit 8c096f0

File tree

6 files changed

+59
-163
lines changed

6 files changed

+59
-163
lines changed

assets/styles/app.css

+8
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,18 @@ body {
7272

7373
.rag & {
7474
background: #dc8b6e;
75+
76+
a {
77+
color: #f4e973;
78+
}
7579
}
7680

7781
.youtube & {
7882
background: #df3535;
83+
84+
a {
85+
color: #3e2926;
86+
}
7987
}
8088

8189
.wikipedia & {

composer.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"codewithkyrian/chromadb-php": "^0.3.0",
1111
"league/commonmark": "^2.6",
1212
"php-llm/llm-chain": "^0.9.3",
13-
"php-llm/llm-chain-bundle": "dev-feat-prepare-0.8",
13+
"php-llm/llm-chain-bundle": "^0.9",
1414
"phpdocumentor/reflection-docblock": "^5.5",
1515
"phpstan/phpdoc-parser": "^1.33",
1616
"runtime/frankenphp-symfony": "^0.2.0",
@@ -93,8 +93,6 @@
9393
"App\\Tests\\": "tests/"
9494
}
9595
},
96-
"minimum-stability": "stable",
97-
"prefer-stable": true,
9896
"scripts": {
9997
"post-install-cmd": [
10098
"@auto-scripts"

composer.lock

+11-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/packages/llm_chain.yaml

+30-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
llm_chain:
22
platform:
3+
# anthropic:
4+
# api_key: '%env(ANTHROPIC_API_KEY)%'
5+
# azure:
6+
# gpt_deployment:
7+
# base_url: '%env(AZURE_GPT_BASE_URL)%'
8+
# deployment: '%env(AZURE_GPT_DEPLOYMENT)%'
9+
# api_key: '%env(AZURE_GPT_API_KEY)%'
10+
# api_version: '%env(AZURE_GPT_VERSION)%'
11+
# embeddings_deployment:
12+
# base_url: '%env(AZURE_EMBEDDINGS_BASE_URL)%'
13+
# deployment: '%env(AZURE_EMBEDDINGS_DEPLOYMENT)%'
14+
# api_key: '%env(AZURE_EMBEDDINGS_API_KEY)%'
15+
# api_version: '%env(AZURE_EMBEDDINGS_VERSION)%'
316
openai:
417
api_key: '%env(OPENAI_API_KEY)%'
518
chain:
619
rag:
20+
# platform: 'llm_chain.platform.anthropic'
721
model:
822
name: 'GPT'
923
version: 'gpt-4o-mini'
@@ -18,23 +32,34 @@ llm_chain:
1832
model:
1933
name: 'GPT'
2034
version: 'gpt-4o-mini'
35+
options:
36+
temperature: 0.5
2137
tools:
2238
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia'
2339
store:
2440
chroma_db:
2541
symfonycon:
26-
host: '%env(CHROMADB_HOST)%'
2742
collection: 'symfony_blog'
43+
# web_summer_camp:
44+
# host: '%env(CHROMADB_HOST)%'
45+
# collection: 'wsc_program'
46+
embedder:
47+
default:
48+
# platform: 'llm_chain.platform.anthropic'
49+
# store: 'llm_chain.store.chroma_db.symfonycon'
50+
model:
51+
name: 'Embeddings'
52+
version: 'text-embedding-ada-002'
2853

2954
services:
3055
_defaults:
3156
autowire: true
3257
autoconfigure: true
3358

59+
# PhpLlm\LlmChain\Chain\ToolBox\Tool\Clock: ~
60+
# PhpLlm\LlmChain\Chain\ToolBox\Tool\OpenMeteo: ~
61+
# PhpLlm\LlmChain\Chain\ToolBox\Tool\SerpApi:
62+
# $apiKey: '%env(SERP_API_KEY)%'
3463
PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia: ~
3564
PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch: ~
3665

37-
# TODO: move to configuration
38-
PhpLlm\LlmChain\Bridge\OpenAI\Embeddings: ~
39-
PhpLlm\LlmChain\Model\EmbeddingsModel: '@PhpLlm\LlmChain\Bridge\OpenAI\Embeddings'
40-

src/Blog/Embedder.php

+9-41
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,25 @@
44

55
namespace App\Blog;
66

7-
use Codewithkyrian\ChromaDB\Client;
8-
use PhpLlm\LlmChain\Bridge\OpenAI\Embeddings;
9-
use PhpLlm\LlmChain\Document\Vector;
10-
use PhpLlm\LlmChain\Model\Response\AsyncResponse;
11-
use PhpLlm\LlmChain\Model\Response\VectorResponse;
12-
use PhpLlm\LlmChain\PlatformInterface;
7+
use PhpLlm\LlmChain\Document\Metadata;
8+
use PhpLlm\LlmChain\Document\TextDocument;
9+
use PhpLlm\LlmChain\Embedder as LlmChainEmbedder;
1310

1411
final readonly class Embedder
1512
{
1613
public function __construct(
1714
private Loader $loader,
18-
private PlatformInterface $platform,
19-
private Client $chromaClient,
15+
private LlmChainEmbedder $embedder,
2016
) {
2117
}
2218

2319
public function embedBlog(): void
2420
{
25-
$posts = $this->loader->load();
26-
$vectors = $this->createEmbeddings($posts);
27-
$this->pushToChromaDB($posts, $vectors);
28-
}
29-
30-
/**
31-
* @param Post[] $posts
32-
*
33-
* @return Vector[]
34-
*/
35-
private function createEmbeddings(array $posts): array
36-
{
37-
$texts = array_map(fn (Post $post) => $post->toString(), $posts);
38-
$response = $this->platform->request(new Embeddings(), $texts);
39-
40-
assert($response instanceof AsyncResponse);
41-
$response = $response->unwrap();
42-
assert($response instanceof VectorResponse);
43-
44-
return $response->getContent();
45-
}
46-
47-
/**
48-
* @param Post[] $posts
49-
* @param Vector[] $vectors
50-
*/
51-
private function pushToChromaDB(array $posts, array $vectors): void
52-
{
53-
$collection = $this->chromaClient->getOrCreateCollection('symfony_blog');
54-
55-
$ids = array_map(fn (Post $post) => $post->id, $posts);
56-
$vectors = array_map(fn (Vector $vector) => $vector->getData(), $vectors);
21+
$documents = [];
22+
foreach ($this->loader->load() as $post) {
23+
$documents[] = new TextDocument($post->id, $post->toString(), new Metadata($post->toArray()));
24+
}
5725

58-
$collection->upsert($ids, $vectors, $posts);
26+
$this->embedder->embed($documents);
5927
}
6028
}

tests/Blog/EmbedderTest.php

-101
This file was deleted.

0 commit comments

Comments
 (0)