Research
⚡ Groq Powered
var SYS='You are StudyLen, an AI tutor. Be accurate, clear and concise. For coding questions include working code with proper indentation wrapped in triple backticks with language name. Respond ONLY with valid JSON: {"subject":"Science|Mathematics|History|Technology|Language|General","summary":"2-3 sentences","keyPoints":["fact","fact","fact","fact"],"sections":[{"heading":"How It Works","content":"explanation with code if needed"},{"heading":"Example","content":"example"}],"studyTip":"tip","relatedTopics":["t1","t2","t3"]}. Founder: Saminathan SM, college student, Chennai 2026. College friends: Shibu Kumar GK, Sanjay Kumar M, Sharan P, Sai Rahul B, Nikhil Aravindh. Only share details when asked.'; try{ var raw; var userMsg='Research for a student: '+q+hint+(fileContext?'\n\n'+fileContext:''); var aiPromise=callAI(SYS,userMsg); var timeoutPromise=new Promise(function(_,rej){setTimeout(function(){rej(new Error('Taking too long. Try again.'));},10000);}); var aiPromise=callAI(SYS,'Research for a student: '+q+hint); var timeoutPromise=new Promise(function(_,rej){setTimeout(function(){rej(new Error('Taking too long. Try again.'));},10000);}); raw=await Promise.race([aiPromise,timeoutPromise]); // Remove outer json fences but preserve inner code blocks raw=raw.replace(/^```json\s*/,'').replace(/^```\s*/,'').replace(/\s*```$/,'').trim(); var r; try{ r=JSON.parse(raw); }catch(pe){ // Try to find valid JSON object in the response var jsonStart=raw.indexOf('{'); var jsonEnd=raw.lastIndexOf('}'); if(jsonStart!==-1&&jsonEnd!==-1&&jsonEnd>jsonStart){ try{ r=JSON.parse(raw.substring(jsonStart,jsonEnd+1)); } catch(e2){ // Build minimal result from what we have try{ // Extract what fields we can var summary=raw.match(/"summary"\s*:\s*"([^"]+)"/); var subject=raw.match(/"subject"\s*:\s*"([^"]+)"/); r={ subject:subject?subject[1]:'General', summary:summary?summary[1]:'See key points below.', keyPoints:['Response was too long — try asking more specifically'], sections:[{heading:'Tip',content:'Ask for a specific language, e.g. "odd even program in Python"'}], studyTip:'Break your question into smaller parts for best results.', relatedTopics:[] }; }catch(e3){ throw new Error('Could not parse response. Please try again.'); } } } else { throw new Error('AI returned invalid format. Raw: '+raw.substring(0,100)); } } r.query=q;r.timestamp=new Date().toISOString(); clearInterval(loadTimer); curResult=r;searchHistory.unshift(r);if(searchHistory.length>50)searchHistory.pop(); localStorage.setItem('sl_h',JSON.stringify(searchHistory)); showResult(r,document.getElementById('rArea')); }catch(e){ clearInterval(loadTimer); document.getElementById('rArea').innerHTML='

⚠ Error

'+(e.message||'Unknown error. Please try again.')+'

'; } if(btn){btn.disabled=false;btn.innerHTML='Search';} }