Da Vinci 003 upgrade not working

my code is pretty simple - its for a little generator as part of showing my team how to work with gpt - but i did it ages ago and now its deprecated

so i tried to update it to be

model: "gpt-3.5-turbo-instruct"

instead of

model: "davinci-003"

but it just stopped working - is there something im missing in how to reformat this?

the console error im getting is

Failed to load resource: the server responded with a status of 502 () /.netlify/functions/open:1

which seems to imply its line one of the Open.js file

but when i check the API tracking its being called whenever i load the site - so it must be making it past the first line?

Open.js :point_down:

import axios from "axios";

[API KEY LOGIC]

exports.handler = async function (event, context) {
  const { word } = JSON.parse(event.body);

  const prompt = word?.length
    ? `Generate a.... [long prompt here cut out for brevity]`
    : `Generate a...[long prompt here].`;

  const response = await axios.post(    "https://api.openai.com/v1/completions",
    {
      temperature: 0.4,
      prompt,
      max_tokens: 400,
      n: 1,
      model: "text-davinci-003",
    },
    {
      [API KEY LOGIC]
    }
  );

  // const haikuText = response.data.choices[0].text.trim();

  let haikuText = response.data.choices[0].text.trim();

  // Clean up the haiku text
  haikuText = haikuText.replace(/[^a-zA-Z,.'\s-ñ˜]+/g, '');


  return {
    statusCode: 200,
    body: JSON.stringify({ haikuText }),
  };
};

502 is typically a Cloudflare issue in accessing the resource behind OpenAI. May be a temporary problem, but the full message from https should be obtained for further diagnosis. Or OpenAI sees the user-agent could be a big problem.

BTW: Don’t demonstrate how to put API keys into client execution space.

The error isn’t being thrown from your code but rather from netlify code. That’s why the error message is unhelpful.

Are you able to trace the stack to see where the error originated from?

Regardless, the 502 error is a Bad Gateway error. See:

There isn’t anything you can do to fix this as the error isn’t on your end.

oh oops. does that give people access to my key etc? :flushed:

so changing it to this - should work - as long as i figure out the 502 issue?

yeah this is the error it gives me - i thought it was because it needed to update the node.js build version - but it actually seems like its an Axios thing.

odd.