Work-Assistant / index.html
chandrakant111's picture
Update index.html
ad1b162 verified
Raw History Blame Contribute Delete
2.53 kB
<!DOCTYPE html>
<html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/>
<title>Work Assistant</title>
<style>
body{font-family:system-ui;background:#f6f6f6;margin:0}
.top{background:#000;color:#fff;padding:16px;text-align:center;font-size:22px;font-weight:800}
#chat{max-width:800px;margin:0 auto;padding:20px 20px 130px}
.bubble{padding:12px 16px;border-radius:18px;margin:12px 0;max-width:80%;line-height:1.5;word-break:break-word}
.user{background:#000;color:#fff;margin-left:auto}
.ai{background:#fff;border:1px solid #ddd;white-space:pre-wrap}
.bar{position:fixed;bottom:0;left:0;right:0;background:#fff;padding:10px;display:flex;gap:6px;border-top:1px solid #ddd}
.bar input{padding:12px;border-radius:24px;border:1px solid #ccc;outline:none}
#key{flex:0 0 160px;background:#fff8e1}
#msg{flex:1}
.bar button{padding:12px 18px;border-radius:24px;border:none;background:#000;color:#fff;font-weight:700}
</style></head><body>
<div class="top">🤖 My Assistant</div>
<div id="chat"><div class="bubble ai">Nayi Groq Key neeche PEHLE box me daalo, fir baat karo. Purani wali key delete kar di hai.</div></div>
<div class="bar">
<input id="key" placeholder="Yahan gsk_ key daalo">
<input id="msg" placeholder="Yahan likho...">
<button onclick="go()">Send</button>
</div>
<script>
const keyInput=document.getElementById('key');
keyInput.value=localStorage.getItem('groq_key')||'';
keyInput.addEventListener('input',()=>localStorage.setItem('groq_key',keyInput.value));
async function go(){
let k=keyInput.value.trim();
let i=document.getElementById('msg');
let t=i.value.trim();
if(!t)return;
if(!k||!k.startsWith('gsk_')){alert('Pehle box me sahi gsk_ key daalo!');return;}
let c=document.getElementById('chat');
c.innerHTML+=`<div class="bubble user">${t}</div>`;
i.value='';
try{
let r=await fetch('https://api.groq.com/openai/v1/chat/completions',{
method:'POST',
headers:{'Content-Type':'application/json','Authorization':'Bearer '+k},
body:JSON.stringify({model:'openai/gpt-oss-20b',messages:[{role:'user',content:t}]})
});
let d=await r.json();
if(!r.ok) throw new Error(d.error?.message||JSON.stringify(d));
let ans=d.choices?.[0]?.message?.content||'Kuch nahi aaya';
c.innerHTML+=`<div class="bubble ai">${ans}</div>`;
}catch(e){
c.innerHTML+=`<div class="bubble ai">Error: ${e.message}. Key galat hai ya expire ho gayi. Nayi banao console.groq.com se</div>`;
}
window.scrollTo(0,document.body.scrollHeight);
}
</script></body></html>