@@ -467,30 +467,30 @@ High Availability
467467As most platform exposes a REST API, errors can occurs during generation phase due to network issues, timeout and more.
468468
469469To 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 ));
0 commit comments