forked from transitive-bullshit/agentic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo-conversation.ts
57 lines (43 loc) · 1.03 KB
/
demo-conversation.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
import dotenv from 'dotenv-safe'
import { oraPromise } from 'ora'
import { ChatGPTAPI } from '.'
dotenv.config()
/**
* Demo CLI for testing conversation support.
*
* ```
* npx tsx src/demo-conversation.ts
* ```
*/
async function main() {
const api = new ChatGPTAPI({ sessionToken: process.env.SESSION_TOKEN })
await api.ensureAuth()
const conversation = api.getConversation()
const prompt = 'What is OpenAI?'
const response = await oraPromise(conversation.sendMessage(prompt), {
text: prompt
})
console.log(response)
const prompt2 = 'Did they made OpenGPT?'
console.log(
await oraPromise(conversation.sendMessage(prompt2), {
text: prompt2
})
)
const prompt3 = 'Who founded this institute?'
console.log(
await oraPromise(conversation.sendMessage(prompt3), {
text: prompt3
})
)
const prompt4 = 'Who is that?'
console.log(
await oraPromise(conversation.sendMessage(prompt4), {
text: prompt4
})
)
}
main().catch((err) => {
console.error(err)
process.exit(1)
})