I have a simple form on my website with text input. We want to make a call to the OpenAI API to ask ChatGPT to find some similar companies based on a job description that a user pastes in the text box.
So far, we haven't been able to get the return data to work. It is correctly sending the job description data, but it is not able to list a list of companies. How can we fix it?
const form = document.querySelector('form');
const generateButton = document.querySelector('#generate-button');
const companiesOutput = document.querySelector('#output-companies');
function generateCampaign(event) {
event.preventDefault();
const jobDescription = document.querySelector('#job-description').value;
fetch('https://api.openai.com/v1/engines/davinci-codex/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify({
prompt: `Give me 20 top-tier VC backed startup companies in the same space as the company in this job description:\n\n ${jobDescription}`,
max_tokens: 50,
temperature: 0.7
})
})
.then(response => response.json())
.then(data => {
const companiesList = data.choices[0].text;
companiesOutput.innerHTML = `<li>${companiesList}</li>`;
})
.catch(error => console.error(error));
};
form.addEventListener('submit', generateCampaign);