-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.php
44 lines (39 loc) · 1.28 KB
/
example.php
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
<?php
require __DIR__ . '/vendor/autoload.php';
use Http\Client\Common\Plugin\LoggerPlugin;
use Http\Message\Formatter\FullHttpMessageFormatter;
use Sourceability\OpenAIClient\Client;
use Sourceability\OpenAIClient\Generated\Model\CreateCompletionRequest;
use Sourceability\OpenAIClient\Generated\Model\CreateCompletionResponse;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\ConsoleOutput;
$apiClient = Client::create(
additionalPlugins: [
new LoggerPlugin(
new ConsoleLogger(new ConsoleOutput(ConsoleOutput::VERBOSITY_DEBUG)),
new FullHttpMessageFormatter()
)
],
apiKey: getenv('OPENAI_API_KEY')
);
$requests = [
new CreateCompletionRequest(
model: 'text-davinci-003',
temperature: 0,
maxTokens: 512,
prompt: 'The jane php library is very useful because'
),
new CreateCompletionRequest(
model: 'text-davinci-003',
temperature: 0,
maxTokens: 512,
prompt: 'Symfony symfony symfony is like sourceability on a'
),
];
$completionResponses = $apiClient->createCompletions($requests);
var_dump(
array_map(
fn (CreateCompletionResponse $response) => $response->getChoices()[0]->getText(),
$completionResponses
)
);