mgbam commited on
Commit
2892395
·
verified ·
1 Parent(s): 1644837

Update static/index.js

Browse files
Files changed (1) hide show
  1. static/index.js +51 -66
static/index.js CHANGED
@@ -1,86 +1,86 @@
1
- /* static/index.js — AnyCoder front‑end logic */
2
 
3
- // ────── 1. MODEL LIST ──────
4
  const MODELS = [
5
- { name: "Moonshot Kimi‑K2", id: "moonshotai/Kimi-K2-Instruct", provider: "groq" },
6
- { name: "DeepSeek V3", id: "deepseek-ai/DeepSeek-V3-0324" },
7
- { name: "DeepSeek R1", id: "deepseek-ai/DeepSeek-R1-0528" },
8
- { name: "ERNIE‑4.5‑VL", id: "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT" },
9
- { name: "MiniMax M1", id: "MiniMaxAI/MiniMax-M1-80k" },
10
- { name: "Qwen3‑235B‑A22B", id: "Qwen/Qwen3-235B-A22B" },
11
- { name: "Qwen3‑235B‑A22B‑Instruct‑2507", id: "Qwen/Qwen3-235B-A22B-Instruct-2507" },
12
- { name: "Qwen3‑235B‑A22B‑Thinking", id: "Qwen/Qwen3-235B-A22B-Thinking" },
13
- { name: "Qwen3‑Coder‑480B‑A35B", id: "Qwen/Qwen3-Coder-480B-A35B-Instruct" },
14
- { name: "Qwen3‑32B", id: "Qwen/Qwen3-32B" },
15
- { name: "SmolLM3‑3B", id: "HuggingFaceTB/SmolLM3-3B" },
16
- { name: "GLM‑4.1V‑9B‑Thinking", id: "THUDM/GLM-4.1V-9B-Thinking" },
17
- /* optional premium providers keep but hide if you don't have keys */
18
- { name: "OpenAI GPT‑4", id: "openai/gpt-4", provider: "openai" },
19
- { name: "Gemini Pro", id: "gemini/pro", provider: "gemini" },
20
- { name: "Fireworks V1", id: "fireworks-ai/fireworks-v1", provider: "fireworks" }
21
  ];
22
 
23
- // ────── 2. LANGUAGE LIST ──────
24
  const LANGS = [
25
- "python","c","cpp","markdown","latex","json","html","css","javascript",
26
- "jinja2","typescript","yaml","dockerfile","shell","r","sql","sql-msSQL",
27
- "sql-mySQL","sql-mariaDB","sql-sqlite","sql-cassandra","sql-plSQL",
28
- "sql-hive","sql-pgSQL","sql-gql","sql-gpSQL","sql-sparkSQL","sql-esper"
29
  ];
30
 
31
- // ────── 3. DOM SHORTCUTS ──────
32
  const $ = s => document.querySelector(s);
33
  const els = {
34
- model: $("#model"), lang : $("#lang"), prompt: $("#prompt"),
35
- file : $("#file"), url : $("#url"), search: $("#search"),
36
- code : $("#code"), prev : $("#preview"), hist : $("#hist"),
37
- gen : $("#gen"), clr : $("#clear")
38
  };
39
 
40
- // ────── 4. POPULATE SELECTS ──────
41
- MODELS.forEach(m => els.model.append(new Option(m.name, m.id)));
42
- LANGS .forEach(l => els.lang .append(new Option(l.toUpperCase(), l)));
43
 
44
- // ────── 5. SIMPLE TAB SWITCHER ──────
45
  document.querySelectorAll(".tabs[role=tablist]").forEach(tl => {
46
- tl.addEventListener("click", ev => {
47
- if (ev.target.role !== "tab") return;
48
  tl.querySelectorAll("[role=tab]").forEach(t =>
49
- t.setAttribute("aria-selected", t === ev.target));
50
  tl.parentElement.querySelectorAll("[role=tabpanel]").forEach(p =>
51
- p.hidden = (p.id !== ev.target.getAttribute("aria-controls")));
52
  });
53
  });
54
 
55
- // ────── 6. CLEAR SESSION ──────
56
  els.clr.onclick = () => {
57
- els.prompt.value = ""; els.file.value = ""; els.url.value = "";
58
- els.code.textContent = ""; els.prev.srcdoc = ""; els.hist.innerHTML = "";
59
  };
60
 
61
- // ────── 7. ADD HISTORY LINE ──────
62
- const addHist = txt => {
63
- const li = document.createElement("li");
64
- li.textContent = `${new Date().toLocaleTimeString()} – ${txt.slice(0,40)}…`;
65
  els.hist.prepend(li);
66
  };
67
 
