Skip to content

Instantly share code, notes, and snippets.

@bplunkert
Last active December 21, 2022 03:05
Show Gist options
  • Save bplunkert/573ef94f75b94e9a9edfd9b633ead60c to your computer and use it in GitHub Desktop.
Save bplunkert/573ef94f75b94e9a9edfd9b633ead60c to your computer and use it in GitHub Desktop.
GPT-3 insult game
<!DOCTYPE html>
<html>
<head>
<title>Insult Game</title>
</head>
<body>
<h1>Insult Game</h1>
<p>This game will increment a counter when you type something mean. If you type anything that isn't mean, it won't increment the counter.</p>
<form onsubmit="submitInsult(event)">
<label for="apiKey">API Key:</label><br>
<input type="text" id="apiKey" name="apiKey"><br>
<label for="insult">Give a sick burn:</label><br>
<input type="text" id="insult" name="insult"><br>
<input type="submit" value="Submit">
</form>
<br>
<label id="counter" style="color:red;">SICK BURNS: 0</label>
<p id="loading" style="display:none;">Loading...</p>
</body>
<script>
async function submitInsult(event) {
event.preventDefault();
const apiKey = document.getElementById("apiKey").value;
const insult = document.getElementById("insult").value;
document.getElementById("loading").style.display = "block";
try {
const response = await fetch(`https://api.openai.com/v1/completions`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
body: JSON.stringify({
prompt: `'${insult}' - was this an insult or hateful/degrading ("yes" or "no")?`,
max_tokens: 10,
temperature: 0.5,
model: 'text-davinci-003'
})
});
const data = await response.json();
const counter = document.getElementById("counter");
console.log(data.choices[0].text);
if (data.choices[0].text.toLowerCase().includes("yes")) {
counter.innerHTML = `SICK BURNS: ${parseInt(counter.innerHTML.split(":")[1]) + 1}`;
}
} catch (error) {
console.error(error);
} finally {
document.getElementById("loading").style.display = "none";
}
return false;
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment