forked from php-llm/llm-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat-completion.php
More file actions
26 lines (20 loc) · 849 Bytes
/
chat-completion.php
File metadata and controls
26 lines (20 loc) · 849 Bytes
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
<?php
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
use PhpLlm\LlmChain\Model\Message\Message;
use PhpLlm\LlmChain\Model\Message\MessageBag;
use Symfony\Component\Dotenv\Dotenv;
require_once dirname(__DIR__, 2).'/vendor/autoload.php';
(new Dotenv())->loadEnv(dirname(__DIR__, 2).'/.env');
if (empty($_ENV['HUGGINGFACE_KEY'])) {
echo 'Please set the HUGGINGFACE_KEY environment variable.'.PHP_EOL;
exit(1);
}
$platform = PlatformFactory::create($_ENV['HUGGINGFACE_KEY']);
$model = new Model('HuggingFaceH4/zephyr-7b-beta');
$messages = new MessageBag(Message::ofUser('Hello, how are you doing today?'));
$response = $platform->request($model, $messages, [
'task' => Task::CHAT_COMPLETION,
]);
echo $response->getContent().PHP_EOL;