Closed minimum-devs closed 1 year ago
I'm using in my Discord bot, it works fine.
Try installing chatgpt@1.3.0, I think the ^ operator might allow higher versions aswell
use rollup. you could see my project (CJS format): https://github.com/oceanlvr/ChatGPTBot. 🌟 it if possibl :D
Maybe I should just cave and add CJS support to main
...
Would help me as well. I'm using nestjs and did not find a way to use the module except for the 1.3 version.
@DerKorb i think you're right! totally missed that 🤦
i will try that and update this issue if that was the problem.
I was able to import the esm module in my nestjs project using this guide: https://jaywolfe.dev/how-to-use-es-modules-with-older-node-js-projects-the-right-way/
Use ESM in CommonJS
async function example() {
// use ESM in CommonJS, dynamic import
const { ChatGPTAPI } = await import('chatgpt')
// sessionToken is required; see below for details
const api = new ChatGPTAPI({ sessionToken: process.env.SESSION_TOKEN })
// ensure the API is properly authenticated
await api.ensureAuth()
// send a message and wait for the response
const response = await api.sendMessage(
'Write a python version of bubble sort. Do not include example usage.'
)
// response is a markdown-formatted string
console.log(response)
}
Thanks for the example + PR @GoneTone 🙏
wondering if i'm doing something wrong but
with version 1.3.0 installed like this:
and trying to import it like this:
let { ChatGPTAPI } = require("chatgpt");
i'm still getting this error:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/task/node_modules/chatgpt/build/index.js require() of ES modules is not supported.
am i doing anything wrong?