NOT-OMEGA commited on
Commit
dcd3af5
·
verified ·
1 Parent(s): 1c34d26

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +116 -9
index.html CHANGED
@@ -592,16 +592,123 @@ async function runBench() {
592
  btn.disabled = true;
593
  btn.textContent = "Running Benchmark...";
594
 
595
- // Placeholder text - yahan aapka main loop aayega jo 5 prompts ko test karega
596
- bcontent.innerHTML += `<p style="color: var(--amber); margin-top: 10px;">Benchmark started! (Note: Actual API loop logic needs to be added here)</p>`;
597
-
598
- // Simulate delay
599
- setTimeout(() => {
600
- btn.textContent = "▶ Run Benchmark";
601
- btn.disabled = false;
602
- }, 2000);
603
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
605
  </script>
606
  </body>
607
  </html>
 
592
  btn.disabled = true;
593
  btn.textContent = "Running Benchmark...";
594
 
595
+ const prompts = [
596
+ "What is the capital of France?",
597
+ "Write a short poem about coding.",
598
+ "Explain quantum computing in simple terms.",
599
+ "What are the benefits of exercise?",
600
+ "Translate 'Hello world' to Spanish."
601
+ ];
602
+
603
+ let resultsHTML = `
604
+ <table class="btbl" style="margin-top: 15px;">
605
+ <thead>
606
+ <tr>
607
+ <th>Prompt</th>
608
+ <th>Tokens</th>
609
+ <th>TTFT (ms)</th>
610
+ <th>TPS (tok/s)</th>
611
+ </tr>
612
+ </thead>
613
+ <tbody id="bench-tbody">
614
+ </tbody>
615
+ </table>
616
+ `;
617
+ bcontent.innerHTML = resultsHTML;
618
+ const tbody = document.getElementById('bench-tbody');
619
+
620
+ let totalTps = 0;
621
+ let totalTtft = 0;
622
+
623
+ for (let i = 0; i < prompts.length; i++) {
624
+ let pText = prompts[i];
625
+ let tr = document.createElement('tr');
626
+ tr.innerHTML = `<td>Prompt ${i+1}</td><td colspan="3" style="color:var(--amber)">Testing...</td>`;
627
+ tbody.appendChild(tr);
628
+
629
+ let t0 = Date.now();
630
+ let firstTokT = null;
631
+ let tokCount = 0;
632
+ let finalTps = 0;
633
+
634
+ try {
635
+ const payload = {
636
+ message: pText,
637
+ session_id: crypto.randomUUID(),
638
+ system_prompt: "You are a helpful assistant.",
639
+ max_new_tokens: 50,
640
+ temperature: 0.1,
641
+ top_k: 40
642
+ };
643
+
644
+ const resp = await fetch(`${API}/chat`, {
645
+ method: 'POST',
646
+ headers: {'Content-Type':'application/json'},
647
+ body: JSON.stringify(payload),
648
+ });
649
+
650
+ const reader = resp.body.getReader();
651
+ const decoder = new TextDecoder();
652
+ let buf = '';
653
+
654
+ while (true) {
655
+ const {done, value} = await reader.read();
656
+ if (done) break;
657
+ buf += decoder.decode(value, {stream:true});
658
+ let nl;
659
+ while ((nl = buf.indexOf('\n')) !== -1) {
660
+ const line = buf.slice(0, nl).trim();
661
+ buf = buf.slice(nl+1);
662
+ if (!line.startsWith('data:')) continue;
663
+ const raw = line.slice(5).trim();
664
+ if (raw === '[DONE]') break;
665
+ let chunk;
666
+ try { chunk = JSON.parse(raw); } catch { continue; }
667
+
668
+ if (chunk.type === 'token') {
669
+ if (firstTokT === null) firstTokT = Date.now();
670
+ tokCount++;
671
+ } else if (chunk.type === 'done') {
672
+ finalTps = chunk.tps;
673
+ }
674
+ }
675
+ }
676
+
677
+ let ttft = firstTokT !== null ? (firstTokT - t0) : 0;
678
+ totalTps += finalTps;
679
+ totalTtft += ttft;
680
+
681
+ tr.innerHTML = `
682
+ <td>Prompt ${i+1}</td>
683
+ <td>${tokCount}</td>
684
+ <td class="${ttft < 800 ? 'good' : 'mid'}">${ttft}</td>
685
+ <td class="good">${finalTps}</td>
686
+ `;
687
+ } catch (e) {
688
+ tr.innerHTML = `<td>Prompt ${i+1}</td><td colspan="3" class="bad">Failed</td>`;
689
+ }
690
+ }
691
+
692
+ let avgTps = (totalTps / prompts.length).toFixed(1);
693
+ let avgTtft = (totalTtft / prompts.length).toFixed(0);
694
 
695
+ let summaryHTML = `
696
+ <div class="bench-summary" style="margin-top: 15px;">
697
+ <div class="bench-stat">
698
+ <div class="bval">${avgTps}</div>
699
+ <div class="blbl">Avg Tok/s</div>
700
+ </div>
701
+ <div class="bench-stat">
702
+ <div class="bval">${avgTtft}ms</div>
703
+ <div class="blbl">Avg TTFT</div>
704
+ </div>
705
+ </div>
706
+ `;
707
+ bcontent.insertAdjacentHTML('afterbegin', summaryHTML);
708
+
709
+ btn.textContent = "▶ Run Benchmark Again";
710
+ btn.disabled = false;
711
+ }
712
  </script>
713
  </body>
714
  </html>