-
Notifications
You must be signed in to change notification settings - Fork 1
/
socket_timeout.php
executable file
·46 lines (40 loc) · 1.17 KB
/
socket_timeout.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
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Partitech\PhpMistral\MistralClient;
use Partitech\PhpMistral\MistralClientException;
use Partitech\PhpMistral\Messages;
use Symfony\Component\HttpClient\Exception\TransportException;
// export MISTRAL_API_KEY=
$apiKey = getenv('MISTRAL_API_KEY');
$client = new MistralClient(apiKey: $apiKey, timeout:0.1);
$messages = new Messages();
$messages->addUserMessage('What is the best French cheese?');
$params = [
'model' => 'mistral-large-latest',
'temperature' => 0.7,
'top_p' => 1,
'max_tokens' => null,
'safe_prompt' => false,
'random_seed' => null
];
try {
foreach ($client->chatStream($messages, $params) as $chunk) {
echo $chunk->getChunk();
}
} catch (MistralClientException $e) {
echo $e->getMessage();
exit(1);
} catch (TransportException $e) {
echo 'Idle timeout reached' . PHP_EOL;
}
$client->setTimeout(null);
try {
foreach ($client->chatStream($messages, $params) as $chunk) {
echo $chunk->getChunk();
}
} catch (MistralClientException $e) {
echo $e->getMessage();
exit(1);
} catch (TransportException $e) {
echo 'Idle timeout reached' . PHP_EOL;;
}