|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use PhpLlm\LlmChain\Chain\Chain; |
| 6 | +use PhpLlm\LlmChain\Platform\Bridge\Albert\PlatformFactory; |
| 7 | +use PhpLlm\LlmChain\Platform\Bridge\OpenAI\GPT; |
| 8 | +use PhpLlm\LlmChain\Platform\Message\Message; |
| 9 | +use PhpLlm\LlmChain\Platform\Message\MessageBag; |
| 10 | + |
| 11 | +require_once dirname(__DIR__).'/../vendor/autoload.php'; |
| 12 | + |
| 13 | +if (empty($_ENV['ALBERT_API_KEY'])) { |
| 14 | + echo 'Please set the ALBERT_API_KEY environment variable.'.\PHP_EOL; |
| 15 | + exit(1); |
| 16 | +} |
| 17 | + |
| 18 | +if (empty($_ENV['ALBERT_API_URL'])) { |
| 19 | + echo 'Please set the ALBERT_API_URL environment variable (e.g., https://your-albert-instance.com/v1).'.\PHP_EOL; |
| 20 | + exit(1); |
| 21 | +} |
| 22 | + |
| 23 | +$platform = PlatformFactory::create( |
| 24 | + apiKey: $_ENV['ALBERT_API_KEY'], |
| 25 | + baseUrl: $_ENV['ALBERT_API_URL'], |
| 26 | +); |
| 27 | + |
| 28 | +$model = new GPT('gpt-4o'); |
| 29 | +$chain = new Chain($platform, $model); |
| 30 | + |
| 31 | +$documentContext = <<<'CONTEXT' |
| 32 | + Document: AI Strategy of France |
| 33 | +
|
| 34 | + France has launched a comprehensive national AI strategy with the following key objectives: |
| 35 | + 1. Strengthening the AI ecosystem and attracting talent |
| 36 | + 2. Developing sovereign AI capabilities |
| 37 | + 3. Ensuring ethical and responsible AI development |
| 38 | + 4. Supporting AI adoption in public services |
| 39 | + 5. Investing €1.5 billion in AI research and development |
| 40 | +
|
| 41 | + The Albert project is part of this strategy, providing a sovereign AI solution for French public administration. |
| 42 | + CONTEXT; |
| 43 | + |
| 44 | +$messages = new MessageBag( |
| 45 | + Message::forSystem( |
| 46 | + 'You are an AI assistant with access to documents about French AI initiatives. '. |
| 47 | + 'Use the provided context to answer questions accurately.' |
| 48 | + ), |
| 49 | + Message::ofUser($documentContext), |
| 50 | + Message::ofUser('What are the main objectives of France\'s AI strategy?'), |
| 51 | +); |
| 52 | + |
| 53 | +$response = $chain->call($messages); |
| 54 | + |
| 55 | +echo $response->getContent().\PHP_EOL; |
0 commit comments