Skip to content

Commit c83ccdc

Browse files
committed
docs: fix example scripts for docker, class names and env var names
1 parent 6a98e92 commit c83ccdc

13 files changed

+58
-36
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
(new PhpCsFixer\Finder())
4545
->in([__DIR__.'/demo', __DIR__.'/examples', __DIR__.'/fixtures', __DIR__.'/src'])
4646
->append([__FILE__])
47-
->exclude(__DIR__.'/demo/var')
47+
->exclude('var')
4848
)
4949
;

examples/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ On top, the examples are used as integration tests to ensure that the components
77

88
## Running the examples
99

10+
For setting up and running the examples, you can either run them standalone or via the example runner. You find the
11+
commands for that in this section. Make sure to change into the `examples` directory before running the commands.
12+
13+
```bash
14+
cd examples
15+
```
16+
1017
### Setup
1118

1219
#### Dependencies
@@ -25,6 +32,15 @@ corresponding example you want to run.
2532

2633
_Now you can run examples standalone or via the example runner._
2734

35+
#### Store with Docker
36+
37+
Some of the store examples require locally running services, meaning that you need to have Docker installed and running
38+
to test these examples.
39+
40+
```bash
41+
docker compose up -d
42+
```
43+
2844
### Running examples standalone
2945

3046
Every example script is a standalone PHP script that can be run from the command line.
File renamed without changes.

examples/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"async-aws/bedrock-runtime": "^1.1",
99
"codewithkyrian/transformers": "^0.5.3",
1010
"doctrine/dbal": "^3.3|^4.0",
11+
"mrmysql/youtube-transcript": "^0.0.5",
1112
"php-http/discovery": "^1.20",
1213
"probots-io/pinecone-php": "^1.1",
1314
"psr/http-factory-implementation": "*",
@@ -38,6 +39,7 @@
3839
"allow-plugins": {
3940
"codewithkyrian/transformers-libsloader": true,
4041
"php-http/discovery": true
41-
}
42+
},
43+
"sort-packages": true
4244
}
4345
}

examples/google/embeddings.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111

1212
use Symfony\AI\Platform\Bridge\Google\Embeddings;
1313
use Symfony\AI\Platform\Bridge\Google\PlatformFactory;
14-
use Symfony\AI\Platform\Response\VectorResponse;
1514
use Symfony\Component\Dotenv\Dotenv;
1615

1716
require_once dirname(__DIR__).'/vendor/autoload.php';
1817
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
1918

