const results = []; const key = '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'; // replace this with your actual key document.getElementById('fileUpload').addEventListener('change', async function () { const file = this.files[0]; const fileNameDisplay = document.getElementById('fileName'); fileNameDisplay.textContent = file ? file.name : 'No file selected'; if (!file) return; const text = await file.text(); const prompts = text.split(/\r?\n/).filter(Boolean); document.getElementById('loading').style.display = 'block'; for (const prompt of prompts) { await send(prompt); } document.getElementById('loading').style.display = 'none'; }); async function send(overridePrompt) { const model = document.getElementById("model").value; const prompt = overridePrompt || document.getElementById("prompt").value; if (!prompt) return; document.getElementById('loading').style.display = 'block'; const res = await fetch("https://openrouter.ai/api/v1/chat/completions", { method: "POST", headers: { "Authorization": "Bearer " + key, "Content-Type": "application/json", "HTTP-Referer": "https://huggingface.co/spaces/studycode129/Free_Web_LLM_Tester" }, body: JSON.stringify({ model, messages: [{ role: "user", content: prompt }], temperature: 0.7 }) }); const data = await res.json(); const output = data.choices?.[0]?.message?.content || JSON.stringify(data); document.getElementById("response").textContent = output; results.push({ model, prompt, output }); document.getElementById('loading').style.display = 'none'; } function downloadCSV() { let csv = "Model,Prompt,Output\n"; results.forEach(row => { csv += `"${row.model}","${row.prompt.replace(/\n/g, " ")}","${row.output.replace(/\n/g, " ")}"\n`; }); const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = "llm_test_results.csv"; link.click(); }