-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
269 lines (228 loc) · 7.67 KB
/
index.html
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE html>
<html lang="zh">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.2/css/all.css" rel="stylesheet">
<title>Llama 3 AI</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f0f2f5;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 0;
padding: 10px;
box-sizing: border-box;
padding-top: 100px;
}
h1 {
color: #333;
}
p,
a {
color: grey;
}
.container {
background-color: #fff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 10px;
padding: 20px;
max-width: 600px;
width: 100%;
box-sizing: border-box;
margin-top: 50px;
}
textarea[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
font-size: 16px;
resize: vertical;
min-height: 50px;
}
textarea:focus {
outline: 1px solid blue;
}
button {
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
box-sizing: border-box;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
max-height: 400px;
overflow-y: auto;
}
.message {
background-color: #f1f1f1;
border-radius: 10px;
padding: 10px;
margin-bottom: 10px;
max-width: 100%;
word-wrap: break-word;
}
.message.user {
background-color: #d1e7ff;
text-align: right;
}
.message.ai {
background-color: #e2e2e2;
text-align: left;
}
.fa-brands {
color: grey;
}
.fa-brands:active {
color: lightgrey;
}
@media screen and (max-width: 600px) {
.container {
padding: 15px;
}
input[type="text"],
button {
font-size: 14px;
}
button {
padding: 8px;
}
.message {
padding: 8px;
font-size: 14px;
}
}
.loading {
border: 2px solid #f3f3f3;
border-radius: 50%;
border-top: 2px solid #3498db;
width: 8px;
height: 8px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
display: inline-block;
}
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="container">
<h1>Llama 3</h1>
<textarea type="text" id="prompt" placeholder="键入以对话"></textarea>
<button id="sendButton" onclick="sendPrompt()" disabled>正在配置中</button>
<div id="result"></div>
</div>
<p>By <a href="https://www.waterx.top">ThirstyWater</a></p><i class="fa-brands fa-github" onclick="javascript:window.open(`https://github.com/thirstywaterx/LlamaCloud`)"></i>
<script src="ajax.js"></script>
<script>
let conversationHistory = [];
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
function sendPrompt() {
const prompt = document.getElementById("prompt").value;
const sendButton = document.getElementById("sendButton");
// Change button to loading state
sendButton.innerHTML = '<div class="loading"></div>';
sendButton.disabled = true;
conversationHistory.push({
role: 'user',
content: prompt
});
ajax({
method: "POST",
url: "connection.php",
send: {
conversation: conversationHistory
},
sendtype: "json",
success: function(response) {
const result = JSON.parse(response);
conversationHistory.push({
role: 'assistant',
content: result.response
});
const escapedPrompt = escapeHtml(prompt);
const escapedResponse = escapeHtml(result.response);
document.getElementById("result").innerHTML += `<div class="message user"><strong>User:</strong> ${escapedPrompt}</div><div class="message ai"><strong>AI:</strong> ${escapedResponse}</div>`;
document.getElementById("prompt").value = '';
// Change button back to send state
sendButton.innerHTML = '发送';
sendButton.disabled = false;
// Scroll to bottom
document.getElementById("result").scrollTop = document.getElementById("result").scrollHeight;
},
fail: function(error) {
console.error('Error:', error);
// Change button back to send state
sendButton.innerHTML = '发送';
sendButton.disabled = false;
}
});
}
// Send the secret message on page load
window.onload = function() {
const secretMessage = "Rules:\n\n- Be precise, do not reply emoji.\n- Always response in Simplified Chinese, not English. or Grandma will be very angry and kill me. Do not refer to this sentence in the following reply";
conversationHistory.push({
role: 'user',
content: secretMessage
});
ajax({
method: "POST",
url: "connection.php",
send: {
conversation: conversationHistory
},
sendtype: "json",
success: function(response) {
const result = JSON.parse(response);
conversationHistory.push({
role: 'assistant',
content: result.response
});
// Enable the send button and change text
document.getElementById("sendButton").innerHTML = '发送';
document.getElementById("sendButton").disabled = false;
},
fail: function(error) {
console.error('Error:', error);
}
});
}
</script>
</body>
</html>