SeaWolf-AI commited on
Commit
1026671
·
verified ·
1 Parent(s): bc713ee

serving: manual load + GenerationMixin + use_cache=False + streaming

Browse files
Files changed (1) hide show
  1. index.html +16 -6
index.html CHANGED
@@ -134,14 +134,24 @@ const out=document.getElementById('out'), btn=document.getElementById('go'), sta
134
  async function gen(){
135
  const prompt=document.getElementById('prompt').value.trim();
136
  if(!prompt){return}
137
- btn.disabled=true; out.textContent=''; stat.textContent='generating (model may be loading on first call)…';
 
138
  try{
139
- const r=await fetch('/api/generate',{method:'POST',headers:{'Content-Type':'application/json'},
140
  body:JSON.stringify({prompt:prompt,max_new_tokens:200,temperature:0.7})});
141
- const j=await r.json();
142
- if(j.ok){ out.textContent=j.completion||'(empty)';
143
- stat.textContent=`${j.tokens} tokens · ${j.seconds}s · ${j.tok_per_s||''} tok/s · ${j.device}`;
144
- } else { out.textContent=j.message||'unavailable'; stat.textContent=j.status||''; }
 
 
 
 
 
 
 
 
 
145
  }catch(e){ out.textContent='Request failed: '+e; stat.textContent=''; }
146
  btn.disabled=false;
147
  }
 
134
  async function gen(){
135
  const prompt=document.getElementById('prompt').value.trim();
136
  if(!prompt){return}
137
+ btn.disabled=true; out.textContent=''; stat.textContent='generating (model may be loading on first call)…';
138
+ const t0=performance.now();
139
  try{
140
+ const r=await fetch('/api/stream',{method:'POST',headers:{'Content-Type':'application/json'},
141
  body:JSON.stringify({prompt:prompt,max_new_tokens:200,temperature:0.7})});
142
+ if(!r.body){ out.textContent=await r.text(); stat.textContent=''; btn.disabled=false; return; }
143
+ const reader=r.body.getReader(), dec=new TextDecoder();
144
+ let text='';
145
+ while(true){
146
+ const {done,value}=await reader.read();
147
+ if(done) break;
148
+ text+=dec.decode(value,{stream:true});
149
+ out.textContent=text;
150
+ stat.textContent=`streaming… ${((performance.now()-t0)/1000).toFixed(1)}s`;
151
+ }
152
+ const secs=((performance.now()-t0)/1000).toFixed(1);
153
+ out.textContent=text||'(empty)';
154
+ stat.textContent = r.status>=400 ? '' : `done · ${secs}s · live token streaming`;
155
  }catch(e){ out.textContent='Request failed: '+e; stat.textContent=''; }
156
  btn.disabled=false;
157
  }