-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (35 loc) · 1.3 KB
/
app.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
const form = document.getElementById("chat-form");
const input = document.getElementById("chat-input");
const messages = document.getElementById("chat-messages");
const apiKey = "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";
form.addEventListener("submit", async (e) => {
e.preventDefault();
const message = input.value;
input.value = "";
messages.innerHTML += `<div class="message user-message">
<img src="C:\Users\mateeb.ce41ceme\Desktop\radixgpt_UI\icons\me.png" alt="user icon"> <span>${message}</span>
</div>`;
if (!document.getElementById("chat-messages")) {
console.error("Element with ID 'chat-messages' not found in the HTML document");
}
// Use axios library to make a POST request to the OpenAI API
const response = await axios.post(
"https://api.openai.com/v1/completions",
{
prompt: message,
model: "text-davinci-003",
temperature: 10,
max_tokens: 1000,
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
},
}
);
const chatbotResponse = response.data.choices[0].text;
messages.innerHTML += `<div class="message bot-message">
<img src="C:\Users\mateeb.ce41ceme\Desktop\radixgpt_UI\icons\chatbot.png" alt="bot icon"> <span>${chatbotResponse}</span>
</div>`;
});