-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
39 lines (32 loc) · 1.13 KB
/
Copy pathindex.php
File metadata and controls
39 lines (32 loc) · 1.13 KB
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
<?php require 'db.php'; ?>
<!DOCTYPE html>
<html>
<head>
<title>ChatGPT PHP App</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="chat-container">
<h2>Chat with ChatGPT</h2>
<div class="form-container">
<select id="model">
<option value="gpt-3.5-turbo">GPT-3.5 Turbo</option>
<option value="gpt-4">GPT-4</option>
</select>
<textarea id="message" placeholder="Type your message..."></textarea>
<button id="send">Send</button>
</div>
<div id="chat-box" class="chat-box">
<?php
$stmt = $db->query("SELECT * FROM messages ORDER BY timestamp DESC");
foreach ($stmt as $row) {
$roleClass = $row['role'] === 'user' ? 'user' : 'assistant';
echo "<div class='bubble $roleClass'><b>{$row['role']}:</b><br>" . nl2br(htmlspecialchars($row['content'])) . "</div>";
}
?>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="script.js"></script>
</body>
</html>