-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeepthink-0004.html
396 lines (342 loc) · 10.9 KB
/
deepthink-0004.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enterprise AI Assistant</title>
<link href="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet">
<style>
:root {
--primary: #2563eb;
--background: #0f172a;
--surface: #1e293b;
--text: #e2e8f0;
}
body {
font-family: 'SF Pro Text', -apple-system, system-ui;
margin: 0;
background: var(--background);
color: var(--text);
min-height: 100vh;
}
.container {
display: grid;
grid-template-columns: 280px 1fr;
gap: 2rem;
max-width: 1440px;
margin: 0 auto;
padding: 2rem;
}
.sidebar {
background: var(--surface);
padding: 1.5rem;
border-radius: 12px;
height: min-content;
}
.chat-interface {
background: var(--surface);
border-radius: 12px;
padding: 2rem;
display: flex;
flex-direction: column;
gap: 1rem;
}
.message-history {
flex: 1;
overflow-y: auto;
max-height: 70vh;
padding: 1rem;
background: rgba(0,0,0,0.2);
border-radius: 8px;
}
.message {
margin: 1rem 0;
padding: 1rem;
background: rgba(255,255,255,0.05);
border-radius: 8px;
border-left: 3px solid;
animation: messageIn 0.3s ease;
}
.message.user { border-color: #10b981; }
.message.assistant { border-color: #8b5cf6; }
.message.system { border-color: #3b82f6; }
.input-area {
position: relative;
}
textarea {
width: 100%;
padding: 1rem;
background: var(--surface);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 8px;
color: var(--text);
resize: vertical;
min-height: 100px;
}
.toolbar {
display: flex;
gap: 0.5rem;
margin-top: 0.5rem;
}
button {
background: var(--primary);
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 6px;
cursor: pointer;
transition: opacity 0.2s;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.6; cursor: not-allowed; }
@keyframes messageIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
pre[class*="language-"] {
background: rgba(0,0,0,0.3) !important;
margin: 0.5rem 0;
padding: 1rem !important;
}
</style>
</head>
<body>
<div class="container">
<!-- Control Sidebar -->
<div class="sidebar">
<h2>Configuration</h2>
<div class="form-group">
<label>AI Model</label>
<select id="modelSelect" disabled>
<option>Loading models...</option>
</select>
</div>
<div class="form-group">
<label>System Persona</label>
<textarea id="systemPrompt" placeholder="Configure AI behavior..."></textarea>
</div>
<div class="form-group">
<label>Context Window</label>
<input type="number" id="contextWindow" value="20" min="5" max="100">
</div>
<button onclick="saveConfig()">Save Settings</button>
<button onclick="clearHistory()">Clear History</button>
</div>
<!-- Main Chat Interface -->
<div class="chat-interface">
<div class="message-history" id="messageHistory"></div>
<div class="input-area">
<textarea id="userInput" placeholder="Type your message..." rows="4"></textarea>
<div class="toolbar">
<button onclick="sendMessage()" id="sendBtn">Send</button>
<button onclick="copyLastResponse()">Copy</button>
<label>
<input type="checkbox" id="streamToggle" checked> Stream
</label>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/prism.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
<script>
// State Management
let appState = {
session: {
id: Date.now(),
messages: [],
config: {
model: null,
systemPrompt: '',
contextWindow: 20,
streaming: false
}
}
};
// Core Functions
async function initializeApp() {
loadSession();
await loadModels();
setupEventListeners();
}
async function loadModels() {
try {
const response = await fetch('https://text.pollinations.ai/models');
const models = await response.json();
populateModelSelect(models.filter(m => m.type === 'chat'));
} catch (error) {
showError('Failed to load models: ' + error.message);
}
}
function populateModelSelect(models) {
const select = document.getElementById('modelSelect');
select.innerHTML = models.map(m => `
<option value="${m.name}" ${m.censored ? 'data-censored="true"' : ''} data-info='${JSON.stringify(m)}'>
${m.description} (${m.censored ? 'censored' : 'uncensored'})
</option>
`).join('');
select.disabled = false;
// Set the selected model if one is already configured
if (appState.session.config.model) {
select.value = appState.session.config.model;
}
// Add event listener to save the selected model
select.addEventListener('change', () => {
appState.session.config.model = select.value;
saveSession();
});
}
async function sendMessage() {
const input = document.getElementById('userInput');
const message = input.value.trim();
if (!message) return;
// Ensure a model is selected
if (!appState.session.config.model) {
showError('Please select a model from the dropdown before sending a message.');
return;
}
// Disable UI during processing
const sendBtn = document.getElementById('sendBtn');
sendBtn.disabled = true;
input.disabled = true;
try {
// Add user message
addMessage('user', message);
input.value = '';
// Prepare messages payload
const messages = constructMessagePayload(message);
// Generate response
const response = await generateResponse(messages);
handleResponse(response);
} catch (error) {
showError(error.message);
} finally {
sendBtn.disabled = false;
input.disabled = false;
Prism.highlightAll();
}
}
function constructMessagePayload(newMessage) {
const model = appState.session.config.model;
const modelInfo = getModelInfo(model);
const messages = [];
if (modelInfo && modelInfo.baseModel) {
messages.push({ role: 'system', content: appState.session.config.systemPrompt });
}
messages.push(...appState.session.messages.slice(-appState.session.config.contextWindow));
messages.push({ role: 'user', content: newMessage });
return messages;
}
function getModelInfo(modelName) {
const select = document.getElementById('modelSelect');
const option = select.querySelector(`option[value="${modelName}"]`);
return option ? JSON.parse(option.dataset.info || '{}') : null;
}
async function generateResponse(messages) {
const model = appState.session.config.model;
// Ensure a model is selected
if (!model) {
showError('Please select a model from the dropdown before sending a message.');
return;
}
const response = await fetch('https://text.pollinations.ai/', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
messages,
model,
code: 'beesknees',
stream: false
})
});
if (!response.ok) throw new Error(`API Error: ${response.status}`);
return await response.json();
}
function handleResponse(response) {
if (response && response.content) {
addMessage('assistant', response.content);
} else {
showError('Invalid response from the API');
}
}
// UI Functions
function addMessage(role, content) {
appState.session.messages.push({ role, content });
renderMessage({ role, content });
saveSession();
}
function renderMessage(message) {
const history = document.getElementById('messageHistory');
const messageElement = document.createElement('div');
messageElement.className = `message ${message.role}`;
messageElement.id = `msg-${appState.session.messages.length - 1}`;
messageElement.innerHTML = `
<strong>${message.role.toUpperCase()}:</strong>
<div>${formatContent(message.content)}</div>
`;
history.appendChild(messageElement);
history.scrollTop = history.scrollHeight;
}
function formatContent(content) {
return content
.replace(/```(\w+)?\n([\s\S]*?)```/g, (_, lang, code) => {
const language = lang || 'javascript';
return `<pre class="language-${language}"><code>${code.trim()}</code></pre>`;
})
.replace(/(https?:\/\/\S+)/g, '<a href="$1" target="_blank">$1</a>');
}
// Session Management
function saveSession() {
localStorage.setItem('aiSession', JSON.stringify(appState.session));
}
function loadSession() {
const savedSession = localStorage.getItem('aiSession');
if (savedSession) {
appState.session = JSON.parse(savedSession);
document.getElementById('systemPrompt').value = appState.session.config.systemPrompt;
document.getElementById('contextWindow').value = appState.session.config.contextWindow;
document.getElementById('streamToggle').checked = appState.session.config.streaming;
appState.session.messages.forEach(renderMessage);
}
}
function saveConfig() {
appState.session.config = {
model: document.getElementById('modelSelect').value,
systemPrompt: document.getElementById('systemPrompt').value,
contextWindow: parseInt(document.getElementById('contextWindow').value),
streaming: document.getElementById('streamToggle').checked
};
saveSession();
}
function clearHistory() {
appState.session.messages = [];
document.getElementById('messageHistory').innerHTML = '';
saveSession();
}
function copyLastResponse() {
const lastResponse = [...appState.session.messages].reverse()
.find(m => m.role === 'assistant')?.content;
if (lastResponse) {
navigator.clipboard.writeText(lastResponse);
}
}
function showError(message) {
const errorElement = document.createElement('div');
errorElement.className = 'message error';
errorElement.textContent = `Error: ${message}`;
document.getElementById('messageHistory').appendChild(errorElement);
}
// Initialization
function setupEventListeners() {
document.getElementById('userInput').addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
}
// Start the application
initializeApp();
</script>
</body>
</html>