When i type less than 3-5 characters, OpenAI API replies with random output and delayed for like 5 seconds (based on how long openai output is). Tried changing model and lowering max_tokens to 500.
#main.JS
const userInput = document.querySelector('.user-input');
const inputText = userInput.value;
const data = {
model: 'text-davinci-003',
prompt: inputText,
temperature: 0.7,
max_tokens: 2048,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0
};
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${openaiApiKey}`
},
body: JSON.stringify(data)
};
try {
const response = await fetch('https://api.openai.com/v1/completions', options);
const data = await response.json();
const choices = data.choices;
const text = choices[0].text.trim();
addMessage(text, 'bot');
} catch (error) {
console.error(error);
}
#index.html
<textarea class="user-input" id="user-input"></textarea>
Use "gpt-3.5-turbo" model