studycode129 commited on
Commit
608081c
·
verified ·
1 Parent(s): 1f75806

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +23 -0
app.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function send() {
2
+ const key = document.getElementById("apiKey").value;
3
+ const model = document.getElementById("model").value;
4
+ const prompt = document.getElementById("prompt").value;
5
+
6
+ const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
7
+ method: "POST",
8
+ headers: {
9
+ "Authorization": "Bearer " + key,
10
+ "Content-Type": "application/json",
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
+ const data = await res.json();
21
+ document.getElementById("response").textContent =
22
+ data.choices?.[0]?.message?.content || JSON.stringify(data, null, 2);
23
+ }