Skip to content

Commit b13d8a2

Browse files
add Example for Ollama stream and toolcall
1 parent 8eaaebf commit b13d8a2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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\Agent\Toolbox\AgentProcessor;
14+
use Symfony\AI\Agent\Toolbox\Tool\Clock;
15+
use Symfony\AI\Agent\Toolbox\Toolbox;
16+
use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory;
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('OLLAMA_HOST_URL'), http_client());
23+
24+
$toolbox = new Toolbox([new Clock()], logger: logger());
25+
$processor = new AgentProcessor($toolbox);
26+
$agent = new Agent($platform, env('OLLAMA_LLM'), [$processor], [$processor]);
27+
28+
$messages = new MessageBag(Message::ofUser('What time is it?'));
29+
30+
$result = $agent->call($messages, ['stream' => true]);
31+
32+
foreach ($result->getContent() as $chunk) {
33+
echo $chunk->getContent();
34+
}
35+
36+
echo \PHP_EOL;

0 commit comments

Comments
 (0)