Scroll to top
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('#wpforms-form-2815283').addEventListener('submit', function (e) {
e.preventDefault(); // Prevent the form from submitting the traditional way
let userInput = document.querySelector('#wpforms-2815283-field_0').value; // Adjust field ID as necessary
let apiKey = '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'; // Replace with your actual GPT API key
fetch('https://api.openai.com/v1/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + apiKey
},
body: JSON.stringify({
model: "UK Racing Jargon Buster", // Replace with your model's name if needed
prompt: userInput,
max_tokens: 100
})
})
.then(response => response.json())
.then(data => {
document.querySelector('#gpt-response').innerText = data.choices[0].text.trim();
})
.catch(error => console.error('Error:', error));
});
});