Update app.js
Browse files
app.js
CHANGED
@@ -1,23 +1,50 @@
|
|
1 |
-
|
2 |
-
const key = document.getElementById("apiKey").value;
|
3 |
-
const model = document.getElementById("model").value;
|
4 |
-
const prompt = document.getElementById("prompt").value;
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
"HTTP-Referer": "https://example.com"
|
12 |
-
},
|
13 |
-
body: JSON.stringify({
|
14 |
-
model,
|
15 |
-
messages: [{ role: "user", content: prompt }],
|
16 |
-
temperature: 0.7
|
17 |
-
})
|
18 |
-
});
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const results = [];
|
|
|
|
|
|
|
2 |
|
3 |
+
document.getElementById('fileUpload').addEventListener('change', async function () {
|
4 |
+
const file = this.files[0];
|
5 |
+
if (!file) return;
|
6 |
+
const text = await file.text();
|
7 |
+
const prompts = text.split(/\r?\n/).filter(Boolean);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
for (const prompt of prompts) {
|
10 |
+
await send(prompt);
|
11 |
+
}
|
12 |
+
});
|
13 |
+
|
14 |
+
async function send(overridePrompt) {
|
15 |
+
const key = document.getElementById("apiKey").value;
|
16 |
+
const model = document.getElementById("model").value;
|
17 |
+
const prompt = overridePrompt || document.getElementById("prompt").value;
|
18 |
+
|
19 |
+
const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
|
20 |
+
method: "POST",
|
21 |
+
headers: {
|
22 |
+
"Authorization": "Bearer " + key,
|
23 |
+
"Content-Type": "application/json",
|
24 |
+
"HTTP-Referer": "https://example.com"
|
25 |
+
},
|
26 |
+
body: JSON.stringify({
|
27 |
+
model,
|
28 |
+
messages: [{ role: "user", content: prompt }],
|
29 |
+
temperature: 0.7
|
30 |
+
})
|
31 |
+
});
|
32 |
+
|
33 |
+
const data = await res.json();
|
34 |
+
const output = data.choices?.[0]?.message?.content || JSON.stringify(data);
|
35 |
+
document.getElementById("response").textContent = output;
|
36 |
+
|
37 |
+
results.push({ model, prompt, output });
|
38 |
+
}
|
39 |
+
|
40 |
+
function downloadCSV() {
|
41 |
+
let csv = "Model,Prompt,Output\n";
|
42 |
+
results.forEach(row => {
|
43 |
+
csv += `"${row.model}","${row.prompt.replace(/\n/g, " ")}","${row.output.replace(/\n/g, " ")}"\n`;
|
44 |
+
});
|
45 |
+
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
46 |
+
const link = document.createElement("a");
|
47 |
+
link.href = URL.createObjectURL(blob);
|
48 |
+
link.download = "llm_test_results.csv";
|
49 |
+
link.click();
|
50 |
+
}
|