-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-chat.php
53 lines (48 loc) · 1.6 KB
/
example-chat.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
45
46
47
48
49
50
51
52
53
<?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\ChatCompletionRequestMessage;
use Sourceability\OpenAIClient\Generated\Model\CreateChatCompletionRequest;
use Sourceability\OpenAIClient\Generated\Model\CreateChatCompletionResponse;
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 CreateChatCompletionRequest(
model: 'gpt-3.5-turbo',
temperature: 0,
messages: [
new ChatCompletionRequestMessage(
role: 'user',
content: 'The jane php library is very useful because'
)
],
),
new CreateChatCompletionRequest(
model: 'gpt-3.5-turbo',
temperature: 0,
messages: [
new ChatCompletionRequestMessage(
role: 'user',
content: 'Symfony symfony symfony is like sourceability on a'
)
],
),
];
$completionResponses = $apiClient->createChatCompletions($requests);
var_dump(
array_map(
fn (CreateChatCompletionResponse $response) => $response->getChoices()[0]->getMessage()->getContent(),
$completionResponses
)
);