-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathresponsengine.js
58 lines (56 loc) · 1.93 KB
/
responsengine.js
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
class ResponseEngine {
constructor(
appSettings,
functionList = [{start:"<|call|>",end:"<|/endCall|>",func: "call"} ],
remove= /<\|[^|]*\|>/g
)
{
this.appSettings = appSettings;
this.functionList= functionList;
this.remove = remove;
}
call(text){
console.log("Function called text: " + text);
}
callFunctions(text){
this.functionList.forEach( fun => {
this.functionCheckExecute( text, fun.start, fun.end, this[ fun.func ] )
});
}
functionCheckExecute(text, functionCall, terminator, callback){
if (text.includes(functionCall)) {
const splitText = text.split(functionCall)
if(splitText.length >=1){
if (splitText[0].includes(terminator)){
const outText = splitText[0].split(terminator);
callback(outText[0])
}
}
}
}
//Add your funtions as methods in this file.
removeChatML(text) {
return text.replace(this.remove, '');
}
recieveMessageFindTerminatorsAndTrim(text) {
let totals = []
this.callFunctions(text);
if (this.appSettings.removeFormatting) {
text = this.removeChatML(text);
}
// let low = 100000;
// let LowPosition = 0
// for (let index = 0; index < totals.length; index++) {
// const element = totals[index]> low;
// if (element < low) {
// low = element;
// LowPosition = index;
// }
// }
// let response = text.split(this.terminators[LowPosition])
// return response[0];
return text;
}
}
module.exports =ResponseEngine;
//todo: this will allow the bot to call a few funtions. I intend to change the message recieved sound so that the ai can emote at the user. Not execute code, but i'm considering some form of RAG