Skip to content

Commit bff5d74

Browse files
committed
minor #164 [Examples] Add example for choices (chr-hertel)
This PR was merged into the main branch. Discussion ---------- [Examples] Add example for choices | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | | License | MIT Forgot about that, but wanted at least to add one example. <img width="680" height="251" alt="image" src="https://github.com/user-attachments/assets/a75e1138-b3a8-4de0-88bc-5596b59e4f59" /> Sometimes with a full stop, but always blue. 🤷‍♂️ Commits ------- f37788c Add example for choices
2 parents d022fa1 + f37788c commit bff5d74

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)