diff --git a/demos/demo-conversation-browser.ts b/demos/demo-conversation-browser.ts new file mode 100644 index 0000000..e1f600e --- /dev/null +++ b/demos/demo-conversation-browser.ts @@ -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) +}) diff --git a/demos/demo.ts b/demos/demo.ts index caaf1a5..7fe359d 100644 --- a/demos/demo.ts +++ b/demos/demo.ts @@ -17,8 +17,7 @@ async function main() { const password = process.env.OPENAI_PASSWORD const api = new ChatGPTAPIBrowser({ email, password, debug: true }) - const res = await api.init() - console.log('init result', res) + await api.init() const prompt = 'Write a python version of bubble sort. Do not include example usage.' diff --git a/readme.md b/readme.md index bacf642..aeedaf6 100644 --- a/readme.md +++ b/readme.md @@ -201,6 +201,12 @@ A [conversation demo](./demos/demo-conversation.ts) is also included: 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 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 -- 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) - [OpenAI](https://openai.com) for creating [ChatGPT](https://openai.com/blog/chatgpt/) 🔥