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
import BaseDirective from "./BaseDirective"
import PandaSparkWebSocket from '../core/sockets/PandaSparkWebSocket'
class SparkDirective extends BaseDirective {
constructor(options) {
super(options)
this.pandaSparkWebSocket = new PandaSparkWebSocket({
config : this.params.sparkModelConfig
})
this.pandaSparkWebSocket.start()
}
match () {
const { text } = this;
return true
}
async excute({
sendMsg = function () {}
}) {
return new Promise(async (resolve, reject) => {
this.reject = reject
this.resolve = resolve
this.sendMsg = sendMsg
const data = await this.pandaSparkWebSocket.sendMessag({
content : this.text,
isLinkContext : false,
frame ({resultTextTemp, resultText}) {
sendMsg?.(resultTextTemp)
}
})
resolve(data.resultText)
})
}
closeResponse() {
if(this.pandaSparkWebSocket) {
this.pandaSparkWebSocket.stop()
}
this.sendMsg = null
this.reject("")
}
destroy(){
if(this.pandaSparkWebSocket) {
this.pandaSparkWebSocket.destroy()
this.pandaSparkWebSocket = null
}
}
}
export default SparkDirective