Commit 4693de97 authored by Travis Fischer's avatar Travis Fischer

docs: update readme for new release

parent 52ae3679
...@@ -11,8 +11,9 @@ ...@@ -11,8 +11,9 @@
- [Intro](#intro) - [Intro](#intro)
- [Install](#install) - [Install](#install)
- [Usage](#usage) - [Usage](#usage)
- [Docs](#docs) - [Docs](#docs)
- [How it works](#how-it-works) - [Demos](#demos)
- [Session Tokens](#session-tokens)
- [Compatibility](#compatibility) - [Compatibility](#compatibility)
- [Examples](#examples) - [Examples](#examples)
- [Credit](#credit) - [Credit](#credit)
...@@ -37,7 +38,9 @@ import { ChatGPTAPI } from 'chatgpt' ...@@ -37,7 +38,9 @@ import { ChatGPTAPI } from 'chatgpt'
async function example() { async function example() {
// sessionToken is required; see below for details // sessionToken is required; see below for details
const api = new ChatGPTAPI({ sessionToken: process.env.SESSION_TOKEN }) const api = new ChatGPTAPI({
sessionToken: process.env.SESSION_TOKEN
})
// ensure the API is properly authenticated // ensure the API is properly authenticated
await api.ensureAuth() await api.ensureAuth()
...@@ -52,7 +55,7 @@ async function example() { ...@@ -52,7 +55,7 @@ async function example() {
} }
``` ```
By default, the response will be formatted as markdown. If you want to work with plaintext only, you can use: The default ChatGPT responses are formatted as markdown. If you want to work with plaintext only, you can use:
```ts ```ts
const api = new ChatGPTAPI({ const api = new ChatGPTAPI({
...@@ -61,6 +64,25 @@ const api = new ChatGPTAPI({ ...@@ -61,6 +64,25 @@ const api = new ChatGPTAPI({
}) })
``` ```
If you want to automatically track the conversation, you can use `ChatGPTAPI.getConversation()`:
```ts
const api = new ChatGPTAPI({
sessionToken: process.env.SESSION_TOKEN
})
const conversation = api.getConversation()
// send a message and wait for the response
const response0 = await conversation.sendMessage('What is OpenAI?')
// send a follow-up prompt to the previous message and wait for the response
const response1 = await conversation.sendMessage('Can you expand on that?')
// send another follow-up to the same conversation
const response2 = await conversation.sendMessage('Oh cool; thank you')
```
<details> <details>
<summary>Usage in CommonJS (Dynamic import)</summary> <summary>Usage in CommonJS (Dynamic import)</summary>
...@@ -81,7 +103,13 @@ async function example() { ...@@ -81,7 +103,13 @@ async function example() {
</details> </details>
A full [demo](./src/demo.ts) is included for testing purposes: ### Docs
See the [auto-generated docs](./docs/classes/ChatGPTAPI.md) for more info on methods and parameters.
### Demos
A [basic demo](./src/demo.ts) is included for testing purposes:
```bash ```bash
# 1. clone repo # 1. clone repo
...@@ -91,11 +119,17 @@ A full [demo](./src/demo.ts) is included for testing purposes: ...@@ -91,11 +119,17 @@ A full [demo](./src/demo.ts) is included for testing purposes:
npx tsx src/demo.ts npx tsx src/demo.ts
``` ```
## Docs A [conversation demo](./src/demo-conversation.ts) is also included:
See the [auto-generated docs](./docs/classes/ChatGPTAPI.md) for more info on methods and parameters. ```bash
# 1. clone repo
# 2. install node deps
# 3. set `SESSION_TOKEN` in .env
# 4. run:
npx tsx src/demo-conversation.ts
```
## How it works ### Session Tokens
**This package requires a valid session token from ChatGPT to access it's unofficial REST API.** **This package requires a valid session token from ChatGPT to access it's unofficial REST API.**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment