The CORS error you get when calling your app's deployed version is most likely due to a web browser security feature that prevents cross-origin requests. This means that the browser will block any requests made from a different domain than the one serving the page.
To fix this, you can add CORS headers to your Cloud Functions HTTP response. You can do this by setting the appropriate headers in your function:
export const getSummary = functions.https.onCall(async (data, context) => {
// Set CORS headers
context.response.headers.set("Access-Control-Allow-Origin", "*");
context.response.headers.set("Access-Control-Allow-Methods", "GET, PUT, POST, OPTIONS");
context.response.headers.set("Access-Control-Allow-Headers", "Content-Type");
// Your existing code
const configuration = new Configuration({
apiKey: openAIKey.value(),
});
const openai = new OpenAIApi(configuration);
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{
role: "user",
content: data.prompt,
},
],
});
const [choice] = completion.data.choices;
return {
response: choice.message ?? "no response",
};
});
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/7a5d9703-3744-42ef-b60f-43f5905784cfn%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/db8a011f-c95f-494d-b141-2f88d08d9297n%40googlegroups.com.