forked from lucianotonet/groq-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
79 lines (61 loc) · 1.94 KB
/
index.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
71
72
73
74
75
76
77
78
79
<?php
require __DIR__ . '/vendor/autoload.php';
use LucianoTonet\GroqPHP\Groq;
use LucianoTonet\GroqPHP\Models;
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);
$dotenv->load();
$groq = new Groq(getenv('GROQ_API_KEY'));
$models = new Models($groq);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<title>Groq PHP Examples</title>
</head>
<body class="w-full p-24 ">
<div class="container mx-auto max-w-screen-xl gap-10 prose flex flex-col
">
<h3 class="text-md font-bold">Examples:</h3>
<ul class="list-disc">
<li>
<a href="?page=chat">Chat example</a>
</li>
<li>
<a href="?page=chat-streaming">Chat stream example</a>
</li>
<li>
<a href="?page=json-mode">JSON mode example</a>
</li>
<li>
<a href="?page=tool-calling">Tool calling example</a>
</li>
<li>
<a href="?page=tool-calling-advanced">Tool calling advanced example</a>
</li>
</ul>
<div id="content" class="prose">
<?php
if (isset($_GET['page'])) {
require __DIR__ . '/' . $_GET['page'] . '.php';
} else {
echo "Select an example ☝🏼";
}
?>
</div>
<hr>
<h3 class="text-md font-bold">Models:</h3>
<?php
$response = $models->list();
$modelsList = json_decode($response->getBody(), true);
?>
<ul class="gap-10">
<?php foreach ($modelsList['data'] as $model): ?>
<li><?= $model['id'] ?> | <small class="text-xs"><?= $model['owned_by'] ?></small></li>
<?php endforeach; ?>
</ul>
</div>
</body>
</html>