studycode129's picture
Update app.js
c10af89 verified
raw
history blame
1.77 kB
const results = [];
document.getElementById('fileUpload').addEventListener('change', async function () {
const file = this.files[0];
if (!file) return;
const text = await file.text();
const prompts = text.split(/\r?\n/).filter(Boolean);
for (const prompt of prompts) {
await send(prompt);
}
});
async function send(overridePrompt) {
const model = document.getElementById("model").value;
const prompt = overridePrompt || document.getElementById("prompt").value;
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer " + "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",
"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 });
}
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();
}