neetnestor commited on
Commit
34c1901
1 Parent(s): 5254a31

Fix wrong prompt default value

Browse files
Files changed (2) hide show
  1. dist/index.js +1 -1
  2. src/index.js +10 -7
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]*`;document.addEventListener("DOMContentLoaded",(()=>{const grammarSelection=document.getElementById("grammar-selection"),ebnfContainer=document.getElementById("ebnf-grammar-container"),modelSelection=document.getElementById("model-selection"),ebnfTextarea=document.getElementById("ebnf-grammar"),promptTextarea=document.getElementById("prompt"),outputDiv=document.getElementById("output"),statsParagraph=document.getElementById("stats");ebnfTextarea.value=customGrammar,ebnfTextarea.onchange=A=>{customGrammar=A.target.value,console.log("Grammar updated: ",customGrammar)},grammarSelection.onchange=A=>{console.log("Grammar selection changed:",A.target.value),"json"===A.target.value?(ebnfContainer.classList.add("hidden"),useCustomGrammar=!1):(ebnfContainer.classList.remove("hidden"),useCustomGrammar=!0)};const availableModels=_charliefruan_web_llm__WEBPACK_IMPORTED_MODULE_0__.xn.model_list.filter((A=>A.model_id.startsWith("Llama-3-8B")||A.model_id.startsWith("Llama-3-70B")||A.model_id.startsWith("Llama-3.1-8B")||A.model_id.startsWith("Llama-3.1-70B")||A.model_id.startsWith("Llama-3.2-3B")||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.",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:customGrammar}:{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();outputDiv.innerHTML=highlight_js__WEBPACK_IMPORTED_MODULE_2__.A.highlight(finalMessage,{language:"json"}).value,usage&&(statsParagraph.textContent=`Prefill: ${usage.extra.prefill_tokens_per_s.toFixed(2)}, Decode: ${usage.extra.decode_tokens_per_s.toFixed(2)}, Grammar Init: ${usage.extra.grammar_init_ms.toFixed(2)}, Grammar Overhead Per Token: ${usage.extra.grammar_per_token_ms.toFixed(2)}`,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]*`;document.addEventListener("DOMContentLoaded",(()=>{const grammarSelection=document.getElementById("grammar-selection"),ebnfContainer=document.getElementById("ebnf-grammar-container"),modelSelection=document.getElementById("model-selection"),ebnfTextarea=document.getElementById("ebnf-grammar"),promptTextarea=document.getElementById("prompt"),outputDiv=document.getElementById("output"),statsParagraph=document.getElementById("stats");ebnfTextarea.value=customGrammar,ebnfTextarea.onchange=A=>{customGrammar=A.target.value,console.log("Grammar updated: ",customGrammar)},grammarSelection.onchange=A=>{console.log("Grammar selection changed:",A.target.value),"json"===A.target.value?(ebnfContainer.classList.add("hidden"),useCustomGrammar=!1):(ebnfContainer.classList.remove("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:customGrammar}:{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();outputDiv.innerHTML=highlight_js__WEBPACK_IMPORTED_MODULE_2__.A.highlight(finalMessage,{language:"json"}).value,usage&&(statsParagraph.textContent=`Prefill: ${usage.extra.prefill_tokens_per_s.toFixed(2)}, Decode: ${usage.extra.decode_tokens_per_s.toFixed(2)}, Grammar Init Overhead: ${usage.extra.grammar_init_ms.toFixed(2)}, Grammar Per Token Overhead: ${usage.extra.grammar_per_token_ms.toFixed(2)}`,statsParagraph.classList.remove("hidden"))}}))})()})();
src/index.js CHANGED
@@ -60,11 +60,7 @@ document.addEventListener("DOMContentLoaded", () => {
60
  const availableModels = prebuiltAppConfig.model_list
61
  .filter(
62
  (m) =>
63
- m.model_id.startsWith("Llama-3-8B") ||
64
- m.model_id.startsWith("Llama-3-70B") ||
65
- m.model_id.startsWith("Llama-3.1-8B") ||
66
- m.model_id.startsWith("Llama-3.1-70B") ||
67
- m.model_id.startsWith("Llama-3.2-3B") ||
68
  m.model_id.startsWith("Hermes-2") ||
69
  m.model_id.startsWith("Hermes-3") ||
70
  m.model_id.startsWith("Phi-3")
@@ -124,8 +120,15 @@ document.addEventListener("DOMContentLoaded", () => {
124
  })`);
125
 
126
  // Set initial prompt
127
- promptTextarea.value = `Hermione Granger is a character in Harry Potter. Please fill in the following information about this character in JSON format.`;
128
-
 
 
 
 
 
 
 
129
  // Generate button click handler
130
  document.getElementById("generate").onclick = async () => {
131
  const schemaInput = editor.getValue();
 
60
  const availableModels = prebuiltAppConfig.model_list
61
  .filter(
62
  (m) =>
63
+ m.model_id.startsWith("Llama-3") ||
 
 
 
 
64
  m.model_id.startsWith("Hermes-2") ||
65
  m.model_id.startsWith("Hermes-3") ||
66
  m.model_id.startsWith("Phi-3")
 
120
  })`);
121
 
122
  // Set initial prompt
123
+ promptTextarea.value = `Hermione Granger is a character in Harry Potter. Please fill in the following information about this character in JSON format.
124
+ Name is a string of character name.
125
+ House is one of Gryffindor, Hufflepuff, Ravenclaw, Slytherin.
126
+ Blood status is one of Pure-blood, Half-blood, Muggle-born.
127
+ Occupation is one of Student, Professor, Ministry of Magic, Other.
128
+ Wand is an object with wood, core, and length.
129
+ Alive is a boolean.
130
+ Patronus is a string.
131
+ `;
132
  // Generate button click handler
133
  document.getElementById("generate").onclick = async () => {
134
  const schemaInput = editor.getValue();