Update how to use with commonJS

Add another workaround for commonJS libraries
pull/506/head
Daniil Pankov 2023-03-29 20:42:49 +03:00 zatwierdzone przez GitHub
rodzic 4613b95cc3
commit cf29a97c0b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 4 dodań i 1 usunięć

Wyświetl plik

@ -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 })