forked from transitive-bullshit/agentic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo-conversations-browser.ts
67 lines (51 loc) · 1.55 KB
/
demo-conversations-browser.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import dotenv from 'dotenv-safe'
import ora, { oraPromise } from 'ora'
import { ChatGPTAPIBrowser } from '../src'
dotenv.config()
/**
* Demo CLI for testing conversation list support, and creation + deletion
*
* ```
* npx tsx demos/demo-conversations-browser.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 conversations = await oraPromise(api.getConversations(), {
text: 'Fetching active conversations'
})
console.log(conversations, `${conversations.total} active conversations`)
var success = await oraPromise(api.deleteAllConversations(), {
text: 'Deleting all conversations'
})
console.log('Could delete all conversations:', success)
let res = await oraPromise(api.sendMessage('how are you'), {
text: 'Creating example conversation'
})
console.log('ChatGPT response:', res.response, res.conversationId)
let title = await oraPromise(
api.generateConversationTitle(res.conversationId, res.messageId),
{
text: 'Generating conversation title'
}
)
console.log('ChatGPT generated title:', title)
var success = await oraPromise(api.deleteConversation(res.conversationId), {
text: 'Deleting the conversation'
})
console.log('Could delete the conversation:', success)
// close the browser at the end
await api.closeSession()
}
main().catch((err) => {
console.error(err)
process.exit(1)
})