Files
archived-ai/examples/perplexity/image-input-url.php
2026-01-23 20:05:26 +01:00

34 lines
1.0 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\AI\Platform\Bridge\Perplexity\PlatformFactory;
use Symfony\AI\Platform\Message\Content\ImageUrl;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
require_once __DIR__.'/bootstrap.php';
$platform = PlatformFactory::create(env('PERPLEXITY_API_KEY'), http_client());
$messages = new MessageBag(
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
Message::ofUser(
'Describe the image as a comedian would do it.',
new ImageUrl('https://christopher-hertel.de/images/projects/llmchain.png'),
),
);
$result = $platform->invoke('sonar', $messages);
echo $result->asText().\PHP_EOL;
print_search_results($result->getMetadata()->get('search_results'));
print_citations($result->getMetadata()->get('citations'));