feat: add browser-based conversation demo

pull/146/head
Travis Fischer 2022-12-15 17:26:03 -06:00
rodzic 186864a99c
commit eaff91a6e6
3 zmienionych plików z 66 dodań i 3 usunięć

Wyświetl plik

@ -0,0 +1,58 @@
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: true })
await api.init()
const prompt = 'What is OpenAI?'
const response = await oraPromise(api.sendMessage(prompt), {
text: prompt
})
console.log(response)
const prompt2 = 'Did they made OpenGPT?'
console.log(
await oraPromise(api.sendMessage(prompt2), {
text: prompt2
})
)
const prompt3 = 'Who founded this institute?'
console.log(
await oraPromise(api.sendMessage(prompt3), {
text: prompt3
})
)
const prompt4 = 'Who is that?'
console.log(
await oraPromise(api.sendMessage(prompt4), {
text: prompt4
})
)
}
main().catch((err) => {
console.error(err)
process.exit(1)
})

Wyświetl plik

@ -17,8 +17,7 @@ async function main() {
const password = process.env.OPENAI_PASSWORD const password = process.env.OPENAI_PASSWORD
const api = new ChatGPTAPIBrowser({ email, password, debug: true }) const api = new ChatGPTAPIBrowser({ email, password, debug: true })
const res = await api.init() await api.init()
console.log('init result', res)
const prompt = const prompt =
'Write a python version of bubble sort. Do not include example usage.' 'Write a python version of bubble sort. Do not include example usage.'

Wyświetl plik

@ -201,6 +201,12 @@ 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
On December 11, 2022, OpenAI added some additional Cloudflare protections which make it more difficult to access the unofficial API. On December 11, 2022, OpenAI added some additional Cloudflare protections which make it more difficult to access the unofficial API.
@ -310,7 +316,7 @@ This package is ESM-only. It supports:
## Credits ## Credits
- Huge thanks to [@wong2](https://github.com/wong2), [@simon300000](https://github.com/simon300000), [@RomanHotsiy](https://github.com/RomanHotsiy), [@ElijahPepe](https://github.com/ElijahPepe), and all the other contributors 💪 - Huge thanks to [@waylaidwanderer](https://github.com/waylaidwanderer), [@wong2](https://github.com/wong2), [@simon300000](https://github.com/simon300000), [@RomanHotsiy](https://github.com/RomanHotsiy), [@ElijahPepe](https://github.com/ElijahPepe), and all the other contributors 💪
- The original browser version was inspired by this [Go module](https://github.com/danielgross/whatsapp-gpt) by [Daniel Gross](https://github.com/danielgross) - The original browser version was inspired by this [Go module](https://github.com/danielgross/whatsapp-gpt) by [Daniel Gross](https://github.com/danielgross)
- [OpenAI](https://openai.com) for creating [ChatGPT](https://openai.com/blog/chatgpt/) 🔥 - [OpenAI](https://openai.com) for creating [ChatGPT](https://openai.com/blog/chatgpt/) 🔥