68
- // ────── 8. GENERATE (calls /run/predict) ──────
69
  els.gen.onclick = async () => {
70
  const prompt = els.prompt.value.trim();
71
- if (!prompt) return alert("Provide a prompt first.");
72
 
73
  els.gen.disabled = true; els.gen.textContent = "Generating…";
74
 
75
  // optional file upload
76
- let file_path = null;
77
  if (els.file.files.length) {
78
- const fd = new FormData(); fd.append("file", els.file.files[0]);
79
- const up = await fetch("/upload", { method:"POST", body: fd });
80
- file_path = (await up.json()).file;
81
  }
82
 
83
- const body = {
84
  prompt,
85
  model_id : els.model.value,
86
  language : els.lang.value,
@@ -92,19 +92,4 @@ els.gen.onclick = async () => {
92
  try {
93
  const r = await fetch("/run/predict", {
94
  method:"POST",
95
- headers:{ "Content-Type":"application/json" },
96
- body: JSON.stringify(body)
97
- });
98
- if (!r.ok) throw new Error(r.statusText);
99
- const [code] = await r.json(); // returns [code, history]
100
- els.code.textContent = code;
101
- els.prev.srcdoc = (els.lang.value === "html")
102
- ? code
103
- : `<pre style="white-space:pre-wrap">${code.replace(/</g,"&lt;")}</pre>`;
104
- addHist(prompt);
105
- } catch (err) {
106
- console.error(err); alert("Generation failed (see console).");
107
- } finally {
108
- els.gen.disabled = false; els.gen.textContent = "Generate code";
109
- }
110
- };
 
1
+ /* static/index.js — AnyCoder front‑end 2025‑07 */
2
 
3
+ /* 1) Model registry */
4
  const MODELS = [
5
+ {name:"Moonshot Kimi‑K2", id:"moonshotai/Kimi-K2-Instruct", provider:"groq"},
6
+ {name:"DeepSeek V3", id:"deepseek-ai/DeepSeek-V3-0324"},
7
+ {name:"DeepSeek R1", id:"deepseek-ai/DeepSeek-R1-0528"},
8
+ {name:"ERNIE‑4.5‑VL", id:"baidu/ERNIE-4.5-VL-424B-A47B-Base-PT"},
9
+ {name:"MiniMax M1", id:"MiniMaxAI/MiniMax-M1-80k"},
10
+ {name:"Qwen3‑235B‑A22B", id:"Qwen/Qwen3-235B-A22B"},
11
+ {name:"Qwen3‑235B‑A22B‑Instruct‑2507", id:"Qwen/Qwen3-235B-A22B-Instruct-2507"},
12
+ {name:"Qwen3‑235B‑A22B‑Thinking", id:"Qwen/Qwen3-235B-A22B-Thinking"},
13
+ {name:"Qwen3‑Coder‑480B‑A35B", id:"Qwen/Qwen3-Coder-480B-A35B-Instruct"},
14
+ {name:"Qwen3‑32B", id:"Qwen/Qwen3-32B"},
15
+ {name:"SmolLM3‑3B", id:"HuggingFaceTB/SmolLM3-3B"},
16
+ {name:"GLM‑4.1V‑9B‑Thinking", id:"THUDM/GLM-4.1V-9B-Thinking"},
17
+ /* premium providers (optional) */
18
+ {name:"OpenAI GPT‑4", id:"openai/gpt-4", provider:"openai"},
19
+ {name:"Gemini Pro", id:"gemini/pro", provider:"gemini"},
20
+ {name:"Fireworks V1", id:"fireworks-ai/fireworks-v1", provider:"fireworks"}
21
  ];
22
 
23
+ /* 2) Language list */
24
  const LANGS = [
25
+ "python","c","cpp","markdown","latex","json","html","css","javascript","jinja2",
26
+ "typescript","yaml","dockerfile","shell","r","sql","sql-msSQL","sql-mySQL",
27
+ "sql-mariaDB","sql-sqlite","sql-cassandra","sql-plSQL","sql-hive","sql-pgSQL",
28
+ "sql-gql","sql-gpSQL","sql-sparkSQL","sql-esper"
29
  ];
30
 
31
+ /* 3) DOM helpers */
32
  const $ = s => document.querySelector(s);
33
  const els = {
34
+ model: $("#model"), lang: $("#lang"), prompt: $("#prompt"),
35
+ file : $("#file"), url: $("#url"), search: $("#search"),
36
+ code : $("#code"), prev: $("#preview"), hist: $("#hist"),
37
+ gen : $("#gen"), clr: $("#clear")
38
  };
39
 
40
+ /* 4) Populate selects */
41
+ MODELS.forEach(m => els.model.add(new Option(m.name, m.id)));
42
+ LANGS .forEach(l => els.lang .add(new Option(l.toUpperCase(), l)));
43
 
44
+ /* 5) Basic tab switcher */
45
  document.querySelectorAll(".tabs[role=tablist]").forEach(tl => {
46
+ tl.addEventListener("click", e => {
47
+ if (e.target.role !== "tab") return;
48
  tl.querySelectorAll("[role=tab]").forEach(t =>
49
+ t.setAttribute("aria-selected", t===e.target));
50
  tl.parentElement.querySelectorAll("[role=tabpanel]").forEach(p =>
51
+ p.hidden = p.id !== e.target.getAttribute("aria-controls"));
52
  });
53
  });
54
 
55
+ /* 6) Clear */
56
  els.clr.onclick = () => {
57
+ els.prompt.value=""; els.file.value=""; els.url.value="";
58
+ els.code.textContent=""; els.prev.srcdoc=""; els.hist.innerHTML="";
59
  };
60
 
61
+ /* 7) History helper */
62
+ const addHist = text => {
63
+ const li=document.createElement("li");
64
+ li.textContent = `${new Date().toLocaleTimeString()} – ${text.slice(0,40)}…`;
65
  els.hist.prepend(li);
66
  };
67
 
68
+ /* 8) Generate POST /run/predict */
69
  els.gen.onclick = async () => {
70
  const prompt = els.prompt.value.trim();
71
+ if (!prompt) { alert("Enter a prompt first."); return; }
72
 
73
  els.gen.disabled = true; els.gen.textContent = "Generating…";
74
 
75
  // optional file upload
76
+ let file_path=null;
77
  if (els.file.files.length) {
78
+ const fd=new FormData(); fd.append("file", els.file.files[0]);
79
+ const up=await fetch("/upload",{method:"POST", body:fd});
80
+ file_path=(await up.json()).file;
81
  }
82
 
83
+ const payload = {
84
  prompt,
85
  model_id : els.model.value,
86
  language : els.lang.value,
 
92
  try {
93
  const r = await fetch("/run/predict", {
94
  method:"POST",
95
+ headers:{ "Content-Type":"application/j