File size: 2,065 Bytes
21b5630 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
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();
}
|