【问题标题】:Dall-E API in Node.js always returns 400 Bad RequestNode.js 中的 Dall-E API 总是返回 400 Bad Request
【发布时间】:2023-01-12 00:06:15
【问题描述】:

我正在尝试在我的 Next.js 项目中实现 OpenAI 的 Dall-E API,但每次重新加载都会返回 400 Bad Request。

我完全按照文档中的步骤进行操作,但我仍然收到此错误。

const { Configuration, OpenAIApi } = require("openai");

async function predict() {
  const configuration = new Configuration({
    apiKey: process.env.OPEN_AI,
  });
  const openai = new OpenAIApi(configuration);

  const response = await openai.createImage(
    {
      prompt: "a white siamese cat",
    },
    {
      validateStatus: function (status: number) {
        return status < 500;
      },
    }
  );

  console.log(response);
}

这是回应

    status: 400,
    statusText: 'BAD REQUEST',
    headers: {
      date: 'Wed, 11 Jan 2023 10:42:12 GMT',
      'content-type': 'application/json',
      'content-length': '172',
      connection: 'keep-alive',
      'access-control-allow-origin': '*',
      'openai-version': '2020-10-01',
      'openai-organization': 'user-***************',
      'x-request-id': '6f3b88d1c538d56b102d76d2f1dc6aee',
      'openai-processing-ms': '55',
      'strict-transport-security': 'max-age=15724800; includeSubDomains'
    },

【问题讨论】:

    标签: node.js next.js openai


    【解决方案1】:

    试试这个,让我知道会发生什么:

    const { Configuration, OpenAIApi } = require("openai");
    
    async function predict() {
      const configuration = new Configuration({
        apiKey: process.env.OPEN_AI,
      });
      const openai = new OpenAIApi(configuration);
    
      const response = await openai.createImage({
        prompt: "a white siamese cat",
      });
    
      console.log(response);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-29
      • 2018-09-21
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多