Skip to content

Commit c26add7

Browse files
committed
chore: move example runner into examples folder including composer setup for examples
1 parent 7b7dc8c commit c26add7

File tree

105 files changed

+426
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+426
-186
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
.doctor-rst.cache
2-
.env.local
32
.php-cs-fixer.cache
43
.phpunit.cache
5-
.transformers-cache
64

75
composer.lock
86
vendor

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
->setRiskyAllowed(true)
4343
->setFinder(
4444
(new PhpCsFixer\Finder())
45-
->in([__DIR__.'/src', __DIR__.'/examples'])
45+
->in([__DIR__.'/src', __DIR__.'/examples', __DIR__.'/fixtures'])
4646
->append([__FILE__])
4747
->notPath('#/Fixtures/#')
4848
)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,8 @@ foreach ($responses as $response) {
683683
684684
#### Code Examples
685685

686-
1. [Parallel GPT Calls](examples/parallel-chat-gpt.php)
687-
1. [Parallel Embeddings Calls](examples/parallel-embeddings.php)
686+
1. [Parallel GPT Calls](examples/misc/parallel-chat-gpt.php)
687+
1. [Parallel Embeddings Calls](examples/misc/parallel-embeddings.php)
688688

689689
> [!NOTE]
690690
> Please be aware that some embedding models also support batch processing out of the box.

composer.json

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,13 @@
55
"keywords": [
66
"dev"
77
],
8-
"minimum-stability": "dev",
9-
"prefer-stable": true,
108
"require-dev": {
119
"php": ">=8.2",
12-
"async-aws/bedrock-runtime": "^0.1.0",
13-
"codewithkyrian/transformers": "^0.5.3",
1410
"php-cs-fixer/shim": "^3.75",
15-
"probots-io/pinecone-php": "^1.0",
16-
"symfony/ai-agent": "@dev",
17-
"symfony/ai-platform": "@dev",
18-
"symfony/ai-store": "@dev",
19-
"symfony/console": "^6.4|^7.0",
20-
"symfony/css-selector": "^6.4|^7.0",
21-
"symfony/dom-crawler": "^6.4|^7.0",
22-
"symfony/dotenv": "^6.4|^7.0",
23-
"symfony/event-dispatcher": "^6.4|^7.0",
24-
"symfony/filesystem": "^6.4|^7.0",
2511
"symfony/finder": "^6.4|^7.0",
26-
"symfony/process": "^6.4|^7.0",
27-
"symfony/var-dumper": "^6.4|^7.0"
28-
},
29-
"repositories": [
30-
{ "type": "path", "url": "src/agent" },
31-
{ "type": "path", "url": "src/platform" },
32-
{ "type": "path", "url": "src/store" }
33-
],
34-
"autoload-dev": {
35-
"psr-4": {
36-
"Symfony\\AI\\Fixtures\\": "fixtures/"
37-
}
12+
"symfony/process": "^6.4|^7.0"
3813
},
3914
"config": {
40-
"sort-packages": true,
41-
"allow-plugins": {
42-
"codewithkyrian/transformers-libsloader": true
43-
}
15+
"sort-packages": true
4416
}
4517
}

.env renamed to examples/.env

File renamed without changes.

examples/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env.local
2+
.transformers-cache
3+
composer.lock
4+
vendor

examples/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Symfony AI Examples
2+
3+
This directory contains various examples of how to use the Symfony AI components. They are meant to provide a
4+
reference implementation to help you get started.
5+
6+
On top, the examples are used as integration tests to ensure that the components work as expected.
7+
8+
## Running the examples
9+
10+
### Setup
11+
12+
#### Dependencies
13+
14+
Before running the examples, you need to install the dependencies. You can do this by running:
15+
16+
```bash
17+
composer install
18+
```
19+
20+
#### Configuration
21+
22+
Depending on the examples you want to run, you may need to configure the needed API keys. Therefore, you need to create a
23+
`.env.local` file in the root of the examples directory. This file should contain the environment variables for the
24+
corresponding example you want to run.
25+
26+
_Now you can run examples standalone or via the example runner._
27+
28+
### Running examples standalone
29+
30+
Every example script is a standalone PHP script that can be run from the command line.
31+
You can run an example by executing the following command:
32+
33+
```bash
34+
php openai/openai/chat.php
35+
```
36+
37+
### Running examples via the example runner
38+
39+
You can also run the examples via the example runner, which takes care of running the examples parallel in
40+
sub-processes. This is useful if you are contributing to the Symfony AI components and want to ensure that all examples
41+
work as expected.
42+
43+
You can run the example runner by executing the following command:
44+
45+
```bash
46+
./runner
47+
```
48+
49+
If you want to run only examples of a specific subdirectory, you can pass the subdirectory name as an argument:
50+
51+
```bash
52+
./runner openai
53+
```

examples/anthropic/chat.php

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

19-
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
20-
(new Dotenv())->loadEnv(dirname(__DIR__, 2).'/.env');
19+
require_once dirname(__DIR__).'/vendor/autoload.php';
20+
(new Dotenv())->loadEnv(dirname(__DIR__).'/.env');
2121

2222
if (empty($_ENV['ANTHROPIC_API_KEY'])) {
2323
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;

examples/anthropic/image-input-binary.php

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

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

2323
if (empty($_ENV['ANTHROPIC_API_KEY'])) {
2424
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;

examples/anthropic/image-input-url.php

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

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

2323
if (empty($_ENV['ANTHROPIC_API_KEY'])) {
2424
echo 'Please set the ANTHROPIC_API_KEY environment variable.'.\PHP_EOL;

0 commit comments

Comments
 (0)