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

Commit 5db2d46

Browse files
committed
feat: adopt after release 0.8 & 0.9
1 parent 1a3d710 commit 5db2d46

17 files changed

+602
-416
lines changed

README.md

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,48 @@ composer require php-llm/llm-chain-bundle
1010

1111
## Configuration
1212

13+
### Simple Example with OpenAI
14+
1315
```yaml
1416
# config/packages/llm_chain.yaml
1517
llm_chain:
16-
platforms:
17-
azure_gpt:
18-
type: 'azure'
19-
base_url: '%env(AZURE_OPENAI_BASEURL)%'
20-
deployment: '%env(AZURE_OPENAI_GPT)%'
21-
api_key: '%env(AZURE_OPENAI_KEY)%'
22-
version: '%env(AZURE_OPENAI_VERSION)%'
23-
azure_embeddings:
24-
type: 'azure'
25-
base_url: '%env(AZURE_OPENAI_BASEURL)%'
26-
deployment: '%env(AZURE_OPENAI_EMBEDDINGS)%'
27-
api_key: '%env(AZURE_OPENAI_KEY)%'
28-
version: '%env(AZURE_OPENAI_VERSION)%'
18+
platform:
2919
openai:
30-
type: 'openai'
3120
api_key: '%env(OPENAI_API_KEY)%'
32-
llms:
33-
azure_gpt:
34-
platform: 'azure_gpt'
35-
original_gpt:
36-
platform: 'openai'
37-
embeddings:
38-
azure_embeddings:
39-
platform: 'azure_embeddings'
40-
original_embeddings:
41-
platform: 'openai'
42-
stores:
43-
azure_search:
44-
engine: 'azure-search'
45-
api_key: '%env(AZURE_SEARCH_KEY)%'
46-
endpoint: '%env(AZURE_SEARCH_ENDPOINT)%'
47-
index_name: '%env(AZURE_SEARCH_INDEX)%'
48-
api_version: '2024-07-01'
49-
chroma_db:
50-
engine: 'chroma-db'
51-
collection_name: '%env(CHROMA_COLLECTION)%'
52-
mongodb:
53-
engine: 'mongodb'
54-
database_name: '%env(MONGODB_DATABASE)%'
55-
collection_name: '%env(MONGODB_COLLECTION)%'
56-
index_name: '%env(MONGODB_INDEX)%'
57-
vector_field_name: 'vector'
58-
bulk_write: false
59-
pinecone:
60-
engine: 'pinecone'
61-
namespace: 'partition'
62-
filter: { 'key' : 'value' }
63-
top_k: 5
21+
chain:
22+
default:
23+
model:
24+
name: 'GPT'
25+
```
26+
27+
### Advanced Example with Anthropic, Azure and multiple chains
28+
```yaml
29+
# config/packages/llm_chain.yaml
30+
llm_chain:
31+
platform:
32+
anthropic:
33+
api_key: '%env(ANTHROPIC_API_KEY)%'
34+
azure:
35+
# multiple deployments possible
36+
gpt_deployment:
37+
base_url: '%env(AZURE_OPENAI_BASEURL)%'
38+
deployment: '%env(AZURE_OPENAI_GPT)%'
39+
api_key: '%env(AZURE_OPENAI_KEY)%'
40+
api_version: '%env(AZURE_GPT_VERSION)%'
41+
chain:
42+
rag:
43+
platform: 'llm_chain.platform.azure.gpt_deployment'
44+
model:
45+
name: 'GPT'
46+
version: 'gpt-4o-mini'
47+
tools:
48+
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch'
49+
research:
50+
platform: 'llm_chain.platform.anthropic'
51+
model:
52+
name: 'Claude'
53+
tools:
54+
- 'PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia'
6455
```
6556
6657
## Usage
@@ -69,12 +60,14 @@ llm_chain:
6960
7061
Use the `Chain` service to leverage GPT:
7162
```php
72-
use PhpLlm\LlmChain\Chat;
63+
use PhpLlm\LlmChain\ChainInterface;
64+
use PhpLlm\LlmChain\Model\Message\Message;
65+
use PhpLlm\LlmChain\Model\Message\MessageBag;
7366
7467
final readonly class MyService
7568
{
7669
public function __construct(
77-
private Chain $chain,
70+
private ChainInterface $chain,
7871
) {
7972
}
8073
@@ -99,18 +92,18 @@ services:
9992
autowire: true
10093
autoconfigure: true
10194
102-
PhpLlm\LlmChain\ToolBox\Tool\Clock: ~
103-
PhpLlm\LlmChain\ToolBox\Tool\OpenMeteo: ~
104-
PhpLlm\LlmChain\ToolBox\Tool\SerpApi:
95+
PhpLlm\LlmChain\Chain\ToolBox\Tool\Clock: ~
96+
PhpLlm\LlmChain\Chain\ToolBox\Tool\OpenMeteo: ~
97+
PhpLlm\LlmChain\Chain\ToolBox\Tool\SerpApi:
10598
$apiKey: '%env(SERP_API_KEY)%'
106-
PhpLlm\LlmChain\ToolBox\Tool\SimilaritySearch: ~
107-
PhpLlm\LlmChain\ToolBox\Tool\Wikipedia: ~
108-
PhpLlm\LlmChain\ToolBox\Tool\YouTubeTranscriber: ~
99+
PhpLlm\LlmChain\Chain\ToolBox\Tool\SimilaritySearch: ~
100+
PhpLlm\LlmChain\Chain\ToolBox\Tool\Wikipedia: ~
101+
PhpLlm\LlmChain\Chain\ToolBox\Tool\YouTubeTranscriber: ~
109102
```
110103

