neetnestor commited on
Commit
4b86d74
1 Parent(s): 6508682

Increase max token

Browse files
Files changed (2) hide show
  1. dist/index.js +1 -1
  2. src/index.js +5 -4
dist/index.js CHANGED
@@ -10,4 +10,4 @@ basic_boolean ::= "true" | "false"
10
  basic_null ::= "null"
11
  basic_array ::= "[" ("" | ws basic_any (ws "," ws basic_any)*) ws "]"
12
  basic_object ::= "{" ("" | ws basic_string ws ":" ws basic_any ( ws "," ws basic_string ws ":" ws basic_any)*) ws "}"
13
- ws ::= [\n\t]*`,grammarSelection.onchange=A=>{console.log("Grammar selection changed:",A.target.value),"json"===A.target.value?(ebnfContainer.classList.add("hidden"),schemaContainer.classList.remove("hidden"),useCustomGrammar=!1):(ebnfContainer.classList.remove("hidden"),schemaContainer.classList.add("hidden"),useCustomGrammar=!0)};const availableModels=_charliefruan_web_llm__WEBPACK_IMPORTED_MODULE_0__.xn.model_list.filter((A=>A.model_id.startsWith("Llama-3")||A.model_id.startsWith("Hermes-2")||A.model_id.startsWith("Hermes-3")||A.model_id.startsWith("Phi-3"))).map((A=>A.model_id));let selectedModel=availableModels[0];availableModels.forEach((A=>{const g=document.createElement("option");g.value=A,g.textContent=A,modelSelection.appendChild(g)})),modelSelection.value=selectedModel,modelSelection.onchange=A=>{selectedModel=A.target.value,engine=null};const editor=ace_builds__WEBPACK_IMPORTED_MODULE_1___default().edit("schema",{mode:"ace/mode/javascript",theme:"ace/theme/github",wrap:!0});editor.setTheme("ace/theme/github"),editor.setValue('Type.Object({\n "name": Type.String(),\n "house": Type.Enum({\n "Gryffindor": "Gryffindor",\n "Hufflepuff": "Hufflepuff",\n "Ravenclaw": "Ravenclaw",\n "Slytherin": "Slytherin",\n }),\n "blood_status": Type.Enum({\n "Pure-blood": "Pure-blood",\n "Half-blood": "Half-blood",\n "Muggle-born": "Muggle-born",\n }),\n "occupation": Type.Enum({\n "Student": "Student",\n "Professor": "Professor",\n "Ministry of Magic": "Ministry of Magic",\n "Other": "Other",\n }),\n "wand": Type.Object({\n "wood": Type.String(),\n "core": Type.String(),\n "length": Type.Number(),\n }),\n "alive": Type.Boolean(),\n "patronus": Type.String(),\n })'),promptTextarea.value="Hermione Granger is a character in Harry Potter. Please fill in the following information about this character in JSON format.\nName is a string of character name.\nHouse is one of Gryffindor, Hufflepuff, Ravenclaw, Slytherin.\nBlood status is one of Pure-blood, Half-blood, Muggle-born.\nOccupation is one of Student, Professor, Ministry of Magic, Other.\nWand is an object with wood, core, and length.\nAlive is a boolean.\nPatronus is a string.\n",document.getElementById("generate").onclick=async()=>{const schemaInput=editor.getValue();let T;try{T=eval(schemaInput)}catch(A){return void console.error("Invalid schema",A)}const schema=JSON.stringify(T);engine||(engine=await(0,_charliefruan_web_llm__WEBPACK_IMPORTED_MODULE_0__.L6)(selectedModel,{initProgressCallback:A=>{console.log(A),outputDiv.textContent=A.text}}));const request={stream:!0,stream_options:{include_usage:!0},messages:[{role:"user",content:promptTextarea.value}],max_tokens:128,response_format:useCustomGrammar?{type:"grammar",grammar:ebnfTextarea.value}:{type:"json_object",schema}};let curMessage="",usage=null;const generator=await engine.chatCompletion(request);for await(const A of generator){const g=A.choices[0]?.delta.content;g&&(curMessage+=g),A.usage&&(usage=A.usage),outputDiv.textContent=curMessage}const finalMessage=await engine.getMessage();if(outputDiv.innerHTML=highlight_js__WEBPACK_IMPORTED_MODULE_2__.A.highlight(finalMessage,{language:"json"}).value,usage){const A=[];usage.extra.prefill_tokens_per_s&&A.push(`Prefill: ${usage.extra.prefill_tokens_per_s.toFixed(1)} tok/s`),usage.extra.decode_tokens_per_s&&A.push(`Decode: ${usage.extra.decode_tokens_per_s.toFixed(1)} tok/s`),usage.extra.grammar_init_ms&&A.push(`Grammar Init Overhead: ${usage.extra.grammar_init_ms.toFixed(0)} ms`),usage.extra.grammar_per_token_ms&&A.push(`Grammar Per Token Overhead: ${usage.extra.grammar_per_token_ms.toFixed(2)} ms`),statsParagraph.textContent=A.join(", "),statsParagraph.classList.remove("hidden")}}}))})()})();
 
10
  basic_null ::= "null"
11
  basic_array ::= "[" ("" | ws basic_any (ws "," ws basic_any)*) ws "]"
12
  basic_object ::= "{" ("" | ws basic_string ws ":" ws basic_any ( ws "," ws basic_string ws ":" ws basic_any)*) ws "}"
13
+ ws ::= [\n\t]*`,grammarSelection.onchange=A=>{console.log("Grammar selection changed:",A.target.value),"json"===A.target.value?(ebnfContainer.classList.add("hidden"),schemaContainer.classList.remove("hidden"),useCustomGrammar=!1):(ebnfContainer.classList.remove("hidden"),schemaContainer.classList.add("hidden"),useCustomGrammar=!0)};const availableModels=_charliefruan_web_llm__WEBPACK_IMPORTED_MODULE_0__.xn.model_list.filter((A=>A.model_id.startsWith("Llama-3")||A.model_id.startsWith("Hermes-2")||A.model_id.startsWith("Hermes-3")||A.model_id.startsWith("Phi-3"))).map((A=>A.model_id));let selectedModel=availableModels[0];availableModels.forEach((A=>{const g=document.createElement("option");g.value=A,g.textContent=A,modelSelection.appendChild(g)})),modelSelection.value=selectedModel,modelSelection.onchange=A=>{selectedModel=A.target.value,engine=null};const editor=ace_builds__WEBPACK_IMPORTED_MODULE_1___default().edit("schema",{mode:"ace/mode/javascript",theme:"ace/theme/github",wrap:!0});editor.setTheme("ace/theme/github"),editor.setValue('Type.Object({\n "name": Type.String(),\n "house": Type.Enum({\n "Gryffindor": "Gryffindor",\n "Hufflepuff": "Hufflepuff",\n "Ravenclaw": "Ravenclaw",\n "Slytherin": "Slytherin",\n }),\n "blood_status": Type.Enum({\n "Pure-blood": "Pure-blood",\n "Half-blood": "Half-blood",\n "Muggle-born": "Muggle-born",\n }),\n "occupation": Type.Enum({\n "Student": "Student",\n "Professor": "Professor",\n "Ministry of Magic": "Ministry of Magic",\n "Other": "Other",\n }),\n "wand": Type.Object({\n "wood": Type.String(),\n "core": Type.String(),\n "length": Type.Number(),\n }),\n "alive": Type.Boolean(),\n "patronus": Type.String(),\n })'),promptTextarea.value="Hermione Granger is a character in Harry Potter. Please fill in the following information about this character in JSON format.\nName is a string of character name.\nHouse is one of Gryffindor, Hufflepuff, Ravenclaw, Slytherin.\nBlood status is one of Pure-blood, Half-blood, Muggle-born.\nOccupation is one of Student, Professor, Ministry of Magic, Other.\nWand is an object with wood, core, and length.\nAlive is a boolean.\nPatronus is a string.\n",document.getElementById("generate").onclick=async()=>{const schemaInput=editor.getValue();let T;try{T=eval(schemaInput)}catch(A){return void console.error("Invalid schema",A)}const schema=JSON.stringify(T);engine||(engine=await(0,_charliefruan_web_llm__WEBPACK_IMPORTED_MODULE_0__.L6)(selectedModel,{initProgressCallback:A=>{console.log(A),outputDiv.textContent=A.text}}));const request={stream:!0,stream_options:{include_usage:!0},messages:[{role:"user",content:promptTextarea.value}],max_tokens:512,response_format:useCustomGrammar?{type:"grammar",grammar:ebnfTextarea.value}:{type:"json_object",schema}};let curMessage="",usage=null;const generator=await engine.chatCompletion(request);for await(const A of generator){const g=A.choices[0]?.delta.content;g&&(curMessage+=g),A.usage&&(usage=A.usage),outputDiv.textContent=curMessage}const finalMessage=await engine.getMessage();if(outputDiv.innerHTML=highlight_js__WEBPACK_IMPORTED_MODULE_2__.A.highlight(finalMessage,{language:"json"}).value,usage){const A=[];console.log(usage),usage.extra.prefill_tokens_per_s&&A.push(`Prefill Speed: ${usage.extra.prefill_tokens_per_s.toFixed(1)} tok/s`),usage.extra.decode_tokens_per_s&&A.push(`Decode Speed: ${usage.extra.decode_tokens_per_s.toFixed(1)} tok/s`),usage.extra.grammar_init_ms&&A.push(`Grammar Init Overhead: ${usage.extra.grammar_init_ms.toFixed(0)} ms`),usage.extra.grammar_per_token_ms&&A.push(`Grammar Per-token Overhead: ${usage.extra.grammar_per_token_ms.toFixed(2)} ms`),statsParagraph.textContent=A.join(", "),statsParagraph.classList.remove("hidden")}}}))})()})();
src/index.js CHANGED
@@ -150,7 +150,7 @@ Patronus is a string.
150
  stream: true,
