From a1ac915a14f0a22e8fe78a2ef5df98ea8faac4af Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Tue, 6 Dec 2022 22:15:58 -0600 Subject: [PATCH] docs: tweak commonjs example --- readme.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/readme.md b/readme.md index 2f9ebf3..ed4cd90 100644 --- a/readme.md +++ b/readme.md @@ -60,29 +60,26 @@ const api = new ChatGPTAPI({ }) ``` -Usage in CommonJS (Dynamic import): +
+Usage in CommonJS (Dynamic import) ```js async function example() { - // use ESM in CommonJS, dynamic import + // To use ESM in CommonJS, you can use a 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 + const api = new ChatGPTAPI({ + sessionToken: process.env.SESSION_TOKEN + }) 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 + const response = await api.sendMessage('Hello World!') console.log(response) } ``` +
+ A full [demo](./src/demo.ts) is included for testing purposes: ```bash