I am building a chatbot that responds based on an initial context, but every prompt is answered by the API [object Promise]. How do I get the function to actually extract the text content from the chat completion.
```
async function getCompletionFromMessages( messages, model = 'gpt-3.5-turbo', temperature = 0 ) {
console.log('clicked');
const options = {
method: 'POST',
headers: {
'Authorization': Bearer ${api_key},
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: model,
messages: messages,
maxTokens: 200,
temperature: temperature
})
}
try {
const completion = await fetch("https://api.openai.com/v1/chat/completions", options)
const data = await response.json();
console.log(data);
return data.choices[0].message.content;
} catch {
console.error(error);
}
};
```
This is the chat completion method I am using to return the bot response, but as I said, it returns [object Promise] for every output. Help needed!