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

编程入门 行业动态 更新时间:2024-10-04 19:28:39

TypeError: openai.<a href=https://www.elefans.com/category/jswz/34/1771328.html style=Auth 不是 Object.<anonymous>"/>

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

纱线开始

纱线运行 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 访问 有关此命令的文档。

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(`;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 openaiClientpletions.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

回答如下:

更多推荐

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

本文发布于:2024-05-30 22:33:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Auth   openai   TypeError   Object   gt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!