gpt-test / index.html
abhattac's picture
debugging fetch
25dffb5
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>My static Space</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="card">
<h1>Welcome to my GPT test environment!</h1>
<p>Enter a prompt in the textbox to get started</p>
<textarea name="prompt" id="prompt" cols="30" rows="10"></textarea><br>
<button id="submit">Submit</button>
<p id="response"></p>
</div>
</body>
<script>
const btn = document.querySelector("#submit")
const textbox = document.querySelector("#prompt")
const res = document.querySelector("#response")
const prompt = textbox.value
btn.addEventListener("click", event => {
fetch(`/gpt?prompt=${prompt}`)
.then(res => {
console.log(res)
res.json()
})
.then(res => {
console.log(res)
res.textContent = res
})
.catch(err => {
console.log(err)
res.textContent = err
})
})
</script>
</html>