|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 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\Platform\Bridge\Perplexity\Perplexity; |
| 14 | +use Symfony\AI\Platform\Bridge\Perplexity\PlatformFactory; |
| 15 | +use Symfony\AI\Platform\Bridge\Perplexity\SearchResultProcessor; |
| 16 | +use Symfony\AI\Platform\Message\Content\ImageUrl; |
| 17 | +use Symfony\AI\Platform\Message\Message; |
| 18 | +use Symfony\AI\Platform\Message\MessageBag; |
| 19 | + |
| 20 | +require_once dirname(__DIR__).'/bootstrap.php'; |
| 21 | + |
| 22 | +$platform = PlatformFactory::create(env('PERPLEXITY_API_KEY'), http_client()); |
| 23 | +$model = new Perplexity(); |
| 24 | +$agent = new Agent($platform, $model, outputProcessors: [new SearchResultProcessor()], logger: logger()); |
| 25 | + |
| 26 | +$messages = new MessageBag( |
| 27 | + Message::forSystem('You are an image analyzer bot that helps identify the content of images.'), |
| 28 | + Message::ofUser( |
| 29 | + 'Describe the image as a comedian would do it.', |
| 30 | + new ImageUrl('https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Webysther_20160423_-_Elephpant.svg/350px-Webysther_20160423_-_Elephpant.svg.png'), |
| 31 | + ), |
| 32 | +); |
| 33 | +$result = $agent->call($messages); |
| 34 | + |
| 35 | +echo $result->getContent().\PHP_EOL; |
| 36 | + |
| 37 | +perplexity_print_search_results($result->getMetadata()); |
| 38 | +perplexity_print_citations($result->getMetadata()); |
0 commit comments