Skip to content

Commit ce2f020

Browse files
committed
ref
1 parent c232299 commit ce2f020

File tree

18 files changed

+218
-27
lines changed

18 files changed

+218
-27
lines changed

docs/components/platform.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -467,30 +467,30 @@ High Availability
467467
As most platform exposes a REST API, errors can occurs during generation phase due to network issues, timeout and more.
468468

469469
To prevent exceptions at the application level and allows to keep a smooth experience for end users,
470-
the ``Symfony\AI\Platform\FailoverPlatform`` can be used to automatically call a backup platform::
470+
the :class:``Symfony\\AI\\Platform\\Bridge\\Failover\\FailoverPlatform`` can be used to automatically call a backup platform::
471471

472+
use Symfony\AI\Platform\Bridge\Failover\FailoverPlatform;
472473
use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory as OllamaPlatformFactory;
473474
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory;
474-
use Symfony\AI\Platform\FailoverPlatform;
475475
use Symfony\AI\Platform\Message\Message;
476476
use Symfony\AI\Platform\Message\MessageBag;
477477
use Symfony\Component\RateLimiter\RateLimiterFactory;
478478
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
479479

480-
$ollamaPlatform = OllamaPlatformFactory::create('http://127.0.0.1:11434', http_client());
481-
$openAiPlatform = OpenAiPlatformFactory::create('sk-foo', http_client());
482-
483-
$failoverPlatform = new FailoverPlatform([
484-
$ollamaPlatform, // # Ollama will fail as 'gpt-4o' is not available in the catalog
485-
$openAiPlatform,
486-
], new RateLimiterFactory([
480+
$rateLimiter = new RateLimiterFactory([
487481
'policy' => 'sliding_window',
488482
'id' => 'failover',
489-
'interval' => '60 seconds',
483+
'interval' => '3 seconds',
490484
'limit' => 1,
491-
], new InMemoryStorage()));
485+
], new InMemoryStorage());
486+
487+
// # Ollama will fail as 'gpt-4o' is not available in the catalog
488+
$platform = new FailoverPlatform([
489+
OllamaPlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()),
490+
OpenAiPlatformFactory::create(env('OPENAI_API_KEY'), http_client()),
491+
], $rateLimiter);
492492

493-
$result = $failoverPlatform->invoke('gpt-4o', new MessageBag(
493+
$result = $platform->invoke('gpt-4o', new MessageBag(
494494
Message::forSystem('You are a helpful assistant.'),
495495
Message::ofUser('Tina has one brother and one sister. How many sisters do Tina\'s siblings have?'),
496496
));

examples/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"symfony/ai-docker-model-runner-platform": "@dev",
8585
"symfony/ai-elasticsearch-store": "@dev",
8686
"symfony/ai-eleven-labs-platform": "@dev",
87+
"symfony/ai-failover-platform": "@dev",
8788
"symfony/ai-gemini-platform": "@dev",
8889
"symfony/ai-generic-platform": "@dev",
8990
"symfony/ai-session-message-store": "@dev",

examples/misc/failover-platform.php

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

12+
use Symfony\AI\Platform\Bridge\Failover\FailoverPlatform;
1213
use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory as OllamaPlatformFactory;
14+
use Symfony\AI\Platform\Bridge\OpenAi\Gpt\ResultConverter;
1315
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory;
14-
use Symfony\AI\Platform\FailoverPlatform;
1516
use Symfony\AI\Platform\Message\Message;
1617
use Symfony\AI\Platform\Message\MessageBag;
1718
use Symfony\Component\RateLimiter\RateLimiterFactory;
1819
use Symfony\Component\RateLimiter\Storage\InMemoryStorage;
1920

2021
require_once dirname(__DIR__).'/bootstrap.php';
2122

22-
$ollamaPlatform = OllamaPlatformFactory::create(env('OLLAMA_HOST_URL'), http_client());
23-
$openAiPlatform = OpenAiPlatformFactory::create(env('OPENAI_API_KEY'), http_client());
24-
25-
$platform = new FailoverPlatform([
26-
$ollamaPlatform, // # Ollama will fail as 'gpt-4o' is not available in the catalog
27-
$openAiPlatform,
28-
], new RateLimiterFactory([
23+
$rateLimiter = new RateLimiterFactory([
2924
'policy' => 'sliding_window',
3025
'id' => 'failover',
3126
'interval' => '3 seconds',
3227
'limit' => 1,
33-
], new InMemoryStorage()));
28+
], new InMemoryStorage());
29+
30+
// # Ollama will fail as 'gpt-4o' is not available in the catalog
31+
$platform = new FailoverPlatform([
32+
OllamaPlatformFactory::create(env('OLLAMA_HOST_URL'), http_client()),
33+
OpenAiPlatformFactory::create(env('OPENAI_API_KEY'), http_client()),
34+
], $rateLimiter);
3435

3536
$result = $platform->invoke('gpt-4o', new MessageBag(
3637
Message::forSystem('You are a helpful assistant.'),
3738
Message::ofUser('Tina has one brother and one sister. How many sisters do Tina\'s siblings have?'),
3839
));
3940

41+
assert($result->getResultConverter() instanceof ResultConverter);
42+
4043
echo $result->asText().\PHP_EOL;

src/ai-bundle/src/AiBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
use Symfony\AI\Platform\CachedPlatform;
7878
use Symfony\AI\Platform\Capability;
7979
use Symfony\AI\Platform\Exception\RuntimeException;
80-
use Symfony\AI\Platform\FailoverPlatform;
80+
use Symfony\AI\Platform\Bridge\Failover\FailoverPlatform;
8181
use Symfony\AI\Platform\Message\Content\File;
8282
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
8383
use Symfony\AI\Platform\ModelClientInterface;

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
use Symfony\AI\Platform\CachedPlatform;
3838
use Symfony\AI\Platform\Capability;
3939
use Symfony\AI\Platform\EventListener\TemplateRendererListener;
40-
use Symfony\AI\Platform\FailoverPlatform;
40+
use Symfony\AI\Platform\Bridge\Failover\FailoverPlatform;
4141
use Symfony\AI\Platform\Message\TemplateRenderer\ExpressionLanguageTemplateRenderer;
4242
use Symfony\AI\Platform\Message\TemplateRenderer\StringTemplateRenderer;
4343
use Symfony\AI\Platform\Message\TemplateRenderer\TemplateRendererRegistry;

src/platform/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"symfony/http-client": "^7.3|^8.0",
7474
"symfony/http-client-contracts": "^3.5",
7575
"symfony/process": "^7.3|^8.0",
76-
"symfony/rate-limiter": "^7.3|^8.0",
7776
"symfony/var-dumper": "^7.3|^8.0"
7877
},
7978
"minimum-stability": "dev",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.git* export-ignore
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Please do not submit any Pull Requests here. They will be closed.
2+
---
3+
4+
Please submit your PR here instead:
5+
https://github.com/symfony/ai
6+
7+
This repository is what we call a "subtree split": a read-only subset of that main repository.
8+
We're looking forward to your PR there!
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Close Pull Request
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
7+
jobs:
8+
run:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: superbrothers/close-pull-request@v3
12+
with:
13+
comment: |
14+
Thanks for your Pull Request! We love contributions.
15+
16+
However, you should instead open your PR on the main repository:
17+
https://github.com/symfony/ai
18+
19+
This repository is what we call a "subtree split": a read-only subset of that main repository.
20+
We're looking forward to your PR there!
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
4+
.phpunit.result.cache

0 commit comments

Comments
 (0)