Commit 025e7e3a authored by Travis Fischer's avatar Travis Fischer

docs: update demo to remove redundant browser conversation demo

parent 726550b5
import dotenv from 'dotenv-safe'
import { oraPromise } from 'ora'
import { ChatGPTAPIBrowser } from '../src'
dotenv.config()
/**
* Demo CLI for testing conversation support.
*
* ```
* npx tsx demos/demo-conversation-browser.ts
* ```
*/
async function main() {
const email = process.env.OPENAI_EMAIL
const password = process.env.OPENAI_PASSWORD
const api = new ChatGPTAPIBrowser({
email,
password,
debug: false,
minimize: true
})
await api.initSession()
const prompt = 'Write a poem about cats.'
let res = await oraPromise(api.sendMessage(prompt), {
text: prompt
})
console.log('\n' + res.response + '\n')
const prompt2 = 'Can you make it cuter and shorter?'
res = await oraPromise(
api.sendMessage(prompt2, {
conversationId: res.conversationId,
parentMessageId: res.messageId
}),
{
text: prompt2
}
)
console.log('\n' + res.response + '\n')
const prompt3 = 'Now write it in French.'
res = await oraPromise(
api.sendMessage(prompt3, {
conversationId: res.conversationId,
parentMessageId: res.messageId
}),
{
text: prompt3
}
)
console.log('\n' + res.response + '\n')
const prompt4 = 'What were we talking about again?'
res = await oraPromise(
api.sendMessage(prompt4, {
conversationId: res.conversationId,
parentMessageId: res.messageId
}),
{
text: prompt4
}
)
console.log('\n' + res.response + '\n')
// close the browser at the end
await api.closeSession()
}
main().catch((err) => {
console.error(err)
process.exit(1)
})
...@@ -71,6 +71,7 @@ async function main() { ...@@ -71,6 +71,7 @@ async function main() {
) )
console.log('\n' + res.response + '\n') console.log('\n' + res.response + '\n')
// close the browser at the end
await api.closeSession() await api.closeSession()
} }
......
...@@ -203,12 +203,6 @@ A [conversation demo](./demos/demo-conversation.ts) is also included: ...@@ -203,12 +203,6 @@ A [conversation demo](./demos/demo-conversation.ts) is also included:
npx tsx demos/demo-conversation.ts npx tsx demos/demo-conversation.ts
``` ```
A [browser-based conversation demo](./demos/demo-conversation-browser.ts) is also included:
```bash
npx tsx demos/demo-conversation-browser.ts
```
### Authentication ### Authentication
The authentication section relates to the REST-based version (using `getOpenAIAuth` + `ChatGPTAPI`). The browser-based solution, `ChatGPTAPIBrowser`, takes care of all the authentication for you. The authentication section relates to the REST-based version (using `getOpenAIAuth` + `ChatGPTAPI`). The browser-based solution, `ChatGPTAPIBrowser`, takes care of all the authentication for you.
......
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