Update index.html

This commit is contained in:
B14ckR41n 2023-01-20 08:39:23 -05:00 committed by GitHub
parent 04dab03a80
commit 24b60853c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,3 +16,34 @@
<div id="chatbot-response"></div> <div id="chatbot-response"></div>
</div> </div>
{% endblock %} {% endblock %}
<script>
const form = document.getElementById('chatbot-form');
const input = document.getElementById('chatbot-input');
const responseContainer = document.getElementById('chatbot-response');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const message = input.value;
// Make the API call to GPT-3
const apiKey = 'YOUR_API_KEY';
const response = await fetch(`https://api.openai.com/v1/engines/davinci-codex/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify({
prompt: message,
max_tokens: 128,
})
});
const json = await response.json();
const answer = json.choices[0].text;
// Display the response
responseContainer.innerHTML = answer;
});
</script>