Does it mean that i cant use OpenAI API beeacuse i live in kosovo and it looks that OpenAI doesnt support its API services in certain countries. Or is just my code wrong? (Error 429)
type or paste code hereconst chatInput = document.querySelector(".chat-input textarea");
const sendChatBtn = document.querySelector(".chat-input span");
const chatBox = document.querySelector(".chatbox");
let userMessage;
const API_KEY = "MY_API_KEY";
const createChatLi = (message, className) => {
const chatLi = document.createElement("li")
chatLi.classList.add("chat", className);
let chatContent = className === "outgoing" ? `<p>${message}</p>` : `<span class="material-symbols-outlined">smart_toy</span><p>${message}</p>`;
chatLi.innerHTML = chatContent;
return chatLi
}
const generateResponse = (incomingChatLi) => {
const API_URL = "https://api.openai.com/v1/chat/completions"
const messageElement = incomingChatLi.querySelector("p")
const requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: userMessage}]
})
}
fetch(API_URL, requestOptions).then(res => res.json()).then(data =>{
messageElement.textContent = data.choices[0].message.content
}).catch((error) =>{
messageElement.textContent = "Oops! Something weent wrong. Please try again"
})
}
const handleChat = () => {
userMessage = chatInput.value.trim();
if(!userMessage) return;
Q
chatBox.appendChild(createChatLi(userMessage, "outgoing"));
setTimeout(() => {
const incomingChatLi = createChatLi("Thinking...", "incoming")
chatBox.appendChild(incomingChatLi);
generateResponse(incomingChatLi)
}, 600)
}
sendChatBtn.addEventListener("click", handleChat);