Skip to content
Back

First time function user - works locally, can't get it working on cloud.

  • 0
  • React Native
  • Cloud
SorryLad2
24 Nov, 2024, 17:54

Hi guys, I am struggling to understand how to get my function to run as expected. I can get it to run locally, and can get it to build on appwrite cloud, but I think my file structure is wrong or I am missing some package manager step or dependencies or something... first time doing this so not really sure how local and cloud differs. Can anyone give advice on this? Thanks!

I had the function at least executing and logging last night, but now I am getting a weird curl error and have zero visibility into the function itself.

Internal curl error has occurred within the executor! Error Number: 52 Error Code: 500

TL;DR
Developers are having trouble getting a function working on cloud after running successfully locally. They suspect a file structure issue related to environment variables and package dependencies. The function utilizes the OpenAI API. They are encountering a curl error and lack visibility into the function itself. Solution: Check the file structure, ensure environment variables are correctly set up, and verify if all dependencies are properly installed. Additionally, investigate the specificities of running the function on a cloud platform.
SorryLad2
24 Nov, 2024, 17:55

For context I am doing something like this:

TypeScript
...build payload above

console.log("Constructed messages for OpenAI API:", JSON.stringify(messages, null, 2));

    // Initialize OpenAI client
    const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

    // Send request to OpenAI API
    console.log("Sending request to OpenAI API...");
    const response = await openai.chat.completions.create({
      model: "gpt-4o-mini",
      messages
    });

    // Return OpenAI API response
    const prompt = response.choices[0]?.message?.content || "No prompt generated";
    console.log("OpenAI API response:", prompt);
    return res.json({ prompt });

  } catch (err) {
    console.error("Error occurred during execution:", err.message);
    return res.json({ error: "Internal server error", details: err.message });
  }
SorryLad2
24 Nov, 2024, 17:58

File structure looks like this:

I have the OPENAI_API_KEY set as an env variable, and the only other command I am running is npm install openai what am I missing?!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more