Voilà, je fais fasse à un mur depuis tout à l"heure et je n'arrive même pas à comprendre le problème.
aiAnswer(topic, aiMode)
.then(function(text) {
console.log(text.choices[0].text);
textarea.value = text.choices[0].text;
})
function aiAnswer(text, aiMode) {
if (aiMode) {
const init = {
method : 'POST',
headers : {
'Authorization' : 'Bearer ' + apiKey,
'Content-Type' : 'application/json',
},
body : JSON.stringify({
model : 'text-ada-001',
prompt : text,
max_tokens : 100,
temperature : 0,
}),
};
return fetch('https://api.openai.com/v1/completions', init)
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err))
}
}
Suis-je à coté de la plaque vis à vis du synchronisme ? 