-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
53 lines (42 loc) · 1.21 KB
/
index.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
import memoriApiClient from '@memori.ai/memori-api-client'
import fetch from 'cross-fetch'
import * as readline from 'readline'
const client = memoriApiClient()
let sessionId: string
const handleConversation = () => {
const commandLineIO = readline.createInterface({
input: process.stdin,
output: process.stdout
})
commandLineIO.question('You: ', async (question) => {
if (!sessionId) {
console.log('No session ID')
return
}
const { currentState, ...resp } = await client.postTextEnteredEvent({
sessionId,
text: question
})
if (currentState && resp.resultCode === 0) {
let emission = currentState.emission
if (emission) console.log(`Nunzio: ${emission}`)
} else {
console.error(resp)
}
commandLineIO.close()
handleConversation()
})
}
;(async () => {
const { sessionID, currentState, ...resp } = await client.initSession({
memoriID: '1afe57c6-1b69-4a61-96ea-52bf7b8d158e'
})
if (sessionID && currentState && resp.resultCode === 0) {
sessionId = sessionID
let emission = currentState.emission
if (emission) console.log(`Nunzio: ${emission}`)
handleConversation()
} else {
console.error(resp)
}
})()