111104
Custom tools can be registered by using the `#[AsTool]` attribute:
112105
```php
113-
use PhpLlm\LlmChain\ToolBox\AsTool;
106+
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
114107
115108
#[AsTool('company_name', 'Provides the name of your company')]
116109
final class CompanyName

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": ">=8.2",
14-
"php-llm/llm-chain": "0.7.*",
14+
"php-llm/llm-chain": "^0.9.3",
1515
"symfony/config": "^6.4 || ^7.0",
1616
"symfony/dependency-injection": "^6.4 || ^7.0",
1717
"symfony/framework-bundle": "^6.4 || ^7.0"

profiler.png

-23.8 KB
Loading

src/DependencyInjection/Configuration.php

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpLlm\LlmChainBundle\DependencyInjection;
66

7+
use PhpLlm\LlmChain\PlatformInterface;
78
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
89
use Symfony\Component\Config\Definition\ConfigurationInterface;
910

@@ -16,61 +17,82 @@ public function getConfigTreeBuilder(): TreeBuilder
1617

1718
$rootNode
1819
->children()
19-
->arrayNode('platforms')
20-
->normalizeKeys(false)
21-
->useAttributeAsKey('name')
22-
->arrayPrototype()
23-
->children()
24-
->enumNode('type')->values(['openai', 'azure'])->isRequired()->end()
25-
->scalarNode('api_key')->isRequired()->end()
26-
->scalarNode('base_url')->end()
27-
->scalarNode('deployment')->end()
28-
->scalarNode('version')->info('The used API version')->end()
20+
->arrayNode('platform')
21+
->children()
22+
->arrayNode('anthropic')
23+
->children()
24+
->scalarNode('api_key')->isRequired()->end()
25+
->scalarNode('version')->defaultNull()->end()
26+
->end()
27+
->end()
28+
->arrayNode('azure')
29+
->normalizeKeys(false)
30+
->useAttributeAsKey('name')
31+
->arrayPrototype()
32+
->children()
33+
->scalarNode('api_key')->isRequired()->end()
34+
->scalarNode('base_url')->isRequired()->end()
35+
->scalarNode('deployment')->isRequired()->end()
36+
->scalarNode('api_version')->info('The used API version')->end()
37+
->end()
38+
->end()
39+
->end()
40+
->arrayNode('openai')
41+
->children()
42+
->scalarNode('api_key')->isRequired()->end()
43+
->end()
2944
->end()
3045
->end()
3146
->end()
32-
->arrayNode('llms')
47+
->arrayNode('chain')
3348
->normalizeKeys(false)
3449
->useAttributeAsKey('name')
3550
->arrayPrototype()
3651
->children()
37-
->scalarNode('platform')->end()
52+
->scalarNode('platform')->defaultValue(PlatformInterface::class)->end()
53+
->arrayNode('model')
54+
->children()
55+
->scalarNode('name')->isRequired()->end()
56+
->scalarNode('version')->defaultNull()->end()
57+
->arrayNode('options')
58+
->scalarPrototype()->end()
59+
->end()
60+
->end()
61+
->end()
62+
->arrayNode('tools')
63+
->scalarPrototype()->end()
64+
->end()
3865
->end()
3966
->end()
4067
->end()
41-
->arrayNode('embeddings')
68+
->arrayNode('embedder')
4269
->normalizeKeys(false)
4370
->useAttributeAsKey('name')
4471
->arrayPrototype()
4572
->children()
46-
->scalarNode('platform')->end()
73+
->arrayNode('model')
74+
->children()
75+
->scalarNode('name')->isRequired()->end()
76+
->scalarNode('version')->defaultNull()->end()
77+
->arrayNode('options')->end()
78+
->end()
79+
->end()
4780
->end()
4881
->end()
4982
->end()
50-
->arrayNode('stores')
51-
->normalizeKeys(false)
52-
->useAttributeAsKey('name')
53-
->arrayPrototype()
54-
->children()
55-
->enumNode('engine')->values(['azure-search', 'chroma-db', 'mongodb', 'pinecone'])->isRequired()->end()
56-
// Azure AI Search & MongoDB
57-
->scalarNode('index_name')->end()
58-
// Azure AI Search
59-
->scalarNode('api_key')->end()
60-
->scalarNode('api_version')->end()
61-
->scalarNode('endpoint')->end()
62-
// ChromaDB & MongoDB
63-
->scalarNode('collection_name')->end()
64-
// MongoDB
65-
->scalarNode('database_name')->end()
66-
->scalarNode('vector_field_name')->defaultValue('vector')->end()
67-
->booleanNode('bulk_write')->defaultValue(false)->end()
68-
// Pinecone
69-
->arrayNode('filter')->end()
70-
->scalarNode('namespace')->end()
71-
->scalarNode('top_k')->end()
83+
->arrayNode('store')
84+
->children()
85+
->arrayNode('chroma_db')
86+
->normalizeKeys(false)
87+
->useAttributeAsKey('name')
88+
->arrayPrototype()
89+
->children()
90+
->scalarNode('host')->isRequired()->end()
91+
->scalarNode('collection')->isRequired()->end()
92+
->end()
7293
->end()
7394
->end()
95+
->end()
7496
->end()
7597
;
7698

0 commit comments

Comments
 (0)