|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +use Symfony\AI\Agent\Agent; |
| 13 | +use Symfony\AI\Agent\Toolbox\AgentProcessor; |
| 14 | +use Symfony\AI\Agent\Toolbox\Tool\ElevenLabs; |
| 15 | +use Symfony\AI\Agent\Toolbox\Toolbox; |
| 16 | +use Symfony\AI\Platform\Bridge\OpenAi\Gpt; |
| 17 | +use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory; |
| 18 | +use Symfony\AI\Platform\Message\Message; |
| 19 | +use Symfony\AI\Platform\Message\MessageBag; |
| 20 | + |
| 21 | +require_once dirname(__DIR__).'/bootstrap.php'; |
| 22 | + |
| 23 | +$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); |
| 24 | +$model = new Gpt(Gpt::GPT_4O_MINI); |
| 25 | + |
| 26 | +$elevenLabs = new ElevenLabs( |
| 27 | + http_client(), |
| 28 | + env('ELEVENLABS_API_KEY'), |
| 29 | + __DIR__.'/../tmp', |
| 30 | + 'eleven_multilingual_v2', |
| 31 | + 'Dslrhjl3ZpzrctukrQSN' // Brad (https://elevenlabs.io/app/voice-library?voiceId=Dslrhjl3ZpzrctukrQSN) |
| 32 | +); |
| 33 | + |
| 34 | +$toolbox = new Toolbox([$elevenLabs], logger: logger()); |
| 35 | +$toolProcessor = new AgentProcessor($toolbox); |
| 36 | + |
| 37 | +$agent = new Agent($platform, $model, inputProcessors: [$toolProcessor], outputProcessors: [$toolProcessor]); |
| 38 | + |
| 39 | +$messages = new MessageBag(Message::ofUser('Convert the following text to voice: "Hello world with voice!"')); |
| 40 | +$result = $agent->call($messages); |
| 41 | + |
| 42 | +echo $result->getContent().\PHP_EOL; |
0 commit comments