-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
64 lines (51 loc) · 1.5 KB
/
test.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
<?php
use Ay4t\RestClient\Client;
use Ay4t\RestClient\Config\Config;
use Kint\Kint;
require_once __DIR__ . '/../vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
$env = $dotenv->load();
// Kint::dump( $env );
// die;
$groq_api_key = $env['API_KEY'];
$groq_api_url = $env['GROQ_API_URL'];
// Cara 1: Menggunakan Config object (direkomendasikan)
/* $config = new Config();
$config->setBaseUri($groq_api_url)
->setApiKey($groq_api_key); */
// Cara 2: Menggunakan array (alternatif)
$config = [
'base_uri' => $groq_api_url,
'headers' => [
'Authorization' => 'Bearer ' . $groq_api_key
]
];
$client = new Client($config);
/* list all models */
try {
$response = $client->cmd('GET', 'models');
print_r($response);
} catch (Ay4t\RestClient\Exceptions\ApiException $e) {
echo "Error: " . $e->getMessage();
echo "HTTP Status: " . $e->getHttpStatusCode();
echo "Response Body: " . $e->getResponseBody();
}
die;
/* chat/completions */
try {
$cmd = $client->cmd('POST', 'chat/completions', [
'model' => 'deepseek-r1-distill-llama-70b',
'messages' => [
[
'role' => 'user',
'content' => 'hi, why is sea water salty?',
]
]
]);
print_r($cmd);
} catch (Ay4t\RestClient\Exceptions\ApiException $e) {
echo "Error: " . $e->getMessage();
echo "HTTP Status: " . $e->getHttpStatusCode();
echo "Response Body: " . $e->getResponseBody();
}
die;