mirror of
https://github.com/symfony/ai.git
synced 2026-03-23 23:42:18 +01:00
37 lines
1.1 KiB
PHP
37 lines
1.1 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\Agent\Agent;
|
|
use Symfony\AI\Agent\Bridge\Clock\Clock;
|
|
use Symfony\AI\Agent\Toolbox\AgentProcessor;
|
|
use Symfony\AI\Agent\Toolbox\Toolbox;
|
|
use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory;
|
|
use Symfony\AI\Platform\Message\Message;
|
|
use Symfony\AI\Platform\Message\MessageBag;
|
|
|
|
require_once dirname(__DIR__).'/bootstrap.php';
|
|
|
|
$platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), env('OLLAMA_API_KEY'), httpClient: http_client());
|
|
|
|
$toolbox = new Toolbox([new Clock()], logger: logger());
|
|
$processor = new AgentProcessor($toolbox);
|
|
$agent = new Agent($platform, env('OLLAMA_LLM'), [$processor], [$processor]);
|
|
|
|
$messages = new MessageBag(Message::ofUser('What time is it?'));
|
|
|
|
$result = $agent->call($messages, ['stream' => true]);
|
|
|
|
foreach ($result->getContent() as $chunk) {
|
|
echo $chunk->getContent();
|
|
}
|
|
|
|
echo \PHP_EOL;
|