From cf29a97c0b1afe997564046e16b84d27dbc5b89d Mon Sep 17 00:00:00 2001 From: Daniil Pankov Date: Wed, 29 Mar 2023 20:42:49 +0300 Subject: [PATCH] Update how to use with commonJS Add another workaround for commonJS libraries --- readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6b9745b5..a2bb5296 100644 --- a/readme.md +++ b/readme.md @@ -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 })