Bende Whoops ve Veri Çekmeme Hatası Vardı hosting değiştirdim gene çalışmadı sonra aklıma APİ'yi çekiyor mu acaba sorusu geldi
<!DOCTYPE html>
<html>
<head>
<title>API TEST</title>
<meta charset="utf-8">
</head>
<body>
<h1>API TEST :D</h1>
<label for="input">Girdi:</label><br>
<input type="text" id="input" required><br><br>
<button id="sendBtn">Gönder</button>
<div id="response"></div>
<script>
// API anahtarınızı buraya girin
const apiKey = "API_ANAHTARINIZI_GIRINIZ";
// API endpointi
const apiUrl = "https://api.openai.com/v1/chat/completions";
// Gönderme butonuna tıklanınca yapılacak işlem
document.getElementById("sendBtn").addEventListener("click", function() {
// Kullanıcının girdisi
const input = document.getElementById("input").value;
// Gönderilecek veri
const data = {
model: "gpt-3.5-turbo",
messages: [{
role: "user",
content: input
}]
};
// fetch kullanarak API'ye veri gönderme
fetch(apiUrl, {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
throw new Error("API isteği başarısız.");
}
return response.json();
})
.then(responseData => {
// API yanıtındaki veriyi al ve ekrana yazdır
const responseText = responseData.choices[0].message.content;
document.getElementById("response").innerHTML = responseText;
})
.catch(error => {
// Hata durumunda hata mesajını al ve ekrana yazdır
const errorMessage = error.message || "Bir hata oluştu.";
document.getElementById("response").innerHTML = errorMessage;
});
});
</script>
</body>
</html>Bu javascript e api keyinizi girip html olarak masaüstününe kaydedip, chrome ile çalıştırabilirsiniz. Bende "API isteği başarısız." yazınca anladım neden çekmediğini. 5sim.net ve tempmail yardımıyla yeni hesap oluşturup apisi ile denedim sonuç çalıştı.
Bu arada belki hosting soran olur Cenuta'da denedim çalışmadı (bu arada pek çok sitem var Cenuta'da iyi hosting firmasıdır kötülemek için yazmıyorum sadece bunda sıkıntı verdiğini gördüm, r10 da biraz araştırdım vihyper.net ten deneme için 1 aylık aldım sorunsuz çalıştı AI Scripti)