Update static/index.js
Browse files- static/index.js +79 -118
static/index.js
CHANGED
@@ -1,133 +1,94 @@
|
|
1 |
-
/* static/index.js
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
{
|
9 |
-
{
|
10 |
-
{
|
11 |
-
{
|
12 |
-
{
|
13 |
-
{
|
14 |
-
{
|
15 |
-
{ name: "SmolLM3‑3B", id: "HuggingFaceTB/SmolLM3-3B" },
|
16 |
-
{ name: "GLM‑4.1V‑9B‑Thinking", id: "THUDM/GLM-4.1V-9B-Thinking" },
|
17 |
-
{ name: "OpenAI GPT‑4", id: "openai/gpt-4", provider: "openai" },
|
18 |
-
{ name: "Gemini Pro", id: "gemini/pro", provider: "gemini" },
|
19 |
-
{ name: "Fireworks V1", id: "fireworks-ai/fireworks-v1", provider: "fireworks" },
|
20 |
-
// keep this array in sync with models.py if you add more!
|
21 |
];
|
22 |
-
|
23 |
-
|
24 |
-
"
|
25 |
-
"
|
26 |
-
"
|
27 |
-
"sql-cassandra","sql-plSQL","sql-hive","sql-pgSQL","sql-gql",
|
28 |
-
"sql-gpSQL","sql-sparkSQL","sql-esper"
|
29 |
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
/*
|
32 |
-
|
33 |
-
const
|
34 |
-
|
35 |
-
const fileInput = $('#reference-file');
|
36 |
-
const websiteInput = $('#website-url');
|
37 |
-
const langSelect = $('#language');
|
38 |
-
const webSearchChk = $('#web-search');
|
39 |
-
const codeOut = $('#code-output');
|
40 |
-
const previewFrame = $('#preview');
|
41 |
-
const historyList = $('#history-list');
|
42 |
-
const genBtn = $('#generate');
|
43 |
-
const clearBtn = $('#clear');
|
44 |
-
|
45 |
-
/* ~~~~~~~~~~~~~ 3. POPULATE SELECTS ~~~~~~~~~~~~~ */
|
46 |
-
AVAILABLE_MODELS.forEach(m => {
|
47 |
-
const opt = document.createElement('option');
|
48 |
-
opt.value = m.id;
|
49 |
-
opt.textContent = m.name;
|
50 |
-
opt.dataset.provider = m.provider || '';
|
51 |
-
modelSelect.appendChild(opt);
|
52 |
});
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
opt.value = lang;
|
57 |
-
opt.textContent = lang;
|
58 |
-
langSelect.appendChild(opt);
|
59 |
});
|
60 |
|
61 |
-
/*
|
62 |
document.querySelectorAll('.tabs[role="tablist"] button')
|
63 |
-
.forEach(btn
|
64 |
-
const
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
68 |
}));
|
69 |
|
70 |
-
/*
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
codeOut.textContent = '';
|
76 |
-
previewFrame.srcdoc = '';
|
77 |
-
historyList.innerHTML = '';
|
78 |
-
});
|
79 |
-
|
80 |
-
/* ~~~~~~~~~~~~~ 6. HISTORY HELPER ~~~~~~~~~~~~~ */
|
81 |
-
function logHistory(text) {
|
82 |
-
const li = document.createElement('li');
|
83 |
-
li.textContent = `${new Date().toLocaleTimeString()} – ${text.slice(0,40)}…`;
|
84 |
-
historyList.prepend(li);
|
85 |
-
}
|
86 |
|
87 |
-
/*
|
88 |
-
|
89 |
-
const
|
90 |
-
|
|
|
|
|
91 |
|
92 |
-
|
|
|
|
|
|
|
|
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
model_id: modelSelect.value,
|
98 |
-
language: langSelect.value,
|
99 |
-
web_search: webSearchChk.checked,
|
100 |
-
website_url: websiteInput.value || null
|
101 |
};
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
const file = fileInput.files[0];
|
106 |
-
body.file_name = file.name;
|
107 |
-
body.file_data = await file.text();
|
108 |
}
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
codeOut.textContent = code;
|
122 |
-
previewFrame.srcdoc = langSelect.value === 'html'
|
123 |
-
? code
|
124 |
-
: `<pre style="white-space:pre-wrap">${code.replace(/</g,'<')}</pre>`;
|
125 |
-
|
126 |
-
logHistory(prompt);
|
127 |
-
} catch (err) {
|
128 |
-
console.error(err);
|
129 |
-
codeOut.textContent = `/* ERROR: ${err.message} */`;
|
130 |
-
} finally {
|
131 |
-
genBtn.disabled = false; genBtn.textContent = 'Generate Code';
|
132 |
-
}
|
133 |
-
});
|
|
|
1 |
+
/* static/index.js – FULL FILE */
|
2 |
+
const MODELS = [
|
3 |
+
{name:"Qwen/Qwen3‑32B",id:"Qwen/Qwen3-32B"},
|
4 |
+
{name:"Moonshot Kimi‑K2",id:"moonshotai/Kimi-K2-Instruct",provider:"groq"},
|
5 |
+
{name:"DeepSeek V3",id:"deepseek-ai/DeepSeek-V3-0324"},
|
6 |
+
{name:"DeepSeek R1",id:"deepseek-ai/DeepSeek-R1-0528"},
|
7 |
+
{name:"ERNIE‑4.5‑VL",id:"baidu/ERNIE-4.5-VL-424B-A47B-Base-PT"},
|
8 |
+
{name:"MiniMax M1",id:"MiniMaxAI/MiniMax-M1-80k"},
|
9 |
+
{name:"Qwen3‑235B‑A22B",id:"Qwen/Qwen3-235B-A22B"},
|
10 |
+
{name:"SmolLM3‑3B",id:"HuggingFaceTB/SmolLM3-3B"},
|
11 |
+
{name:"GLM‑4.1V‑9B‑Thinking",id:"THUDM/GLM-4.1V-9B-Thinking"},
|
12 |
+
{name:"OpenAI GPT‑4",id:"openai/gpt-4",provider:"openai"},
|
13 |
+
{name:"Gemini Pro",id:"gemini/pro",provider:"gemini"},
|
14 |
+
{name:"Fireworks V1",id:"fireworks-ai/fireworks-v1",provider:"fireworks"}
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
];
|
16 |
+
const LANGS = [
|
17 |
+
"python","c","cpp","markdown","latex","json","html","css","javascript",
|
18 |
+
"jinja2","typescript","yaml","dockerfile","shell","r","sql","sql-msSQL",
|
19 |
+
"sql-mySQL","sql-mariaDB","sql-sqlite","sql-cassandra","sql-plSQL",
|
20 |
+
"sql-hive","sql-pgSQL","sql-gql","sql-gpSQL","sql-sparkSQL","sql-esper"
|
|
|
|
|
21 |
];
|
22 |
+
/* ---------- dom ---------- */
|
23 |
+
const $ = q => document.querySelector(q);
|
24 |
+
const modelSel = $('#model');
|
25 |
+
const promptIn = $('#prompt');
|
26 |
+
const fileIn = $('#reference-file');
|
27 |
+
const urlIn = $('#website-url');
|
28 |
+
const langSel = $('#language');
|
29 |
+
const wsCheck = $('#web-search');
|
30 |
+
const codeOut = $('#code-output');
|
31 |
+
const preview = $('#preview');
|
32 |
+
const histList = $('#history-list');
|
33 |
+
const genBtn = $('#generate');
|
34 |
+
const clrBtn = $('#clear');
|
35 |
|
36 |
+
/* ---------- populate ---------- */
|
37 |
+
MODELS.forEach(m=>{
|
38 |
+
const o=document.createElement('option');
|
39 |
+
o.value=m.id;o.textContent=m.name;o.dataset.provider=m.provider||'';modelSel.appendChild(o);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
});
|
41 |
+
LANGS.forEach(l=>{
|
42 |
+
const o=document.createElement('option');
|
43 |
+
o.value=o.textContent=l;langSel.appendChild(o);
|
|
|
|
|
|
|
44 |
});
|
45 |
|
46 |
+
/* ---------- tabs ---------- */
|
47 |
document.querySelectorAll('.tabs[role="tablist"] button')
|
48 |
+
.forEach(btn=>btn.addEventListener('click',()=>{
|
49 |
+
const list=btn.parentElement;
|
50 |
+
list.querySelectorAll('[role="tab"]').forEach(t=>{
|
51 |
+
const sel=t===btn;t.setAttribute('aria-selected',sel);
|
52 |
+
list.parentElement.querySelector(`#${t.getAttribute('aria-controls')}`).hidden=!sel;
|
53 |
+
});
|
54 |
}));
|
55 |
|
56 |
+
/* ---------- clear ---------- */
|
57 |
+
clrBtn.onclick=()=>{
|
58 |
+
promptIn.value='';fileIn.value='';urlIn.value='';
|
59 |
+
codeOut.textContent='';preview.srcdoc='';histList.innerHTML='';
|
60 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
/* ---------- helper ---------- */
|
63 |
+
const addHist=p=>{
|
64 |
+
const li=document.createElement('li');
|
65 |
+
li.textContent=`${new Date().toLocaleTimeString()} – ${p.slice(0,40)}…`;
|
66 |
+
histList.prepend(li);
|
67 |
+
};
|
68 |
|
69 |
+
/* ---------- generate ---------- */
|
70 |
+
genBtn.onclick=async()=>{
|
71 |
+
const prompt=promptIn.value.trim();
|
72 |
+
if(!prompt){alert('Please provide a prompt');return;}
|
73 |
+
genBtn.disabled=true;genBtn.textContent='Generating…';
|
74 |
|
75 |
+
const body={
|
76 |
+
prompt, model_id:modelSel.value, language:langSel.value,
|
77 |
+
web_search:wsCheck.checked, website_url:urlIn.value||null
|
|
|
|
|
|
|
|
|
78 |
};
|
79 |
+
if(fileIn.files.length){
|
80 |
+
body.file_name=fileIn.files[0].name;
|
81 |
+
body.file_data=Array.from(new Uint8Array(await fileIn.files[0].arrayBuffer())); // binary to int[]
|
|
|
|
|
|
|
82 |
}
|
83 |
|
84 |
+
try{
|
85 |
+
const res=await fetch('/run/predict',{
|
86 |
+
method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});
|
87 |
+
if(!res.ok) throw new Error(await res.text());
|
88 |
+
const {code}=await res.json();
|
89 |
+
codeOut.textContent=code;
|
90 |
+
preview.srcdoc=(langSel.value==='html')?code:`<pre>${code.replace(/</g,'<')}</pre>`;
|
91 |
+
addHist(prompt);
|
92 |
+
}catch(e){console.error(e);alert('Error – see console');}
|
93 |
+
genBtn.disabled=false;genBtn.textContent='Generate Code';
|
94 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|