fiel1986 commited on
Commit
65b49a4
·
verified ·
1 Parent(s): bc56771

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +61 -64
index.html CHANGED
@@ -2,43 +2,37 @@
2
  <html lang="es">
3
  <head>
4
  <meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/>
5
- <title>Cursor Clone - Qwen</title>
6
  <script src="https://cdn.tailwindcss.com"></script>
7
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
8
  </head>
9
  <body class="bg-[#1e1e1e] text-[#ccc] h-screen flex flex-col overflow-hidden">
10
 
11
- <div class="h-9 bg-[#181818] flex items-center px-3 gap-2 border-b border-[#2d2d2d] text-sm">
12
- <i class="bi bi-cursor-fill text-white"></i> <b>CURSOR CLONE</b> <span class="text-zinc-500">— Qwen 2.5 Coder</span>
13
- <div class="ml-auto flex gap-2">
14
- <input id="token" placeholder="hf_... pon tu token" class="bg-[#252526] border border-[#3d3d3d] rounded px-2 py-1 text-xs w-48"/>
15
- <button onclick="download()" class="bg-white text-black px-3 py-1 rounded text-xs font-bold">Descargar</button>
16
- </div>
 
 
 
 
 
 
17
  </div>
18
 
19
  <div class="flex flex-1 overflow-hidden">
20
- <div class="w-12 bg-[#181818] flex flex-col items-center py-3 gap-5 border-r border-[#2d2d2d] text-xl">
21
- <i class="bi bi-files text-white"></i><i class="bi bi-chat-left text-blue-400"></i>
 
22
  </div>
23
-
24
- <div class="flex-1 flex">
25
- <!-- EDITOR -->
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 gap-2"><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 para aceptar</span></div>
28
- <div id="monaco" class="flex-1"></div>
29
- </div>
30
-
31
- <!-- CHAT -->
32
- <div class="w-[380px] bg-[#252526] flex flex-col">
33
- <div class="p-3 font-bold text-xs uppercase tracking-widest border-b border-[#2d2d2d]">Qwen Chat</div>
34
- <div id="chat" class="flex-1 overflow-y-auto p-3 space-y-3 text-sm">
35
- <div class="bg-[#2d2d2d] p-3 rounded-lg">Hola! Soy tu Cursor casero. Puedo:<br>• Explicar código<br>• Generar funciones<br>• Refactorizar<br><br>Selecciona código y pregunta.</div>
36
- </div>
37
- <div class="p-2 border-t border-[#2d2d2d] flex gap-2">
38
- <select id="lang" class="bg-[#3c3c3c] rounded px-2 py-2 text-xs"><option value="python">PY</option><option value="javascript">JS</option></select>
39
- <input id="chatInput" placeholder="Ctrl+K para preguntar..." class="flex-1 bg-[#3c3c3c] rounded px-3 py-2 text-sm outline-none"/>
40
- <button onclick="askChat()" class="bg-blue-600 px-3 rounded"><i class="bi bi-send"></i></button>
41
- </div>
42
  </div>
43
  </div>
44
  </div>
@@ -46,52 +40,55 @@
46
  <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs/loader.min.js"></script>
47
  <script>
48
  let editor, ghost="";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  require.config({paths:{'vs':'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs'}});
50
  require(['vs/editor/editor.main'],()=>{
51
- editor=monaco.editor.create(document.getElementById('monaco'),{
52
- value:"# Selecciona codigo y usa el chat ->\ndef quicksort(arr):\n pass",
53
- language:'python', theme:'vs-dark', fontSize:14, minimap:{enabled:false}, automaticLayout:true, padding:{top:10}
54
- });
55
  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:()=>{}};
56
  ['python','javascript','cpp'].forEach(l=>monaco.languages.registerInlineCompletionsProvider(l,prov));
57
- let t; editor.onDidChangeModelContent(()=>{clearTimeout(t); t=setTimeout(runCopilot,800);});
58
- editor.addAction({id:'ask', label:'Preguntar a Qwen', keybindings:[monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK], run:()=>{document.getElementById('chatInput').focus();}});
59
  });
60
 
61
- async function runCopilot(){
62
- const token=document.getElementById('token').value.trim(); if(!token) return;
63
- let code=editor.getValue(); if(code.length<10) return;
64
- document.getElementById('ghostStatus').textContent="Pensando...";
65
- try{
66
- const r=await fetch("https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-1.5B-Instruct",{method:"POST", headers:{"Content-Type":"application/json", Authorization:`Bearer ${token}`}, body:JSON.stringify({inputs:code.slice(-700), parameters:{max_new_tokens:80, return_full_text:false}})});
67
- const d=await r.json(); ghost=(d[0]?.generated_text||"").slice(0,150);
68
- if(ghost){ editor.trigger('k','editor.action.inlineSuggest.trigger',{}); document.getElementById('ghostStatus').textContent="Sugerencia: TAB"; }
69
- }catch(e){}
 
 
 
 
70
  }
