kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
docs: tweak commonjs example
rodzic
2c07e53bbc
commit
a1ac915a14
21
readme.md
21
readme.md
|
@ -60,29 +60,26 @@ const api = new ChatGPTAPI({
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Usage in CommonJS (Dynamic import):
|
<details>
|
||||||
|
<summary>Usage in CommonJS (Dynamic import)</summary>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async function example() {
|
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')
|
const { ChatGPTAPI } = await import('chatgpt')
|
||||||
|
|
||||||
// sessionToken is required; see below for details
|
const api = new ChatGPTAPI({
|
||||||
const api = new ChatGPTAPI({ sessionToken: process.env.SESSION_TOKEN })
|
sessionToken: process.env.SESSION_TOKEN
|
||||||
|
})
|
||||||
// ensure the API is properly authenticated
|
|
||||||
await api.ensureAuth()
|
await api.ensureAuth()
|
||||||
|
|
||||||
// send a message and wait for the response
|
const response = await api.sendMessage('Hello World!')
|
||||||
const response = await api.sendMessage(
|
|
||||||
'Write a python version of bubble sort. Do not include example usage.'
|
|
||||||
)
|
|
||||||
|
|
||||||
// response is a markdown-formatted string
|
|
||||||
console.log(response)
|
console.log(response)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
A full [demo](./src/demo.ts) is included for testing purposes:
|
A full [demo](./src/demo.ts) is included for testing purposes:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
Ładowanie…
Reference in New Issue