File size: 1,769 Bytes
c04e9aa
608081c
c04e9aa
 
 
 
 
608081c
c04e9aa
 
 
 
 
 
 
 
 
 
 
 
f164c51
c04e9aa
f164c51
c04e9aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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();
    }