This repository was archived by the owner on Jul 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathchat.php
More file actions
47 lines (35 loc) · 1.66 KB
/
chat.php
File metadata and controls
47 lines (35 loc) · 1.66 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
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
use PhpLlm\LlmChain\Chain\Chain;
use PhpLlm\LlmChain\Platform\Bridge\Albert\PlatformFactory;
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT;
use PhpLlm\LlmChain\Platform\Message\Message;
use PhpLlm\LlmChain\Platform\Message\MessageBag;
require_once dirname(__DIR__).'/../vendor/autoload.php';
if (!isset($_SERVER['ALBERT_API_KEY'], $_SERVER['ALBERT_API_URL'])) {
echo 'Please set the ALBERT_API_KEY and ALBERT_API_URL environment variable (e.g., https://your-albert-instance.com/v1).'.\PHP_EOL;
exit(1);
}
$platform = PlatformFactory::create($_SERVER['ALBERT_API_KEY'], $_SERVER['ALBERT_API_URL']);
$model = new GPT('gpt-4o');
$chain = new Chain($platform, $model);
$documentContext = <<<'CONTEXT'
Document: AI Strategy of France
France has launched a comprehensive national AI strategy with the following key objectives:
1. Strengthening the AI ecosystem and attracting talent
2. Developing sovereign AI capabilities
3. Ensuring ethical and responsible AI development
4. Supporting AI adoption in public services
5. Investing €1.5 billion in AI research and development
The Albert project is part of this strategy, providing a sovereign AI solution for French public administration.
CONTEXT;
$messages = new MessageBag(
Message::forSystem(
'You are an AI assistant with access to documents about French AI initiatives. '.
'Use the provided context to answer questions accurately.'
),
Message::ofUser($documentContext),
Message::ofUser('What are the main objectives of France\'s AI strategy?'),
);
$response = $chain->call($messages);
echo $response->getContent().\PHP_EOL;