Skip to content

Commit

Permalink
Update how to use with commonJS
Browse files Browse the repository at this point in the history
Add another workaround for commonJS libraries
  • Loading branch information
T-Damer committed Mar 29, 2023
1 parent 4613b95 commit cf29a97
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,11 @@ Note that we automatically handle appending the previous messages to the prompt

```js
async function example() {
// To use ESM in CommonJS, you can use a dynamic import
// To use ESM in CommonJS, you can use a dynamic import like this:
const { ChatGPTAPI } = await import('chatgpt')
// You can also try dynamic importing like this:
// const importDynamic = new Function('modulePath', 'return import(modulePath)')
// const { ChatGPTAPI } = await importDynamic('chatgpt')

const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })

Expand Down

0 comments on commit cf29a97

Please sign in to comment.