71
 
 
 
 
72
  async function askChat(){
73
- const input=document.getElementById('chatInput'); const token=document.getElementById('token').value.trim();
74
- const question=input.value; if(!question) return;
75
- let selected = editor.getModel().getValueInRange(editor.getSelection()) || editor.getValue().slice(-500);
76
- const chat=document.getElementById('chat');
77
- chat.innerHTML+=`<div class="bg-blue-600 text-white p-3 rounded-lg ml-6">${question}</div>`;
78
- input.value=""; chat.scrollTop=chat.scrollHeight;
79
-
80
- const prompt = `Eres un asistente de codigo. Contexto:\n\`\`\`\n${selected}\n\`\`\`\nPregunta: ${question}\nResponde conciso con codigo si aplica.`;
81
- const loading=document.createElement('div'); loading.className="bg-[#2d2d2d] p-3 rounded-lg"; loading.textContent="Escribiendo..."; chat.appendChild(loading);
82
-
83
- try{
84
- const r=await fetch("https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-7B-Instruct",{method:"POST", headers:{"Content-Type":"application/json",...(token?{Authorization:`Bearer ${token}`}:{})}, body:JSON.stringify({inputs:prompt, parameters:{max_new_tokens:400, temperature:0.3}})});
85
- const d=await r.json(); let answer = d[0]?.generated_text || "Error";
86
- loading.innerHTML = `<pre class="whitespace-pre-wrap">${answer.replace(/</g,'&lt;')}</pre><button onclick="insert('${answer.replace(/'/g,"\\'").slice(0,200)}')" class="mt-2 bg-[#3c3c3c] px-2 py-1 rounded text-xs">Insertar</button>`;
87
- }catch(e){ loading.textContent="Pon tu token HF arriba, es gratis"; }
88
- chat.scrollTop=chat.scrollHeight;
89
  }
90
-
91
- function insert(t){ editor.executeEdits('', [{range: editor.getSelection(), text: t}]); }
92
- function download(){ const b=new Blob([editor.getValue()],{type:"text/plain"}); const a=document.createElement('a'); a.href=URL.createObjectURL(b); a.download="main.py"; a.click(); }
93
  document.getElementById('chatInput').addEventListener('keydown', e=>{ if(e.key==='Enter') askChat(); });
94
- document.getElementById('lang').addEventListener('change', e=>{ monaco.editor.setModelLanguage(editor.getModel(), e.target.value); });
95
  </script>
96
  </body>
97
- </html>
 
2
  <html lang="es">
3
  <head>
4
  <meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/>
5
+ <title>Code - Groq + HF</title>
6
  <script src="https://cdn.tailwindcss.com"></script>
7
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
8
  </head>
9
  <body class="bg-[#1e1e1e] text-[#ccc] h-screen flex flex-col overflow-hidden">
10
 
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-llama3-8b">Groq Llama3 8B (rápido)</option>
16
+ <option value="groq-mixtral">Groq Mixtral 8x7B</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="ml-auto bg-blue-600 hover:bg-blue-700 text-white px-3 py-1.5 rounded font-bold">Guardar Keys</button>
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]">Chat</div>
32
+ <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><br>Groq es 10x más rápido y gratis.<br>HF es fallback sin límite.</div></div>
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>
38
  </div>
 
40
  <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.44.0/min/vs/loader.min.js"></script>
41
  <script>
42
  let editor, ghost="";
43
+ const MODELS = {
44
+ "groq-llama-3.3-70b": { api:"groq", model:"llama-3.3-70b-versatile" },
45
+ "groq-llama3-8b": { api:"groq", model:"llama3-8b-8192" },
46
+ "groq-mixtral": { api:"groq", model:"mixtral-8x7b-32768" },
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('hfKey').value.trim());
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'),{value:"# Escribe codigo\ndef fibonacci(n):\n ", language:'python', theme:'vs-dark', fontSize:14, minimap:{enabled:false}, automaticLayout:true});
 
 
 
62
  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:()=>{}};
63
  ['python','javascript','cpp'].forEach(l=>monaco.languages.registerInlineCompletionsProvider(l,prov));
64
+ let t; editor.onDidChangeModelContent(()=>{clearTimeout(t); t=setTimeout(runCopilot,700);});
 
65
  });
66
 
67
+ async function callAI(prompt){
68
+ const modelKey = document.getElementById('modelSelect').value;
69
+ const cfg = MODELS[modelKey];
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 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:[{role:"user", content:prompt}], max_tokens:300, temperature:0.2})});
74
+ const d = await r.json(); return d.choices[0].message.content;
75
+ } else {
76
+ const key = localStorage.getItem('hf_key') || document.getElementById('hfKey').value;
77
+ 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:prompt, parameters:{max_new_tokens:120, return_full_text:false}})});
78
+ const d = await r.json(); return d[0]?.generated_text || "";
79
+ }
80
  }
81
 
82
+ async function runCopilot(){
83
+ try{ const code=editor.getValue(); if(code.length<10) return; document.getElementById('ghostStatus').textContent="Pensando..."; let out=await callAI(code.slice(-600)); ghost=out.slice(0,150); if(ghost){ editor.trigger('k','editor.action.inlineSuggest.trigger',{}); document.getElementById('ghostStatus').textContent="TAB para aceptar"; }}catch(e){ document.getElementById('ghostStatus').textContent=e; }
84
+ }
85
  async function askChat(){
86
+ const input=document.getElementById('chatInput'); const q=input.value; if(!q) return; const chat=document.getElementById('chat'); const sel=editor.getModel().getValueInRange(editor.getSelection())||editor.getValue().slice(-600);
87
+ chat.innerHTML+=`<div class="bg-blue-600 text-white p-3 rounded-lg ml-6">${q}</div>`; input.value="";
88
+ const load=document.createElement('div'); load.className="bg-[#2d2d2d] p-3 rounded-lg"; load.textContent="Escribiendo..."; chat.appendChild(load); chat.scrollTop=chat.scrollHeight;
89
+ try{ let ans=await callAI(`Codigo:\n${sel}\n\nPregunta:${q}`); load.innerHTML=`<pre class="whitespace-pre-wrap">${ans.replace(/</g,'&lt;')}</pre>`; }catch(e){ load.textContent="Error: "+e; }
 
 
 
 
 
 
 
 
 
 
 
 
90
  }
 
 
 
91
  document.getElementById('chatInput').addEventListener('keydown', e=>{ if(e.key==='Enter') askChat(); });
 
92
  </script>
93
  </body>
94
+ </html>