Öne Çıkan Yayın Alanı
En Son Yayınlar
HATA SAYFASINI GÖRMEK İÇİN TIKLAYIN.
BUTONLARI NASIL YAPACAĞINIZI GÖRMEK İÇİN YORUMLARA BAKIN! BUTON TARZI 1 : BUTON…
NORMAL EKLENMİŞ YOTUBE VİDEOSU ÖZEL TASARIM GÖRÜNÜMÜ BUNU SAĞLAMAK İÇİN YORUMLAR KISMI…
RESİM DENEME İÇİNDEKİLER İÇİNDEKİLERİN İÇİNDEKİ Burada bişey yapmanıza gerek yok yazın…
Diğer yayınlar
openai
const API_KEY = "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";
const chatForm = document.getElementById("chat-form");
const chatInput = document.getElementById("chat-input");
const userMessages = document.getElementById("user-messages");
const botMessages = document.getElementById("bot-messages");
const clearChatButton = document.getElementById("clear-chat");
chatForm.addEventListener("submit", (e) => {
e.preventDefault();
const message = chatInput.value;
appendMessage(message, "user");
getChatbotResponse(message);
chatInput.value = "";
});
clearChatButton.addEventListener("click", () => {
userMessages.innerHTML = "";
botMessages.innerHTML = "";
});
function getChatbotResponse(message) {
const url = `https://api.openai.com/v1/engines/davinci/completions`;
const data = {
prompt: message,
api_key: API_KEY,
temperature: 0.5,
};
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data) => {
const response = data.choices[0].text;
appendMessage(response, "bot");
});
}
function appendMessage(message, sender) {
const messageElement = document.createElement("div");
messageElement.innerText = message;
if (sender === "user") {
userMessages.appendChild(messageElement);
} else {
botMessages.appendChild(messageElement);
}
}