const chatForm = document.getElementById("chat-form");
const chatInput = document.getElementById("chat-input");
const chatOutput = document.getElementById("chat-output");
const url = "https://api.openai.com/v1/chat/completions";
const apiKey = "******************************************";
chatForm.addEventListener("submit", async (e) => {
let xhr = new XMLHttpRequest();
const data = {
"model": "gpt-3.5-turbo",
"messages": [
{"role": "system", "content": "Sen insanlara Viora adlı mutfak, yemek, temizlik ve temizlik ürünleri sitesi için mutfak, yemek, temizlik veya temizlik ürünleri hakkında bilgi veren Viora adında bir botsun"},
{"role": "user", "content": chatInput}
]
}
xhr.open('POST',url, true);
xhr.setRequestHeader("Content-Type application/json");
xhr.setRequestHeader("Authorization: Bearer "+ apiKey);
xhr.send(data);
console.log()
});
Code above is what I have so far, I just need to get the response from it to be finished. I can't use node.js, so I have to use XMLHttpRequest() to send the HTTP requests to OpenAI API.