-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniMax.html
More file actions
375 lines (331 loc) · 17.8 KB
/
MiniMax.html
File metadata and controls
375 lines (331 loc) · 17.8 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MiniMax AI Chatbox</title>
<!-- Tailwind CSS for styling -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Marked.js for Markdown rendering -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<!-- Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
/* Markdown styles */
.prose pre { background-color: #1e293b; color: #f8fafc; padding: 1rem; border-radius: 0.5rem; overflow-x: auto; margin-top: 0.5rem; margin-bottom: 0.5rem; }
.prose code { background-color: #e2e8f0; color: #0f172a; padding: 0.2rem 0.4rem; border-radius: 0.25rem; font-size: 0.875em; }
.prose pre code { background-color: transparent; padding: 0; color: inherit; }
.prose p { margin-bottom: 0.75rem; }
.prose p:last-child { margin-bottom: 0; }
/* Thinking animation */
.typing-dot { animation: typing 1.4s infinite ease-in-out both; }
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
0%, 80%, 100% { transform: scale(0); }
40% { transform: scale(1); }
}
</style>
</head>
<body class="bg-gray-50 h-screen flex flex-col text-gray-800 font-sans antialiased">
<!-- Header -->
<header class="bg-white shadow-sm border-b border-gray-200 px-6 py-4 flex justify-between items-center z-10 shrink-0">
<div class="flex items-center space-x-3">
<div class="bg-indigo-600 text-white p-2 rounded-lg">
<i class="fa-solid fa-brain"></i>
</div>
<h1 class="text-xl font-semibold text-gray-800 tracking-tight">MiniMax Workspace</h1>
</div>
<button id="settingsBtn" class="text-gray-500 hover:text-indigo-600 transition-colors p-2 rounded-full hover:bg-gray-100">
<i class="fa-solid fa-gear text-xl"></i>
</button>
</header>
<!-- Settings Modal -->
<div id="settingsModal" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center backdrop-blur-sm transition-opacity">
<div class="bg-white rounded-2xl shadow-2xl w-full max-w-md p-6 transform transition-all scale-100">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-gray-800">Configuration</h2>
<button id="closeSettingsBtn" class="text-gray-400 hover:text-gray-600"><i class="fa-solid fa-xmark text-xl"></i></button>
</div>
<div class="space-y-5">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">MiniMax API Key</label>
<div class="relative">
<input type="password" id="apiKeyInput" placeholder="Enter your API key..."
class="w-full pl-4 pr-10 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-shadow">
<i class="fa-solid fa-key absolute right-3 top-3.5 text-gray-400"></i>
</div>
<p class="text-xs text-gray-500 mt-2">Stored locally in your browser.</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Select Model</label>
<select id="modelSelect" class="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 bg-white shadow-sm transition-shadow cursor-pointer">
<option value="MiniMax-M2.7">MiniMax-M2.7 (Recommended)</option>
<option value="MiniMax-M2.7-highspeed">MiniMax-M2.7-highspeed</option>
<option value="MiniMax-M2.5">MiniMax-M2.5</option>
<option value="MiniMax-M2.5-highspeed">MiniMax-M2.5-highspeed</option>
<option value="MiniMax-M2.1">MiniMax-M2.1</option>
<option value="MiniMax-M2.1-highspeed">MiniMax-M2.1-highspeed</option>
<option value="MiniMax-M2">MiniMax-M2</option>
</select>
</div>
</div>
<button id="saveSettingsBtn" class="w-full mt-8 bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-3 px-4 rounded-xl transition-colors shadow-md shadow-indigo-200">
Save & Start Chatting
</button>
</div>
</div>
<!-- Main Chat Area -->
<main class="flex-1 overflow-y-auto p-4 md:p-6 flex flex-col items-center">
<div id="chatContainer" class="w-full max-w-4xl flex flex-col space-y-6 pb-4">
<!-- Welcome Message -->
<div class="flex justify-center mt-10">
<div class="bg-indigo-50 border border-indigo-100 rounded-2xl p-6 text-center max-w-lg shadow-sm">
<div class="w-12 h-12 bg-indigo-100 text-indigo-600 rounded-full flex items-center justify-center mx-auto mb-4 text-xl">
<i class="fa-solid fa-wand-magic-sparkles"></i>
</div>
<h3 class="text-lg font-bold text-gray-800 mb-2">Welcome to MiniMax</h3>
<p class="text-gray-600 text-sm">Please click the gear icon in the top right to configure your API Key and select your desired model before starting.</p>
</div>
</div>
</div>
</main>
<!-- Input Area -->
<footer class="bg-white border-t border-gray-200 px-4 py-4 shrink-0">
<div class="max-w-4xl mx-auto relative flex items-end shadow-sm border border-gray-300 rounded-2xl overflow-hidden focus-within:ring-2 focus-within:ring-indigo-500 focus-within:border-indigo-500 transition-shadow bg-gray-50">
<textarea id="messageInput" rows="1" placeholder="Send a message to MiniMax..."
class="w-full max-h-48 py-4 pl-4 pr-14 bg-transparent resize-none outline-none text-gray-800 placeholder-gray-400"
style="min-height: 56px;"></textarea>
<button id="sendBtn" class="absolute right-2 bottom-2 w-10 h-10 bg-indigo-600 hover:bg-indigo-700 text-white rounded-xl flex items-center justify-center transition-colors disabled:opacity-50 disabled:cursor-not-allowed">
<i class="fa-solid fa-paper-plane"></i>
</button>
</div>
<p class="text-center text-xs text-gray-400 mt-2">MiniMax text models support Agent workflows, complex task scenarios, and recursive self-improvement.</p>
</footer>
<script>
// DOM Elements
const settingsModal = document.getElementById('settingsModal');
const settingsBtn = document.getElementById('settingsBtn');
const closeSettingsBtn = document.getElementById('closeSettingsBtn');
const saveSettingsBtn = document.getElementById('saveSettingsBtn');
const apiKeyInput = document.getElementById('apiKeyInput');
const modelSelect = document.getElementById('modelSelect');
const chatContainer = document.getElementById('chatContainer');
const messageInput = document.getElementById('messageInput');
const sendBtn = document.getElementById('sendBtn');
// State
let conversationHistory =[];
let isGenerating = false;
// Initialize Settings from LocalStorage
window.onload = () => {
const savedKey = localStorage.getItem('minimax_api_key');
const savedModel = localStorage.getItem('minimax_model');
if (savedKey) apiKeyInput.value = savedKey;
if (savedModel) modelSelect.value = savedModel;
// Auto-open settings if no API key
if (!savedKey) toggleSettings();
};
// Event Listeners for Settings
const toggleSettings = () => settingsModal.classList.toggle('hidden');
settingsBtn.addEventListener('click', toggleSettings);
closeSettingsBtn.addEventListener('click', toggleSettings);
saveSettingsBtn.addEventListener('click', () => {
const key = apiKeyInput.value.trim();
if(!key) {
alert("Please enter a valid API Key.");
return;
}
localStorage.setItem('minimax_api_key', key);
localStorage.setItem('minimax_model', modelSelect.value);
toggleSettings();
// Clear welcome message if it's there
if(chatContainer.children.length === 1 && chatContainer.innerHTML.includes('Welcome to MiniMax')) {
chatContainer.innerHTML = '';
}
});
// Auto-resize Textarea
messageInput.addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
sendBtn.disabled = this.value.trim() === '';
});
// Handle Enter key to send (Shift+Enter for new line)
messageInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
handleSend();
}
});
sendBtn.addEventListener('click', handleSend);
// Core Send Logic
async function handleSend() {
const apiKey = localStorage.getItem('minimax_api_key');
const model = localStorage.getItem('minimax_model') || 'MiniMax-M2.7';
const text = messageInput.value.trim();
if (!apiKey) {
toggleSettings();
return;
}
if (!text || isGenerating) return;
// Reset input
messageInput.value = '';
messageInput.style.height = 'auto';
sendBtn.disabled = true;
// Add User Message to UI & History
appendMessage('user', text);
conversationHistory.push({
role: 'user',
content: [{ type: 'text', text: text }]
});
// Add Loading Bubble
const loadingId = addLoadingBubble();
isGenerating = true;
try {
// Call MiniMax API (Anthropic Compatible)
const response = await fetch('https://api.minimax.io/anthropic/v1/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey,
'anthropic-version': '2023-06-01'
},
body: JSON.stringify({
model: model,
max_tokens: 4096,
messages: conversationHistory
})
});
removeElement(loadingId);
if (!response.ok) {
const errText = await response.text();
throw new Error(errText || `HTTP status ${response.status}`);
}
const data = await response.json();
// Parse Anthropic format content blocks (handles Thinking + Text)
let assistantText = "";
let thinkingText = "";
if (data.content && Array.isArray(data.content)) {
data.content.forEach(block => {
if (block.type === 'thinking') {
thinkingText += block.thinking + "\n";
} else if (block.type === 'text') {
assistantText += block.text + "\n";
}
});
} else if (data.content) {
assistantText = data.content;
}
// Add Assistant Message to UI & History
appendMessage('assistant', assistantText.trim(), thinkingText.trim());
conversationHistory.push({
role: 'assistant',
content: assistantText.trim()
});
} catch (error) {
removeElement(loadingId);
appendMessage('error', `**Error:** Failed to communicate with MiniMax API.\n\n\`${error.message}\`\n\n*Check your API key and ensure you are not running into CORS issues (you may need a proxy if calling direct from local browser to some APIs without CORS enabled).*`);
} finally {
isGenerating = false;
sendBtn.disabled = false;
scrollToBottom();
}
}
// UI Helpers
function appendMessage(role, text, thinkingText = null) {
const msgDiv = document.createElement('div');
msgDiv.className = `flex w-full ${role === 'user' ? 'justify-end' : 'justify-start'}`;
let innerHTML = '';
if (role === 'user') {
innerHTML = `
<div class="bg-indigo-600 text-white px-5 py-3.5 rounded-2xl rounded-tr-sm max-w-[85%] shadow-md">
<p class="whitespace-pre-wrap leading-relaxed">${escapeHtml(text)}</p>
</div>
`;
} else if (role === 'assistant') {
const parsedText = marked.parse(text);
let thinkingHTML = '';
if (thinkingText) {
thinkingHTML = `
<details class="mb-4 bg-gray-100 border border-gray-200 rounded-xl overflow-hidden group">
<summary class="px-4 py-2 cursor-pointer font-medium text-sm text-gray-600 flex items-center hover:bg-gray-200 transition-colors">
<i class="fa-solid fa-code-branch mr-2"></i> View Interleaved Thinking Process
</summary>
<div class="px-4 py-3 text-sm text-gray-500 bg-gray-50 whitespace-pre-wrap border-t border-gray-200">${escapeHtml(thinkingText)}</div>
</details>
`;
}
innerHTML = `
<div class="flex items-start max-w-[85%]">
<div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center shrink-0 mr-3 mt-1 shadow-sm">
<i class="fa-solid fa-robot text-sm"></i>
</div>
<div class="bg-white border border-gray-200 px-5 py-4 rounded-2xl rounded-tl-sm shadow-sm w-full">
${thinkingHTML}
<div class="prose prose-slate max-w-none text-gray-800 leading-relaxed">
${parsedText}
</div>
</div>
</div>
`;
} else if (role === 'error') {
const parsedText = marked.parse(text);
innerHTML = `
<div class="flex items-start max-w-[85%]">
<div class="w-8 h-8 rounded-full bg-red-100 text-red-600 flex items-center justify-center shrink-0 mr-3 mt-1">
<i class="fa-solid fa-triangle-exclamation text-sm"></i>
</div>
<div class="bg-red-50 border border-red-200 px-5 py-4 rounded-2xl rounded-tl-sm w-full text-red-800">
<div class="prose prose-red max-w-none text-sm">${parsedText}</div>
</div>
</div>
`;
}
msgDiv.innerHTML = innerHTML;
chatContainer.appendChild(msgDiv);
scrollToBottom();
}
function addLoadingBubble() {
const id = 'loading-' + Date.now();
const loadingDiv = document.createElement('div');
loadingDiv.id = id;
loadingDiv.className = 'flex w-full justify-start';
loadingDiv.innerHTML = `
<div class="flex items-start max-w-[85%]">
<div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center shrink-0 mr-3 mt-1 shadow-sm">
<i class="fa-solid fa-robot text-sm"></i>
</div>
<div class="bg-white border border-gray-200 px-5 py-4 rounded-2xl rounded-tl-sm shadow-sm flex items-center space-x-1.5 h-12">
<div class="w-2 h-2 bg-indigo-400 rounded-full typing-dot"></div>
<div class="w-2 h-2 bg-indigo-400 rounded-full typing-dot"></div>
<div class="w-2 h-2 bg-indigo-400 rounded-full typing-dot"></div>
</div>
</div>
`;
chatContainer.appendChild(loadingDiv);
scrollToBottom();
return id;
}
function removeElement(id) {
const el = document.getElementById(id);
if (el) el.remove();
}
function scrollToBottom() {
const main = document.querySelector('main');
main.scrollTo({ top: main.scrollHeight, behavior: 'smooth' });
}
// Utilities
function escapeHtml(unsafe) {
return (unsafe || '').replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
</script>
</body>
</html>