From a70d6f54524c25174c607fa391d356d955e3db21 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Wed, 11 Jan 2023 03:41:50 -0600 Subject: [PATCH] feat: add google auth demo --- demos/demo-google-auth.ts | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 demos/demo-google-auth.ts diff --git a/demos/demo-google-auth.ts b/demos/demo-google-auth.ts new file mode 100644 index 0000000..d20420b --- /dev/null +++ b/demos/demo-google-auth.ts @@ -0,0 +1,43 @@ +import dotenv from 'dotenv-safe' +import { oraPromise } from 'ora' + +import { ChatGPTAPIBrowser } from '../src' + +dotenv.config() + +/** + * Demo CLI for testing basic functionality using Google auth. + * + * ``` + * npx tsx demos/demo.ts + * ``` + */ +async function main() { + const email = process.env.OPENAI_EMAIL + const password = process.env.OPENAI_PASSWORD + + const api = new ChatGPTAPIBrowser({ + email, + password, + isGoogleLogin: true, + debug: false, + minimize: true + }) + await api.initSession() + + const prompt = + 'Write a python version of bubble sort. Do not include example usage.' + + const res = await oraPromise(api.sendMessage(prompt), { + text: prompt + }) + console.log(res.response) + + // close the browser at the end + await api.closeSession() +} + +main().catch((err) => { + console.error(err) + process.exit(1) +})