kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
Update how to use with commonJS
Add another workaround for commonJS librariespull/506/head
rodzic
4613b95cc3
commit
cf29a97c0b
|
@ -280,8 +280,11 @@ Note that we automatically handle appending the previous messages to the prompt
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async function example() {
|
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')
|
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 })
|
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue