-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathpersistent-chat-cache.php
More file actions
38 lines (29 loc) · 1.1 KB
/
persistent-chat-cache.php
File metadata and controls
38 lines (29 loc) · 1.1 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 <[email protected]>
*
* 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\Chat\Bridge\Cache\MessageStore as CacheStore;
use Symfony\AI\Chat\Chat;
use Symfony\AI\Platform\Bridge\OpenAi\Factory;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
require_once dirname(__DIR__).'/bootstrap.php';
$platform = Factory::createPlatform(env('OPENAI_API_KEY'), http_client());
$store = new CacheStore(new ArrayAdapter(), 'chat');
$store->setup();
$agent = new Agent($platform, 'gpt-5-mini');
$chat = new Chat($agent, $store);
$messages = new MessageBag(
Message::forSystem('You are a helpful assistant. You only answer with short sentences.'),
);
$chat->initiate($messages);
$chat->submit(Message::ofUser('My name is Christopher.'));
$message = $chat->submit(Message::ofUser('What is my name?'));
echo $message->asText().\PHP_EOL;