forked from lucianotonet/groq-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-mode.php
29 lines (26 loc) · 929 Bytes
/
json-mode.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
<?php
require __DIR__ . '/_input.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$message = $_POST['message'];
echo "<strong>user: </strong> $message <br>";
$response = $groq->chat()->completions()->create([
'model' => 'mixtral-8x7b-32768',
'messages' => [
[
'role' => 'system',
'content' => "You are an API and shall responde only with valid JSON.",
],
[
'role' => 'user',
'content' => $message,
],
],
'response_format' => ['type' => 'json_object']
]);
echo "<strong>assistant: </strong> <br>";
echo "<pre>";
echo json_encode(json_decode($response['choices'][0]['message']['content']), JSON_PRETTY_PRINT);
echo "</pre>";
} else {
echo "<small>Ask anythings to simulate an API.<br/>Results will be mocked for demo purposes.</small><br><br>";
}