151
  stream_options: { include_usage: true },
152
  messages: [{ role: "user", content: promptTextarea.value }],
153
- max_tokens: 128,
154
  response_format: useCustomGrammar
155
  ? { type: "grammar", grammar: ebnfTextarea.value }
156
  : { type: "json_object", schema: schema },
@@ -174,13 +174,14 @@ Patronus is a string.
174
 
175
  if (usage) {
176
  const statsTextParts = [];
 
177
  if (usage.extra.prefill_tokens_per_s) {
178
- statsTextParts.push(`Prefill: ${usage.extra.prefill_tokens_per_s.toFixed(
179
  1
180
  )} tok/s`);
181
  }
182
  if (usage.extra.decode_tokens_per_s) {
183
- statsTextParts.push(`Decode: ${usage.extra.decode_tokens_per_s.toFixed(
184
  1
185
  )} tok/s`);
186
  }
@@ -190,7 +191,7 @@ Patronus is a string.
190
  )} ms`);
191
  }
192
  if (usage.extra.grammar_per_token_ms) {
193
- statsTextParts.push(`Grammar Per Token Overhead: ${usage.extra.grammar_per_token_ms.toFixed(
194
  2
195
  )} ms`);
196
  }
 
150
  stream: true,
151
  stream_options: { include_usage: true },
152
  messages: [{ role: "user", content: promptTextarea.value }],
153
+ max_tokens: 512,
154
  response_format: useCustomGrammar
155
  ? { type: "grammar", grammar: ebnfTextarea.value }
156
  : { type: "json_object", schema: schema },
 
174
 
175
  if (usage) {
176
  const statsTextParts = [];
177
+ console.log(usage);
178
  if (usage.extra.prefill_tokens_per_s) {
179
+ statsTextParts.push(`Prefill Speed: ${usage.extra.prefill_tokens_per_s.toFixed(
180
  1
181
  )} tok/s`);
182
  }
183
  if (usage.extra.decode_tokens_per_s) {
184
+ statsTextParts.push(`Decode Speed: ${usage.extra.decode_tokens_per_s.toFixed(
185
  1
186
  )} tok/s`);
187
  }
 
191
  )} ms`);
192
  }
193
  if (usage.extra.grammar_per_token_ms) {
194
+ statsTextParts.push(`Grammar Per-token Overhead: ${usage.extra.grammar_per_token_ms.toFixed(
195
  2
196
  )} ms`);
197
  }