-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
221 lines (214 loc) · 6.48 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Llama3 AI Assistant</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/styles/default.min.css">
<style>
body {
background-color: #2f2f2f;
font-family: Inter, sans-serif;
color: #fff;
}
.chat-container {
max-width: 800px;
margin: 40px auto;
padding: 20px;
background-color: #333;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.chat-header {
padding: 10px;
border-bottom: 1px solid #444;
}
.chat-header h2 {
margin: 0;
font-weight: bold;
color: #fff;
}
.chat-messages {
padding: 20px;
}
.message {
margin-bottom: 20px;
padding: 10px;
border-radius: 10px;
background-color: #444;
color: #fff;
}
.message.assistant {
background-color: #43537E;
}
.message.user {
background-color: #666;
}
.message span {
font-weight: bold;
color: #337ab7;
}
.input-container {
padding: 20px;
}
.input-field {
width: 100%;
padding: 10px;
font-size: 16px;
border: none;
border-radius: 10px;
background-color: #444;
color: #fff;
}
.input-field:focus {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.send-button {
background-color: #337ab7;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 10px;
cursor: pointer;
}
.send-button:hover {
background-color: #23527c;
}
.settings-panel {
padding: 20px;
background-color: #333;
border-top: 1px solid #444;
}
.settings-panel label {
font-weight: bold;
color: #fff;
}
.code-block {
padding: 10px;
border-radius: 10px;
background-color: #f7f7f7;
color: #333;
}
.code-block code {
font-family: Monaco, monospace;
font-size: 14px;
}
.custom-prompt {
padding: 10px;
border-radius: 10px;
background-color: #f7f7f7;
color: #333;
}
.custom-token {
padding: 10px;
border-radius: 10px;
background-color: #f7f7f7;
color: #333;
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
<h2>Llama3 AI Assistant</h2>
</div>
<div class="chat-messages">
<div class="message system">
<span>System:</span> You are a helpful assistant.
</div>
</div>
<div class="input-container">
<input id="user-input" type="text" class="input-field" placeholder="Type a message...">
<button id="send-button" class="send-button">Send</button>
</div>
<div class="settings-panel">
<label>Custom Prompt:</label>
<input id="custom-prompt" type="text" class="input-field" placeholder="Enter a custom prompt...">
<br>
<label>Custom Token:</label>
<input id="custom-token" type="text" class="input-field" placeholder="Enter a custom token...">
<br>
<label>Show Code Blocks:</label>
<span class="code-block-toggle">On</span>
<br>
<label>Show Prompt:</label>
<span class="prompt-toggle">On</span>
<br>
<label>Show Token:</label>
<span class="token-toggle">On</span>
</div>
<script>
const chatMessages = document.querySelector('.chat-messages');
const userInput = document.querySelector('#user-input');
const sendButton = document.querySelector('#send-button');
const customPrompt = document.querySelector('#custom-prompt');
const customToken = document.querySelector('#custom-token');
let messages = [
{ role: 'ystem', content: 'You are a helpful assistant.' }
];
sendButton.addEventListener('click', async () => {
const userInputValue = userInput.value.trim();
if (userInputValue!== '') {
messages.push({ role: 'user', content: userInputValue });
userInput.value = '';
const assistantResponse = await getAssistantResponse(messages);
if (assistantResponse) {
messages.push({ role: 'assistant', content: assistantResponse });
renderChatMessages();
} else {
console.error('Failed to get a response from the assistant.');
}
}
});
async function getAssistantResponse(messages) {
const url = 'https://api.fireworks.ai/inference/v1/chat/completions';
const payload = {
model: 'accounts/fireworks/models/llama-v3-70b-instruct',
max_tokens: 8192,
top_p: 1,
top_k: 40,
presence_penalty: 0,
frequency_penalty: 0,
temperature: 1,
messages
};
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer QAwsdCAvRsIaGhoJQvXqfwNkwuDj7D1MyGqldWn07GV068cq'
};
try {
const response = await fetch(url, { method: 'POST', headers, body: JSON.stringify(payload) });
const responseData = await response.json();
if (responseData.choices && responseData.choices[0].message.content) {
return responseData.choices[0].message.content;
} else {
console.error('No valid response received from the API.');
return null;
}
} catch (error) {
console.error('Error:', error);
return null;
}
}
function renderChatMessages() {
chatMessages.innerHTML = '';
messages.forEach((message) => {
const messageElement = document.createElement('div');
messageElement.className = `message ${message.role}`;
if (message.content.includes('```')) {
const codeBlock = document.createElement('div');
codeBlock.className = 'code-block';
codeBlock.innerHTML = `<code>${message.content.replace('```', '')}</code>`;
messageElement.appendChild(codeBlock);
} else {
messageElement.innerHTML = `<span>${message.role.charAt(0).toUpperCase() + message.role.slice(1)}:</span> ${message.content}`;
}
chatMessages.appendChild(messageElement);
});
}
</script>
</body>
</html>