-
Notifications
You must be signed in to change notification settings - Fork 1
/
fill_in_the_middle.php
executable file
·70 lines (61 loc) · 1.71 KB
/
fill_in_the_middle.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Partitech\PhpMistral\MistralClient;
use Partitech\PhpMistral\MistralClientException;
use Partitech\PhpMistral\Messages;
// export MISTRAL_API_KEY=your_api_key
$apiKey = getenv('MISTRAL_API_KEY');
$model_name = "codestral-2405";
$client = new MistralClient($apiKey);
$prompt = "Write response in php:\n";
$prompt .= "/** Calculate date + n days. Returns \DateTime object */";
$suffix = 'return $datePlusNdays;\n}';
try {
$result = $client->fim(
prompt: $prompt,
suffix: $suffix,
params:[
'model' => $model_name,
'temperature' => 0.7,
'top_p' => 1,
'max_tokens' => 200,
'min_tokens' => 0,
'stop' => 'string',
'random_seed' => 0
]
);
} catch (MistralClientException $e) {
echo $e->getMessage();
exit(1);
}
print_r($result->getMessage());
/**
* function datePlusNdays(\DateTime $date, $n) {
* $datePlusNdays = clone $date;
* $datePlusNdays->add(new \DateInterval('P'.abs($n).'D'));
*/
###############################################
##### Fill in the meddle with streaming ######
###############################################
try {
$result = $client->fimStream(
prompt: $prompt,
suffix: $suffix,
params:[
'model' => $model_name,
'temperature' => 0.7,
'top_p' => 1,
'max_tokens' => 200,
'min_tokens' => 0,
'stop' => 'string',
'random_seed' => 0
]
);
foreach ($result as $chunk) {
echo $chunk->getChunk();
}
} catch (MistralClientException $e) {
echo $e->getMessage();
exit(1);
}