Update index.html
Browse files- index.html +131 -24
index.html
CHANGED
|
@@ -11,27 +11,47 @@
|
|
| 11 |
<div class="bg-[#181818] border-b border-[#2d2d2d] p-2 flex flex-wrap gap-2 items-center text-xs">
|
| 12 |
<span class="font-bold text-white"><i class="bi bi-cpu"></i> fiel1986/Code</span>
|
| 13 |
<select id="modelSelect" class="bg-[#252526] border border-[#3d3d3d] rounded px-2 py-1.5">
|
|
|
|
|
|
|
| 14 |
<option value="groq-openai/gpt-oss-120b">Groq oss-gpt-120B</option>
|
| 15 |
<option value="groq-openai/gpt-oss-20b">Groq oss-gpt-20B</option>
|
| 16 |
<option value="groq-qwen/qwen3.8-27b">Groq Qwen3.8 27B</option>
|
| 17 |
<option value="hf-qwen-1.5b">HF Qwen 1.5B Coder (gratis)</option>
|
| 18 |
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
<input id="groqKey" placeholder="gsk_... Groq API (tuya)" class="bg-[#252526] border border-[#3d3d3d] rounded px-2 py-1.5 w-44"/>
|
| 20 |
<input id="hfKey" placeholder="hf_... HF Token (tuyo)" class="bg-[#252526] border border-[#3d3d3d] rounded px-2 py-1.5 w-44"/>
|
| 21 |
<span class="text-[10px] text-zinc-500">🔒 Tus keys se guardan solo en tu navegador (localStorage), no en mi server</span>
|
| 22 |
-
<button onclick="saveKeys()" class="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
</div>
|
| 24 |
|
| 25 |
<div class="flex flex-1 overflow-hidden">
|
| 26 |
<div class="flex-1 flex flex-col border-r border-[#2d2d2d]">
|
| 27 |
-
<div class="h-8 bg-[#252526] flex items-center px-3 text-xs"><span class="bg-[#1e1e1e] px-3 py-1 border-t-2 border-blue-500">main.py</span><span id="ghostStatus" class="ml-auto text-zinc-500">TAB = aceptar</span></div>
|
| 28 |
<div id="monaco" class="flex-1"></div>
|
|
|
|
| 29 |
</div>
|
| 30 |
<div class="w-[380px] bg-[#252526] flex flex-col">
|
| 31 |
-
<div class="p-3 font-bold text-xs uppercase tracking-widest border-b border-[#2d2d2d]">
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
<div class="p-2 border-t border-[#2d2d2d] flex gap-2">
|
| 34 |
-
<input id="chatInput" placeholder="Pregunta..." class="flex-1 bg-[#3c3c3c] rounded px-3 py-2 text-sm outline-none"/>
|
| 35 |
<button onclick="askChat()" class="bg-blue-600 px-3 rounded"><i class="bi bi-send"></i></button>
|
| 36 |
</div>
|
| 37 |
</div>
|
|
@@ -41,54 +61,141 @@
|
|
| 41 |
<script>
|
| 42 |
let editor, ghost="";
|
| 43 |
const MODELS = {
|
|
|
|
|
|
|
| 44 |
"groq-openai/gpt-oss-120b": { api:"groq", model:"openai/gpt-oss-120b" },
|
| 45 |
"groq-openai/gpt-oss-20b": { api:"groq", model:"openai/gpt-oss-20b" },
|
| 46 |
"groq-qwen/qwen3.8-27b": { api:"groq", model:"qwen/qwen3.8-27b" },
|
| 47 |
"hf-qwen-1.5b": { api:"hf", model:"Qwen/Qwen2.5-Coder-1.5B-Instruct" }
|
| 48 |
-
}
|
|
|
|
|
|
|
| 49 |
window.onload = ()=>{
|
| 50 |
document.getElementById('groqKey').value = localStorage.getItem('groq_key')||"";
|
| 51 |
document.getElementById('hfKey').value = localStorage.getItem('hf_key')||"";
|
| 52 |
-
}
|
| 53 |
function saveKeys(){
|
| 54 |
localStorage.setItem('groq_key', document.getElementById('groqKey').value.trim());
|
| 55 |
-
localStorage.setItem('hf_key', document.getElementById('
|
| 56 |
alert("Keys guardadas en tu navegador!");
|
| 57 |
}
|
| 58 |
|
| 59 |
require.config({paths:{'vs':'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs'}});
|
| 60 |
require(['vs/editor/editor.main'],()=>{
|
| 61 |
-
editor=monaco.editor.create(document.getElementById('monaco'),{
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
});
|
| 66 |
|
| 67 |
-
|
| 68 |
-
const
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
if(cfg.api==="groq"){
|
| 71 |
const key = localStorage.getItem('groq_key') || document.getElementById('groqKey').value;
|
| 72 |
if(!key) throw "Pon tu gsk_... Groq key arriba";
|
| 73 |
-
const
|
| 74 |
-
const
|
|
|
|
|
|
|
|
|
|
| 75 |
} else {
|
| 76 |
const key = localStorage.getItem('hf_key') || document.getElementById('hfKey').value;
|
| 77 |
-
const
|
|
|
|
| 78 |
const d = await r.json(); return d[0]?.generated_text || "";
|
| 79 |
}
|
| 80 |
}
|
| 81 |
|
| 82 |
async function runCopilot(){
|
| 83 |
-
try{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
async function askChat(){
|
| 86 |
-
const input=document.getElementById('chatInput'); const q=input.value; if(!q) return;
|
| 87 |
-
chat
|
| 88 |
-
const
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
}
|
| 91 |
-
document.getElementById('chatInput').addEventListener('keydown', e=>{ if(e.key==='Enter') askChat(); });
|
| 92 |
</script>
|
| 93 |
</body>
|
| 94 |
</html>
|
|
|
|
| 11 |
<div class="bg-[#181818] border-b border-[#2d2d2d] p-2 flex flex-wrap gap-2 items-center text-xs">
|
| 12 |
<span class="font-bold text-white"><i class="bi bi-cpu"></i> fiel1986/Code</span>
|
| 13 |
<select id="modelSelect" class="bg-[#252526] border border-[#3d3d3d] rounded px-2 py-1.5">
|
| 14 |
+
<option value="groq-llama-3.3-70b">Groq Llama 3.3 70B</option>
|
| 15 |
+
<option value="groq-llama-3.1-8b">Groq Llama 3.1 8B (rápido)</option>
|
| 16 |
<option value="groq-openai/gpt-oss-120b">Groq oss-gpt-120B</option>
|
| 17 |
<option value="groq-openai/gpt-oss-20b">Groq oss-gpt-20B</option>
|
| 18 |
<option value="groq-qwen/qwen3.8-27b">Groq Qwen3.8 27B</option>
|
| 19 |
<option value="hf-qwen-1.5b">HF Qwen 1.5B Coder (gratis)</option>
|
| 20 |
</select>
|
| 21 |
+
<select id="langSelect" onchange="setLang()" class="bg-[#252526] border border-[#3d3d3d] rounded px-2 py-1.5">
|
| 22 |
+
<option value="python">Python</option>
|
| 23 |
+
<option value="javascript">JavaScript</option>
|
| 24 |
+
<option value="html">HTML</option>
|
| 25 |
+
<option value="cpp">C++</option>
|
| 26 |
+
<option value="typescript">TypeScript</option>
|
| 27 |
+
<option value="json">JSON</option>
|
| 28 |
+
</select>
|
| 29 |
<input id="groqKey" placeholder="gsk_... Groq API (tuya)" class="bg-[#252526] border border-[#3d3d3d] rounded px-2 py-1.5 w-44"/>
|
| 30 |
<input id="hfKey" placeholder="hf_... HF Token (tuyo)" class="bg-[#252526] border border-[#3d3d3d] rounded px-2 py-1.5 w-44"/>
|
| 31 |
<span class="text-[10px] text-zinc-500">🔒 Tus keys se guardan solo en tu navegador (localStorage), no en mi server</span>
|
| 32 |
+
<button onclick="saveKeys()" class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1.5 rounded font-bold">Guardar Keys</button>
|
| 33 |
+
<div class="ml-auto flex gap-2">
|
| 34 |
+
<button onclick="runCode()" title="Ejecutar (JS/HTML)"><i class="bi bi-play-fill text-green-400"></i></button>
|
| 35 |
+
<button onclick="downloadCode()" title="Descargar archivo"><i class="bi bi-download text-blue-400"></i> Descargar</button>
|
| 36 |
+
</div>
|
| 37 |
</div>
|
| 38 |
|
| 39 |
<div class="flex flex-1 overflow-hidden">
|
| 40 |
<div class="flex-1 flex flex-col border-r border-[#2d2d2d]">
|
| 41 |
+
<div class="h-8 bg-[#252526] flex items-center px-3 text-xs"><span id="fileName" class="bg-[#1e1e1e] px-3 py-1 border-t-2 border-blue-500">main.py</span><span id="ghostStatus" class="ml-auto text-zinc-500">TAB = aceptar</span></div>
|
| 42 |
<div id="monaco" class="flex-1"></div>
|
| 43 |
+
<iframe id="runner" class="hidden border-t border-[#2d2d2d] bg-white" style="height:200px;width:100%"></iframe>
|
| 44 |
</div>
|
| 45 |
<div class="w-[380px] bg-[#252526] flex flex-col">
|
| 46 |
+
<div class="p-3 font-bold text-xs uppercase tracking-widest border-b border-[#2d2d2d] flex justify-between items-center">
|
| 47 |
+
Chat
|
| 48 |
+
<label class="font-normal normal-case tracking-normal text-[10px] text-zinc-400 flex items-center gap-1 cursor-pointer">
|
| 49 |
+
<input type="checkbox" id="autoInsert" checked/> Auto-insertar código
|
| 50 |
+
</label>
|
| 51 |
+
</div>
|
| 52 |
+
<div id="chat" class="flex-1 overflow-y-auto p-3 space-y-3 text-sm"><div class="bg-[#2d2d2d] p-3 rounded-lg">Pon tus keys arriba → Guarda → Selecciona modelo.<br>Pide "escribe una función de..." y el código irá al editor.</div></div>
|
| 53 |
<div class="p-2 border-t border-[#2d2d2d] flex gap-2">
|
| 54 |
+
<input id="chatInput" placeholder="Pregunta o pide código..." class="flex-1 bg-[#3c3c3c] rounded px-3 py-2 text-sm outline-none"/>
|
| 55 |
<button onclick="askChat()" class="bg-blue-600 px-3 rounded"><i class="bi bi-send"></i></button>
|
| 56 |
</div>
|
| 57 |
</div>
|
|
|
|
| 61 |
<script>
|
| 62 |
let editor, ghost="";
|
| 63 |
const MODELS = {
|
| 64 |
+
"groq-llama-3.3-70b": { api:"groq", model:"llama-3.3-70b-versatile" },
|
| 65 |
+
"groq-llama-3.1-8b": { api:"groq", model:"llama-3.1-8b-instant" },
|
| 66 |
"groq-openai/gpt-oss-120b": { api:"groq", model:"openai/gpt-oss-120b" },
|
| 67 |
"groq-openai/gpt-oss-20b": { api:"groq", model:"openai/gpt-oss-20b" },
|
| 68 |
"groq-qwen/qwen3.8-27b": { api:"groq", model:"qwen/qwen3.8-27b" },
|
| 69 |
"hf-qwen-1.5b": { api:"hf", model:"Qwen/Qwen2.5-Coder-1.5B-Instruct" }
|
| 70 |
+
};
|
| 71 |
+
const EXT = { python:"py", javascript:"js", typescript:"ts", html:"html", cpp:"cpp", json:"json" };
|
| 72 |
+
|
| 73 |
window.onload = ()=>{
|
| 74 |
document.getElementById('groqKey').value = localStorage.getItem('groq_key')||"";
|
| 75 |
document.getElementById('hfKey').value = localStorage.getItem('hf_key')||"";
|
| 76 |
+
};
|
| 77 |
function saveKeys(){
|
| 78 |
localStorage.setItem('groq_key', document.getElementById('groqKey').value.trim());
|
| 79 |
+
localStorage.setItem('hf_key', document.getElementById('hf_key').value.trim());
|
| 80 |
alert("Keys guardadas en tu navegador!");
|
| 81 |
}
|
| 82 |
|
| 83 |
require.config({paths:{'vs':'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs'}});
|
| 84 |
require(['vs/editor/editor.main'],()=>{
|
| 85 |
+
editor = monaco.editor.create(document.getElementById('monaco'),{
|
| 86 |
+
value:"# Escribe codigo o pide al chat que escriba por ti\ndef fibonacci(n):\n pass\n",
|
| 87 |
+
language:'python', theme:'vs-dark', fontSize:14, minimap:{enabled:false}, automaticLayout:true
|
| 88 |
+
});
|
| 89 |
+
const prov={provideInlineCompletions:async(m,p)=>{ if(!ghost) return {items:[]}; return {items:[{insertText:ghost, range:new monaco.Range(p.lineNumber,p.column,p.lineNumber,p.column)}]} }, freeInlineCompletions:()=>{}};
|
| 90 |
+
['python','javascript','typescript','cpp','html'].forEach(l=>monaco.languages.registerInlineCompletionsProvider(l,prov));
|
| 91 |
+
let t; editor.onDidChangeModelContent(()=>{ clearTimeout(t); t=setTimeout(runCopilot,900); });
|
| 92 |
});
|
| 93 |
|
| 94 |
+
function setLang(){
|
| 95 |
+
const lang = document.getElementById('langSelect').value;
|
| 96 |
+
if(editor) monaco.editor.setModelLanguage(editor.getModel(), lang);
|
| 97 |
+
document.getElementById('fileName').textContent = "main." + (EXT[lang]||"txt");
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
// ===== Descarga del archivo =====
|
| 101 |
+
function downloadCode(){
|
| 102 |
+
const lang = document.getElementById('langSelect').value;
|
| 103 |
+
const blob = new Blob([editor.getValue()], {type:"text/plain;charset=utf-8"});
|
| 104 |
+
const a = document.createElement('a');
|
| 105 |
+
a.href = URL.createObjectURL(blob);
|
| 106 |
+
a.download = "main." + (EXT[lang]||"txt");
|
| 107 |
+
a.click();
|
| 108 |
+
URL.revokeObjectURL(a.href);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// ===== Ejecutar JS / HTML en iframe =====
|
| 112 |
+
function runCode(){
|
| 113 |
+
const lang = document.getElementById('langSelect').value;
|
| 114 |
+
const frame = document.getElementById('runner');
|
| 115 |
+
const code = editor.getValue();
|
| 116 |
+
if(lang==="html"){ frame.classList.remove('hidden'); frame.srcdoc = code; }
|
| 117 |
+
else if(lang==="javascript"){
|
| 118 |
+
frame.classList.remove('hidden');
|
| 119 |
+
frame.srcdoc = `<body style="font-family:monospace;background:#111;color:#0f0;padding:8px"><script>console.log=(...a)=>document.body.innerHTML+=a.join(' ')+'<br>';<\/script><script>${code.replace(/<\/script>/g,'<\\/script>')}<\/script></body>`;
|
| 120 |
+
} else alert("Solo JS y HTML se ejecutan aquí. Para Python usa 'Descargar' y córrelo local.");
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
async function callAI(prompt, system){
|
| 124 |
+
const cfg = MODELS[document.getElementById('modelSelect').value];
|
| 125 |
if(cfg.api==="groq"){
|
| 126 |
const key = localStorage.getItem('groq_key') || document.getElementById('groqKey').value;
|
| 127 |
if(!key) throw "Pon tu gsk_... Groq key arriba";
|
| 128 |
+
const msgs = []; if(system) msgs.push({role:"system",content:system}); msgs.push({role:"user",content:prompt});
|
| 129 |
+
const r = await fetch("https://api.groq.com/openai/v1/chat/completions",{method:"POST", headers:{"Content-Type":"application/json", Authorization:`Bearer ${key}`}, body:JSON.stringify({model:cfg.model, messages:msgs, max_tokens:4096, temperature:0.2})});
|
| 130 |
+
const d = await r.json();
|
| 131 |
+
if(d.error) throw d.error.message;
|
| 132 |
+
return d.choices[0].message.content;
|
| 133 |
} else {
|
| 134 |
const key = localStorage.getItem('hf_key') || document.getElementById('hfKey').value;
|
| 135 |
+
const full = (system?system+"\n\n":"") + prompt;
|
| 136 |
+
const r = await fetch(`https://router.huggingface.co/hf-inference/models/${cfg.model}`,{method:"POST", headers:{"Content-Type":"application/json",...(key?{Authorization:`Bearer ${key}`}:{})}, body:JSON.stringify({inputs:full, parameters:{max_new_tokens:1024, return_full_text:false}})});
|
| 137 |
const d = await r.json(); return d[0]?.generated_text || "";
|
| 138 |
}
|
| 139 |
}
|
| 140 |
|
| 141 |
async function runCopilot(){
|
| 142 |
+
try{
|
| 143 |
+
const code = editor.getValue(); if(code.length<10) return;
|
| 144 |
+
document.getElementById('ghostStatus').textContent="Pensando...";
|
| 145 |
+
let out = await callAI("Continúa exactamente este código, solo el fragmento que sigue:\n"+code.slice(-600));
|
| 146 |
+
ghost = out.slice(0,150).trim();
|
| 147 |
+
if(ghost){ editor.trigger('k','editor.action.inlineSuggest.trigger',{}); document.getElementById('ghostStatus').textContent="TAB para aceptar"; }
|
| 148 |
+
}catch(e){ document.getElementById('ghostStatus').textContent=String(e).slice(0,60); }
|
| 149 |
}
|
| 150 |
+
|
| 151 |
+
// Extraer bloque ```codigo``` de la respuesta
|
| 152 |
+
function extractCode(text){
|
| 153 |
+
const m = text.match(/```(?:\w+)?\n([\s\S]*?)```/);
|
| 154 |
+
return m ? m[1].trim() : null;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function insertIntoEditor(code){
|
| 158 |
+
const sel = editor.getSelection();
|
| 159 |
+
if(!sel || (sel.startLineNumber===1 && sel.endColumn===1 && editor.getValue()==="")){
|
| 160 |
+
editor.setValue(code);
|
| 161 |
+
} else if(sel.isEmpty()){
|
| 162 |
+
editor.executeEdits("chat",[{range:sel, text:code+"\n"}]);
|
| 163 |
+
} else {
|
| 164 |
+
editor.executeEdits("chat",[{range:sel, text:code}]);
|
| 165 |
+
}
|
| 166 |
+
editor.focus();
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
async function askChat(){
|
| 170 |
+
const input=document.getElementById('chatInput'); const q=input.value.trim(); if(!q) return;
|
| 171 |
+
const chat=document.getElementById('chat');
|
| 172 |
+
const sel = editor.getModel().getValueInRange(editor.getSelection());
|
| 173 |
+
const ctx = sel || editor.getValue().slice(-1500);
|
| 174 |
+
const lang = document.getElementById('langSelect').value;
|
| 175 |
+
chat.innerHTML += `<div class="bg-blue-600 text-white p-3 rounded-lg ml-6">${q.replace(/</g,'<')}</div>`;
|
| 176 |
+
input.value="";
|
| 177 |
+
const load=document.createElement('div'); load.className="bg-[#2d2d2d] p-3 rounded-lg"; load.textContent="Escribiendo...";
|
| 178 |
+
chat.appendChild(load); chat.scrollTop=chat.scrollHeight;
|
| 179 |
+
try{
|
| 180 |
+
const system = `Eres un asistente de código. Si te piden crear o modificar código, respóndelo dentro de un bloque \`\`\`${lang}\`\`\`. Responde breve en español fuera del código.`;
|
| 181 |
+
const ans = await callAI(`Lenguaje actual: ${lang}\nCódigo actual:\n${ctx}\n\nPetición: ${q}`, system);
|
| 182 |
+
const code = extractCode(ans);
|
| 183 |
+
const div=document.createElement('div'); div.className="bg-[#2d2d2d] p-3 rounded-lg space-y-2";
|
| 184 |
+
const pre=document.createElement('pre'); pre.className="whitespace-pre-wrap";
|
| 185 |
+
pre.textContent = code ? ans.replace(/```(\w+)?\n?/g,'').replace(/```/g,'').trim() : ans;
|
| 186 |
+
div.appendChild(pre);
|
| 187 |
+
if(code){
|
| 188 |
+
const btn=document.createElement('button');
|
| 189 |
+
btn.className="bg-green-600 hover:bg-green-700 text-white px-3 py-1 rounded text-xs font-bold";
|
| 190 |
+
btn.innerHTML='<i class="bi bi-braces"></i> → Insertar en editor';
|
| 191 |
+
btn.onclick=()=>{ insertIntoEditor(code); btn.textContent="✔ Insertado"; };
|
| 192 |
+
div.appendChild(btn);
|
| 193 |
+
if(document.getElementById('autoInsert').checked){ insertIntoEditor(code); btn.textContent="✔ Insertado (auto)"; }
|
| 194 |
+
}
|
| 195 |
+
load.replaceWith(div); chat.scrollTop=chat.scrollHeight;
|
| 196 |
+
}catch(e){ load.textContent="Error: "+e; }
|
| 197 |
}
|
| 198 |
+
document.getElementById('chatInput').addEventListener('keydown', e=>{ if(e.key==='Enter' && !e.shiftKey){ e.preventDefault(); askChat(); } });
|
| 199 |
</script>
|
| 200 |
</body>
|
| 201 |
</html>
|