forked from transitive-bullshit/agentic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
57 lines (45 loc) · 1.29 KB
/
example.ts
File metadata and controls
57 lines (45 loc) · 1.29 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
import delay from 'delay'
import { oraPromise } from 'ora'
import { ChatGPTAPI } from './chatgpt-api'
/**
* Example CLI for testing functionality.
*/
async function main() {
const api = new ChatGPTAPI()
await api.init()
const isSignedIn = await api.getIsSignedIn()
if (!isSignedIn) {
// Wait until the user signs in via the chromium browser
await oraPromise(
new Promise<void>(async (resolve, reject) => {
do {
try {
await delay(1000)
const isSignedIn = await api.getIsSignedIn()
if (isSignedIn) {
return resolve()
}
} catch (err) {
return reject(err)
}
} while (true)
}),
'Please sign in to ChatGPT and dismiss the welcome modal'
)
}
const response = await api.sendMessage(
// 'Write a TypeScript function for conway sort.'
'Write a python version of bubble sort. Do not include example usage.'
)
// const prompts = await api.getPrompts()
// const messages = await api.getMessages()
// console.log('prompts', prompts)
// console.log('messages', messages)
// Wait forever; useful for debugging chromium sessions
// await new Promise(() => {})
await api.close()
return response
}
main().then((res) => {
console.log(res)
})