forked from symfony/ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparallel-chat-gpt.php
More file actions
38 lines (31 loc) · 1.18 KB
/
Copy pathparallel-chat-gpt.php
File metadata and controls
38 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?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\OpenAi\Gpt;
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
require_once dirname(__DIR__).'/bootstrap.php';
$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
$model = Gpt::create(Gpt::GPT_4O_MINI, [
'temperature' => 0.5, // default options for the model
]);
$messages = new MessageBag(
Message::forSystem('You will be given a letter and you answer with only the next letter of the alphabet.'),
);
echo 'Initiating parallel calls to GPT on platform ...'.\PHP_EOL;
$results = [];
foreach (range('A', 'D') as $letter) {
echo ' - Request for the letter '.$letter.' initiated.'.\PHP_EOL;
$results[] = $platform->invoke($model, $messages->with(Message::ofUser($letter)));
}
echo 'Waiting for the responses ...'.\PHP_EOL;
foreach ($results as $result) {
echo 'Next Letter: '.$result->asText().\PHP_EOL;
}