0

exports.helloWorld = (req, res) => {
  const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
  model: "text-davinci-003",
 temperature: 0,
  max_tokens: 100,
  top_p: 1,
  frequency_penalty: 0,
  presence_penalty: 0,
  stop: ["\n"],
});


};

Deployment failure: Build failed: /workspace/index.js:10 const response = await openai.createCompletion({ ^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules at Object.compileFunction (node:vm:360:18) at wrapSafe (node:internal/modules/cjs/loader:1084:15) at checkSyntax (node:internal/main/check_syntax:66:3); Error ID: d984e68f

  • 2
    The error explains EXACTLY what's going on. You can only use `await` inside an `async` function or at the top level in an ESM module in a fairly new version of nodejs. Since this inside a function, that function must be declared `async` and thus will return a promise. – jfriend00 Dec 02 '22 at 07:00
  • What is your `helloWorld` function supposed to do? `response` is not used, so the function probably does nothing useful. – Sebastian Simon Dec 02 '22 at 07:01

0 Answers0