forked from Michael-A-Kuykendall/shimmy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayground.html
More file actions
575 lines (491 loc) · 20.4 KB
/
playground.html
File metadata and controls
575 lines (491 loc) · 20.4 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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shimmy API Playground</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
line-height: 1.6;
color: #333;
background: #f8fafc;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 2rem;
border-radius: 12px;
margin-bottom: 2rem;
text-align: center;
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 0.5rem;
}
.header p {
font-size: 1.2rem;
opacity: 0.9;
}
.playground {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2rem;
margin-bottom: 2rem;
}
.panel {
background: white;
border-radius: 12px;
padding: 1.5rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
}
.panel h2 {
color: #4a5568;
margin-bottom: 1rem;
font-size: 1.3rem;
}
.form-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
font-weight: 600;
color: #4a5568;
}
input, textarea, select {
width: 100%;
padding: 0.75rem;
border: 2px solid #e2e8f0;
border-radius: 8px;
font-size: 1rem;
transition: border-color 0.2s;
}
input:focus, textarea:focus, select:focus {
outline: none;
border-color: #667eea;
}
textarea {
min-height: 120px;
resize: vertical;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
}
.response-area {
min-height: 200px;
background: #1a202c;
color: #e2e8f0;
border-radius: 8px;
padding: 1rem;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.9rem;
white-space: pre-wrap;
overflow-y: auto;
border: 2px solid #2d3748;
}
.button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
margin-right: 0.5rem;
}
.button:hover {
transform: translateY(-2px);
box-shadow: 0 8px 15px rgba(102, 126, 234, 0.3);
}
.button:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.button-secondary {
background: #718096;
}
.status {
padding: 0.5rem 1rem;
border-radius: 6px;
margin-bottom: 1rem;
font-weight: 500;
}
.status.success {
background: #c6f6d5;
color: #22543d;
border: 1px solid #9ae6b4;
}
.status.error {
background: #fed7d7;
color: #742a2a;
border: 1px solid #fc8181;
}
.status.loading {
background: #bee3f8;
color: #2c5282;
border: 1px solid #90cdf4;
}
.examples {
background: white;
border-radius: 12px;
padding: 1.5rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.07);
margin-bottom: 2rem;
}
.example-button {
background: #edf2f7;
color: #4a5568;
border: 1px solid #cbd5e0;
padding: 0.5rem 1rem;
border-radius: 6px;
margin: 0.25rem;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.2s;
}
.example-button:hover {
background: #e2e8f0;
border-color: #a0aec0;
}
.grid-2 {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
}
@media (max-width: 768px) {
.playground {
grid-template-columns: 1fr;
}
.grid-2 {
grid-template-columns: 1fr;
}
}
.endpoint-info {
background: #f7fafc;
border: 1px solid #e2e8f0;
border-radius: 8px;
padding: 1rem;
margin-bottom: 1rem;
font-family: monospace;
font-size: 0.9rem;
}
.streaming-output {
border-left: 4px solid #667eea;
padding-left: 1rem;
margin: 0.5rem 0;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🔄 Shimmy API Playground</h1>
<p>Interactive testing environment for the Shimmy LLM inference API</p>
</div>
<div class="examples">
<h2>Quick Examples</h2>
<p style="margin-bottom: 1rem;">Click any example to load it into the playground:</p>
<button class="example-button" onclick="loadExample('simple')">Simple Generation</button>
<button class="example-button" onclick="loadExample('streaming')">Streaming Response</button>
<button class="example-button" onclick="loadExample('chat')">Chat Completion</button>
<button class="example-button" onclick="loadExample('custom')">Custom Parameters</button>
<button class="example-button" onclick="loadExample('models')">List Models</button>
</div>
<div class="playground">
<div class="panel">
<h2>API Request</h2>
<div class="form-group">
<label for="endpoint">Endpoint URL</label>
<input type="text" id="endpoint" value="http://localhost:11434" placeholder="http://localhost:11434">
</div>
<div class="form-group">
<label for="method">HTTP Method</label>
<select id="method">
<option value="POST">POST</option>
<option value="GET">GET</option>
</select>
</div>
<div class="form-group">
<label for="path">API Path</label>
<select id="path">
<option value="/api/generate">Generate Text (/api/generate)</option>
<option value="/api/chat">Chat Completion (/api/chat)</option>
<option value="/api/tags">List Models (/api/tags)</option>
<option value="/api/show">Show Model (/api/show)</option>
<option value="/health">Health Check (/health)</option>
</select>
</div>
<div class="endpoint-info">
<strong>Full URL:</strong> <span id="fullUrl">http://localhost:11434/api/generate</span>
</div>
<div class="form-group">
<label for="payload">Request Body (JSON)</label>
<textarea id="payload" placeholder="Enter JSON payload here...">{
"model": "default",
"prompt": "Explain what Shimmy is in one sentence.",
"max_tokens": 100,
"temperature": 0.7
}</textarea>
</div>
<div class="grid-2">
<div class="form-group">
<label for="streaming">Streaming</label>
<select id="streaming">
<option value="false">Disabled</option>
<option value="true">Enabled</option>
</select>
</div>
<div class="form-group">
<label for="timeout">Timeout (seconds)</label>
<input type="number" id="timeout" value="30" min="5" max="300">
</div>
</div>
<div style="margin-top: 1.5rem;">
<button class="button" onclick="sendRequest()">Send Request</button>
<button class="button button-secondary" onclick="clearResponse()">Clear</button>
</div>
</div>
<div class="panel">
<h2>API Response</h2>
<div id="status"></div>
<div class="response-area" id="response">Ready to send your first request! 🚀
Try the examples above or customize your own request.
Shimmy supports:
• Text generation (/api/generate)
• Chat completions (/api/chat)
• Model listing (/api/tags)
• Health checks (/health)
• Streaming responses
• Native SafeTensors models</div>
</div>
</div>
<div class="panel">
<h2>API Documentation</h2>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem;">
<div style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 1rem;">
<h3 style="color: #667eea; margin-bottom: 0.5rem;">Text Generation</h3>
<code style="font-size: 0.8rem; color: #4a5568;">POST /api/generate</code>
<p style="margin-top: 0.5rem; font-size: 0.9rem;">Generate text with any loaded model. Supports streaming and custom parameters.</p>
</div>
<div style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 1rem;">
<h3 style="color: #667eea; margin-bottom: 0.5rem;">Chat Completion</h3>
<code style="font-size: 0.8rem; color: #4a5568;">POST /api/chat</code>
<p style="margin-top: 0.5rem; font-size: 0.9rem;">Chat-style completions with conversation history and system prompts.</p>
</div>
<div style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 1rem;">
<h3 style="color: #667eea; margin-bottom: 0.5rem;">List Models</h3>
<code style="font-size: 0.8rem; color: #4a5568;">GET /api/tags</code>
<p style="margin-top: 0.5rem; font-size: 0.9rem;">Get all available models and their metadata.</p>
</div>
<div style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 1rem;">
<h3 style="color: #667eea; margin-bottom: 0.5rem;">Health Check</h3>
<code style="font-size: 0.8rem; color: #4a5568;">GET /health</code>
<p style="margin-top: 0.5rem; font-size: 0.9rem;">Check if the Shimmy server is running and healthy.</p>
</div>
</div>
</div>
</div>
<script>
// Update full URL when endpoint or path changes
function updateFullUrl() {
const endpoint = document.getElementById('endpoint').value;
const path = document.getElementById('path').value;
const fullUrl = endpoint.replace(/\/$/, '') + path;
document.getElementById('fullUrl').textContent = fullUrl;
}
// Event listeners for URL updates
document.getElementById('endpoint').addEventListener('input', updateFullUrl);
document.getElementById('path').addEventListener('change', updateFullUrl);
// Initialize
updateFullUrl();
// Load example requests
function loadExample(type) {
const examples = {
simple: {
method: 'POST',
path: '/api/generate',
payload: {
model: 'default',
prompt: 'Explain what Shimmy is in one sentence.',
max_tokens: 50,
temperature: 0.7
}
},
streaming: {
method: 'POST',
path: '/api/generate',
payload: {
model: 'default',
prompt: 'Write a short story about a robot learning to paint.',
max_tokens: 200,
temperature: 0.8,
stream: true
}
},
chat: {
method: 'POST',
path: '/api/chat',
payload: {
model: 'default',
messages: [
{role: 'system', content: 'You are a helpful AI assistant.'},
{role: 'user', content: 'What are the benefits of using SafeTensors format?'}
],
max_tokens: 150
}
},
custom: {
method: 'POST',
path: '/api/generate',
payload: {
model: 'default',
prompt: 'Explain quantum computing:',
max_tokens: 100,
temperature: 0.3,
top_p: 0.9,
frequency_penalty: 0.1
}
},
models: {
method: 'GET',
path: '/api/tags',
payload: {}
}
};
const example = examples[type];
if (!example) return;
document.getElementById('method').value = example.method;
document.getElementById('path').value = example.path;
document.getElementById('payload').value = JSON.stringify(example.payload, null, 2);
updateFullUrl();
}
// Send API request
async function sendRequest() {
const button = event.target;
const status = document.getElementById('status');
const response = document.getElementById('response');
// Get form values
const endpoint = document.getElementById('endpoint').value;
const method = document.getElementById('method').value;
const path = document.getElementById('path').value;
const payload = document.getElementById('payload').value;
const timeout = parseInt(document.getElementById('timeout').value) * 1000;
const url = endpoint.replace(/\/$/, '') + path;
// Update UI
button.disabled = true;
status.innerHTML = '<div class="status loading">Sending request...</div>';
response.textContent = '';
try {
// Parse payload if it's a POST request
let requestBody = null;
let headers = {};
if (method === 'POST' && payload.trim()) {
try {
requestBody = JSON.parse(payload);
headers['Content-Type'] = 'application/json';
} catch (e) {
throw new Error('Invalid JSON in request body: ' + e.message);
}
}
// Check if streaming is requested
const isStreaming = requestBody && requestBody.stream === true;
const startTime = Date.now();
if (isStreaming) {
// Handle streaming response
const response_fetch = await fetch(url, {
method,
headers,
body: requestBody ? JSON.stringify(requestBody) : null,
signal: AbortSignal.timeout(timeout)
});
if (!response_fetch.ok) {
throw new Error(`HTTP ${response_fetch.status}: ${response_fetch.statusText}`);
}
const reader = response_fetch.body.getReader();
const decoder = new TextDecoder();
status.innerHTML = '<div class="status loading">Streaming response...</div>';
response.innerHTML = '<div class="streaming-output">Streaming response:\n\n</div>';
let streamContent = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.trim()) {
try {
const data = JSON.parse(line);
if (data.response) {
streamContent += data.response;
response.innerHTML = `<div class="streaming-output">Streaming response:\n\n${streamContent}</div>`;
}
} catch (e) {
// Ignore JSON parse errors for partial chunks
}
}
}
}
const endTime = Date.now();
status.innerHTML = `<div class="status success">Stream completed in ${endTime - startTime}ms</div>`;
} else {
// Handle regular response
const response_fetch = await fetch(url, {
method,
headers,
body: requestBody ? JSON.stringify(requestBody) : null,
signal: AbortSignal.timeout(timeout)
});
const endTime = Date.now();
const responseText = await response_fetch.text();
// Try to format as JSON
let formattedResponse;
try {
const jsonResponse = JSON.parse(responseText);
formattedResponse = JSON.stringify(jsonResponse, null, 2);
} catch {
formattedResponse = responseText;
}
response.textContent = formattedResponse;
if (response_fetch.ok) {
status.innerHTML = `<div class="status success">Success (${response_fetch.status}) - ${endTime - startTime}ms</div>`;
} else {
status.innerHTML = `<div class="status error">Error ${response_fetch.status}: ${response_fetch.statusText}</div>`;
}
}
} catch (error) {
status.innerHTML = `<div class="status error">Error: ${error.message}</div>`;
response.textContent = `Request failed: ${error.message}`;
} finally {
button.disabled = false;
}
}
// Clear response
function clearResponse() {
document.getElementById('status').innerHTML = '';
document.getElementById('response').textContent = 'Response cleared. Ready for next request.';
}
// Update streaming option when path changes
document.getElementById('path').addEventListener('change', function() {
const streaming = document.getElementById('streaming');
if (this.value === '/api/tags' || this.value === '/health') {
streaming.value = 'false';
streaming.disabled = true;
} else {
streaming.disabled = false;
}
});
</script>
</body>
</html>