Skip to content

Commit f37788c

Browse files
committed
Add example for choices
1 parent 1d5dabb commit f37788c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

examples/mistral/chat-multiple.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\Platform\Bridge\Mistral\Mistral;
14+
use Symfony\AI\Platform\Bridge\Mistral\PlatformFactory;
15+
use Symfony\AI\Platform\Message\Message;
16+
use Symfony\AI\Platform\Message\MessageBag;
17+
18+
require_once dirname(__DIR__).'/bootstrap.php';
19+
20+
$platform = PlatformFactory::create(env('MISTRAL_API_KEY'), http_client());
21+
$agent = new Agent($platform, new Mistral(), logger: logger());
22+
23+
$messages = new MessageBag(
24+
Message::forSystem('Just give short answers.'),
25+
Message::ofUser('What is your favorite color?'),
26+
);
27+
$result = $agent->call($messages, [
28+
'temperature' => 1.5,
29+
'n' => 10,
30+
]);
31+
32+
foreach ($result->getContent() as $key => $choice) {
33+
echo sprintf('Choice #%d: %s', ++$key, $choice->getContent()).\PHP_EOL;
34+
}

0 commit comments

Comments
 (0)