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
|
|
|
|
2023-02-01 09:14:10 +00:00
|
|
|
import { ChatGPTAPI } 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
|
|
|
*
|
|
|
|
* ```
|
2022-12-15 07:25:38 +00:00
|
|
|
* npx tsx demos/demo.ts
|
2022-12-05 23:25:40 +00:00
|
|
|
* ```
|
2022-12-02 23:43:59 +00:00
|
|
|
*/
|
|
|
|
async function main() {
|
2023-03-02 02:49:20 +00:00
|
|
|
const api = new ChatGPTAPI({
|
|
|
|
apiKey: process.env.OPENAI_API_KEY,
|
|
|
|
debug: false
|
|
|
|
})
|
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
|
|
|
|
2022-12-17 04:48:42 +00:00
|
|
|
const res = await oraPromise(api.sendMessage(prompt), {
|
2022-12-05 07:09:24 +00:00
|
|
|
text: prompt
|
|
|
|
})
|
2023-03-02 02:49:20 +00:00
|
|
|
console.log(res.text)
|
2022-12-02 23:43:59 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 04:48:42 +00:00
|
|
|
main().catch((err) => {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|