-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
48 lines (43 loc) · 1.5 KB
/
script.js
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
const send = document.getElementById("submit");
const clear = document.getElementById("clear");
const chat = document.getElementById("chat");
async function sendRequest() {
const query = document.getElementById("input").value;
const paragraph = document.createElement("p");
let response = await fetch("https://api.pawan.krd/v1/chat/completions", {
method: "POST",
headers: {
Authorization:
"Bearer pk-aUKWtOcIbCATnJMfPHQyaLWsQZPhdohFxdxrWpyKJYTzWnrD",
"Content-Type": "application/json",
},
// body: '{\n "model": "gpt-3.5-turbo",\n "max_tokens": 100,\n "messages": [\n {\n "role": "system",\n "content": "You are an helpful assistant."\n },\n {\n "role": "user",\n "content": "Who are you?"\n }\n ]\n}',
body: JSON.stringify({
model: "gpt-3.5-turbo",
max_tokens: 100,
messages: [
{
role: "system",
content: "You are an helpful assistant.",
},
{
role: "user",
content: query,
},
],
}),
});
const textNode = document.createTextNode(response);
paragraph.appendChild(textNode);
chat.appendChild(paragraph);
console.log(query);
//clear input field
document.getElementById("input").value = "";
}
//clear chat window
function clearRequest() {
window.location.reload();
}
// Attach event listeners
send.addEventListener("click", sendRequest);
clear.addEventListener("click", clearRequest);