forked from php-llm/llm-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion-answering.php
More file actions
28 lines (21 loc) · 925 Bytes
/
question-answering.php
File metadata and controls
28 lines (21 loc) · 925 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
27
28
<?php
use PhpLlm\LlmChain\Bridge\HuggingFace\Model;
use PhpLlm\LlmChain\Bridge\HuggingFace\PlatformFactory;
use PhpLlm\LlmChain\Bridge\HuggingFace\Task;
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('deepset/roberta-base-squad2');
$input = [
'question' => 'What is the capital of France?',
'context' => 'Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, in an area of more than 105 square kilometres.',
];
$response = $platform->request($model, $input, [
'task' => Task::QUESTION_ANSWERING,
]);
dump($response->getContent());