For a few days now I get a cors-error when executing my cloud function:
Access to fetch at 'https://us-central1-hauzr01.cloudfunctions.net/getObjectInfos2' from origin 'https://ff-debug-service-frontend-ygxkweukma-uc.a.run.app' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Also the deploy region doesn't seem to fit. I chose "europe-west3" but the cloud logs say it is deployed in "us-central1".
I tried copying the function, but it didn't change anything. If anybody is interested, it is a function to use the OpenAI-API:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const OpenAI = require('openai');
exports.getObjectInfos2 = functions.https.onCall(async (data, context) => {
const openai = new OpenAI({
apiKey: 'sk-...',
});
const strInput = data.strInput;
const strSystem = data.strSystemMsg;
try {
completion = await openai.chat.completions.create({
messages: [{
role: "system",
content: strSystem
},
{
role: "user",
content: strInput
}],
model: "gpt-4",
temperature: 1,
max_tokens: 2000,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
});
console.log(completion.choices.length);
console.log(completion.choices);
if (completion.choices.length>0) {
const generatedText = completion.choices[0].message.content.trim();
return generatedText;
}
} catch (error) {
console.error('OpenAI API request failed:', error);
}
});
I contacted FF-support today, let's see what they say.
Does anybody experience the same problem?