Skip to content

Instantly share code, notes, and snippets.

@antoinefortin
Created January 25, 2023 06:25
Show Gist options
  • Save antoinefortin/682a54b0fef2ded5649318f436040c74 to your computer and use it in GitHub Desktop.
Save antoinefortin/682a54b0fef2ded5649318f436040c74 to your computer and use it in GitHub Desktop.
Bruh....
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<style type="text/css">
#input-prompt {
}
.button
{
border-style: solid;
border-radius: 2px;
border-width: 2px;
border-color: black;
}
</style>
</head>
<body>
<div class="container">
<form>
<div class="form-group">
<label for="input_text">Input Query</label>
<input type="text" class="form-control" id="input_text" placeholder="input query">
</div>
<button type="button" id="action_submit" class="btn btn-primary">Submit</button>
<button type="button" id="action_clear" class="btn btn-danger">Clear</button>
</form>
<div id="render_area">
</div>
</body>
<script type="text/javascript">
const params = new URLSearchParams(location.search);
const aptkn = params.get('keyfor')
window.addEventListener('keydown',function(e){if(e.keyIdentifier=='U+000A'||e.keyIdentifier=='Enter'||e.keyCode==13){if(e.target.nodeName=='INPUT'&&e.target.type=='text'){e.preventDefault();return false;}}},true);
var button = document.getElementById("action_submit");
var button_clear = document.getElementById("action_clear");
var input = document.getElementById("input_text");
var renderArea = document.getElementById("render_area");
button.addEventListener("click", function() {
const API_KEY = aptkn;
const model = "text-davinci-003"
const prompt = input.value;
fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
prompt: prompt,
model: model,
max_tokens: 2500,
})
})
.then(response => response.json())
.then(data => {
console.log(data.choices[0].text);
renderToArea(data.choices[0].text)
});
}); // end of click
function renderToArea(text)
{
renderArea.innerHTML = text;
}
button_clear.addEventListener("click", function() {
console.log("clear render area")
renderArea.innerHTML = " ";
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment