2022-12-05 05:13:36 +00:00
|
|
|
import dotenv from 'dotenv-safe'
|
2022-12-05 07:09:24 +00:00
|
|
|
import { oraPromise } from 'ora'
|
2022-12-02 23:43:59 +00:00
|
|
|
|
2022-12-12 17:23:03 +00:00
|
|
|
import { ChatGPTAPI, getOpenAIAuth } from '../src'
|
2022-12-02 23:43:59 +00:00
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
dotenv.config()
|
|
|
|
|
2022-12-02 23:43:59 +00:00
|
|
|
/**
|
2022-12-06 22:13:11 +00:00
|
|
|
* Demo CLI for testing basic functionality.
|
2022-12-05 23:25:40 +00:00
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* npx tsx src/demo.ts
|
|
|
|
* ```
|
2022-12-02 23:43:59 +00:00
|
|
|
*/
|
|
|
|
async function main() {
|
2022-12-12 23:23:36 +00:00
|
|
|
const email = process.env.OPENAI_EMAIL
|
|
|
|
const password = process.env.OPENAI_PASSWORD
|
2022-12-12 11:28:53 +00:00
|
|
|
|
2022-12-12 17:23:03 +00:00
|
|
|
const authInfo = await getOpenAIAuth({
|
2022-12-12 11:28:53 +00:00
|
|
|
email,
|
|
|
|
password
|
|
|
|
})
|
|
|
|
|
|
|
|
const api = new ChatGPTAPI({ ...authInfo })
|
2022-12-05 05:13:36 +00:00
|
|
|
await api.ensureAuth()
|
2022-12-02 23:43:59 +00:00
|
|
|
|
2022-12-05 07:09:24 +00:00
|
|
|
const prompt =
|
2022-12-02 23:43:59 +00:00
|
|
|
'Write a python version of bubble sort. Do not include example usage.'
|
2022-12-05 07:09:24 +00:00
|
|
|
|
|
|
|
const response = await oraPromise(api.sendMessage(prompt), {
|
|
|
|
text: prompt
|
|
|
|
})
|
2022-12-03 00:09:45 +00:00
|
|
|
|
2022-12-05 07:31:27 +00:00
|
|
|
return response
|
2022-12-02 23:43:59 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 05:13:36 +00:00
|
|
|
main()
|
|
|
|
.then((res) => {
|
|
|
|
console.log(res)
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|