I’m trying to retrieve the updated response from an input sent to openai chat completion via firebase.
The data is successfully retrieved from firebase, then sent to openai api successfully, but there is no valid response.
Any help would be appreciated.
Code:
const completionResponse = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{"role": "system", "content": "You are a helpful editing assistant. Only return the summary without additional information or feedback."},
{"role": "user", "content": data.summary}
],
});
if (completionResponse.data && completionResponse.data.choices.length > 0) {
return { editedPitch: completionResponse.data.choices[0].message.content.trim() };
} else {
throw new functions.https.HttpsError('internal', 'OpenAI API response did not contain valid choices.');
}
} catch (error) {
console.error("Error with OpenAI API:", error.message, error.stack);
throw new functions.https.HttpsError('internal', 'Unable to process the pitch at this time.');
}