TypeError: openai.Auth 不是 Object.<anonymous>

问题描述 投票:0回答:0

纱线开始

纱线运行 v1.22.19

$ 节点 App.js

/data/data/com.termux/files/home/fluantiXbot/App.js:13

const openaiClient = new openai.Auth({ api_key: openaiApiKey });

                 ^

TypeError: openai.Auth 不是构造函数

at Object.<anonymous> (/data/data/com.termux/files/home/fluantiXbot/App.js:13:22)

at Module._compile (node:internal/modules/cjs/loader:1254:14)

at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)

at Module.load (node:internal/modules/cjs/loader:1117:32)

at Module._load (node:internal/modules/cjs/loader:958:12)

at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

at node:internal/main/run_main_module:23:47

Node.js v18.14.1

error 命令失败,退出代码为 1.

info 访问 https://yarnpkg.com/en/docs/cli/run 有关此命令的文档。

require('dotenv').config();

const openai = require("openai");

const Facebook = require('facebook-node-sdk');

const cron = require('node-cron');

const axios = require('axios');

// 从 .env 文件加载凭证

const openaiApiKey = process.env.OPENAI_API_KEY;

const facebookAccessToken = process.env.FACEBOOK_ACCESS_TOKEN;

const unsplashAccessKey = process.env.UNSPLASH_ACCESS_KEY;

// 配置 OpenAI API 客户端

const openaiClient = new openai.Auth({ api_key: openaiApiKey });

// 配置 Facebook Graph API 客户端

const facebookClient = new Facebook({ access_token: facebookAccessToken });

// 定义每天上午 9:00 运行的预定作业

cron.schedule('0 9 * * *', async () => {

尝试{

// Retrieve a random image from Unsplash

const { data: { urls: { regular: imageUrl } } } = await axios.get(`https://api.unsplash.com/photos/random?query=technology&client_id=${unsplashAccessKey}`);

// Generate a prompt for the OpenAI GPT-3 API

const prompt = 'Generate a paragraph about a recent technology topic using GPT-3.';

// Generate text using the OpenAI GPT-3 API

const { data: { choices: [{ text }] } } = await openaiClient.completions.create({

  engine: 'text-davinci-002',

  prompt,

  max_tokens: 256,

  n: 1,

  stop: '\n',

});

// Generate the Facebook post message

const message = `Check out this cool technology news: \n\n${text}\n\n #fluantiX`;

// Create the Facebook post

facebookClient.api('/me/feed', 'post', { message, link: imageUrl }, (response) => {

  if (response && response.error) {

    console.error(response.error);

  }

});

} 赶上(错误){

console.error(error);

}

});

your text

node.js facebook axios bots openai-api
© www.soinside.com 2019 - 2024. All rights reserved.