forked from transitive-bullshit/agentic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-on-progress.ts
45 lines (37 loc) · 902 Bytes
/
demo-on-progress.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import dotenv from 'dotenv-safe'
import { ChatGPTAPIBrowser } from '../src'
dotenv.config()
/**
* Demo CLI for testing the `onProgress` handler.
*
* ```
* npx tsx demos/demo-on-progress.ts
* ```
*/
async function main() {
const email = process.env.OPENAI_EMAIL
const password = process.env.OPENAI_PASSWORD
const api = new ChatGPTAPIBrowser({
email,
password,
debug: false,
minimize: true
})
await api.initSession()
const prompt =
'Write a python version of bubble sort. Do not include example usage.'
console.log(prompt)
const res = await api.sendMessage(prompt, {
onProgress: (partialResponse) => {
console.log('p')
console.log('progress', partialResponse?.response)
}
})
console.log(res.response)
// close the browser at the end
await api.closeSession()
}
main().catch((err) => {
console.error(err)
process.exit(1)
})