20-
if (empty($_ENV['GOOGLE_API_KEY'])) {
21-
echo 'Please set the GOOGLE_API_KEY environment variable.'.\PHP_EOL;
19+
if (!isset($_ENV['GEMINI_API_KEY'])) {
20+
echo 'Please set the GEMINI_API_KEY environment variable.'.\PHP_EOL;
2221
exit(1);
2322
}
2423

25-
$platform = PlatformFactory::create($_ENV['GOOGLE_API_KEY']);
24+
$platform = PlatformFactory::create($_ENV['GEMINI_API_KEY']);
2625
$embeddings = new Embeddings();
2726

2827
$response = $platform->request($embeddings, <<<TEXT
@@ -31,6 +30,4 @@
3130
country was very peaceful and prosperous. The people lived happily ever after.
3231
TEXT);
3332

34-
assert($response instanceof VectorResponse);
35-
36-
echo 'Dimensions: '.$response->getContent()[0]->getDimensions().\PHP_EOL;
33+
echo 'Dimensions: '.$response->asVectors()[0]->getDimensions().\PHP_EOL;

examples/google/server-tools.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use PhpLlm\LlmChain\Chain\Chain;
13-
use PhpLlm\LlmChain\Chain\Toolbox\ChainProcessor;
14-
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Clock;
15-
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
16-
use PhpLlm\LlmChain\Platform\Bridge\Google\Gemini;
17-
use PhpLlm\LlmChain\Platform\Bridge\Google\PlatformFactory;
18-
use PhpLlm\LlmChain\Platform\Message\Message;
19-
use PhpLlm\LlmChain\Platform\Message\MessageBag;
12+
use Symfony\AI\Agent\Agent;
13+
use Symfony\AI\Agent\Toolbox\AgentProcessor;
14+
use Symfony\AI\Agent\Toolbox\Tool\Clock;
15+
use Symfony\AI\Agent\Toolbox\Toolbox;
16+
use Symfony\AI\Platform\Bridge\Google\Gemini;
17+
use Symfony\AI\Platform\Bridge\Google\PlatformFactory;
18+
use Symfony\AI\Platform\Message\Message;
19+
use Symfony\AI\Platform\Message\MessageBag;
2020
use Symfony\Component\Dotenv\Dotenv;
2121

22-
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
23-
(new Dotenv())->loadEnv(dirname(__DIR__, 2).'/.env');
22+
require_once dirname(__DIR__).'/vendor/autoload.php';
23+
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2424

2525
if (!isset($_ENV['GEMINI_API_KEY'])) {
2626
echo 'Please set the GEMINI_API_KEY environment variable.'.\PHP_EOL;
@@ -33,8 +33,8 @@
3333
$llm = new Gemini('gemini-2.5-pro-preview-03-25', ['server_tools' => ['url_context' => true], 'temperature' => 1.0]);
3434

3535
$toolbox = Toolbox::create(new Clock());
36-
$processor = new ChainProcessor($toolbox);
37-
$chain = new Chain($platform, $llm);
36+
$processor = new AgentProcessor($toolbox);
37+
$agent = new Agent($platform, $llm);
3838

3939
$messages = new MessageBag(
4040
Message::ofUser(
@@ -44,6 +44,6 @@
4444
),
4545
);
4646

47-
$response = $chain->call($messages);
47+
$response = $agent->call($messages);
4848

4949
echo $response->getContent().\PHP_EOL;

examples/google/structured-output-clock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
use Symfony\Component\Clock\Clock as SymfonyClock;
2222
use Symfony\Component\Dotenv\Dotenv;
2323

24-
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
25-
(new Dotenv())->loadEnv(dirname(__DIR__, 2).'/.env');
24+
require_once dirname(__DIR__).'/vendor/autoload.php';
25+
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2626

2727
if (!isset($_ENV['GEMINI_API_KEY'])) {
2828
echo 'Please set the GEMINI_API_KEY environment variable.'.\PHP_EOL;

examples/google/structured-output-math.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use Symfony\AI\Platform\Message\MessageBag;
1919
use Symfony\Component\Dotenv\Dotenv;
2020

21-
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
22-
(new Dotenv())->loadEnv(dirname(__DIR__, 2).'/.env');
21+
require_once dirname(__DIR__).'/vendor/autoload.php';
22+
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2323

2424
if (!isset($_ENV['GEMINI_API_KEY'])) {
2525
echo 'Please set the GEMINI_API_KEY environment variable.'.\PHP_EOL;

examples/store/mariadb-similarity-search-gemini.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
use Symfony\Component\Dotenv\Dotenv;
3030
use Symfony\Component\Uid\Uuid;
3131

32-
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
33-
(new Dotenv())->loadEnv(dirname(__DIR__, 2).'/.env');
32+
require_once dirname(__DIR__).'/vendor/autoload.php';
33+
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
3434

3535
if (!isset($_ENV['GEMINI_API_KEY'], $_ENV['MARIADB_URI'])) {
3636
echo 'Please set GEMINI_API_KEY and MARIADB_URI environment variables.'.\PHP_EOL;

examples/store/mariadb-similarity-search.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use Doctrine\DBAL\DriverManager;
1313
use Doctrine\DBAL\Tools\DsnParser;
14+
use Symfony\AI\Agent\Agent;
15+
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1416
use Symfony\AI\Agent\Toolbox\Tool\SimilaritySearch;
1517
use Symfony\AI\Agent\Toolbox\Toolbox;
1618
use Symfony\AI\Platform\Bridge\OpenAI\Embeddings;
@@ -26,8 +28,8 @@
2628
use Symfony\Component\Dotenv\Dotenv;
2729
use Symfony\Component\Uid\Uuid;
2830

29-
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
30-
(new Dotenv())->loadEnv(dirname(__DIR__, 2).'/.env');
31+
require_once dirname(__DIR__).'/vendor/autoload.php';
32+
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
3133

3234
if (!isset($_ENV['OPENAI_API_KEY'], $_ENV['MARIADB_URI'])) {
3335
echo 'Please set OPENAI_API_KEY and MARIADB_URI environment variables.'.\PHP_EOL;
@@ -71,13 +73,13 @@
7173

7274
$similaritySearch = new SimilaritySearch($platform, $embeddings, $store);
7375
$toolbox = Toolbox::create($similaritySearch);
74-
$processor = new ChainProcessor($toolbox);
75-
$chain = new Chain($platform, $model, [$processor], [$processor]);
76+
$processor = new AgentProcessor($toolbox);
77+
$agent = new Agent($platform, $model, [$processor], [$processor]);
7678

7779
$messages = new MessageBag(
7880
Message::forSystem('Please answer all user questions only using SimilaritySearch function.'),
7981
Message::ofUser('Which movie fits the theme of the mafia?')
8082
);
81-
$response = $chain->call($messages);
83+
$response = $agent->call($messages);
8284

8385
echo $response->getContent().\PHP_EOL;

0 commit comments

Comments
 (0)