@tiledesk/tiledesk-server 2.4.99 → 2.4.101
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +8 -0
- package/app.js +47 -9
- package/event/emailEvent.js +13 -0
- package/event/integrationEvent.js +13 -0
- package/models/integrations.js +23 -0
- package/models/kb_setting.js +34 -3
- package/package.json +2 -2
- package/pubmodules/cache/mongoose-cachegoose-fn.js +12 -0
- package/pubmodules/emailNotification/requestNotification.js +1 -0
- package/routes/auth.js +14 -5
- package/routes/email.js +4 -2
- package/routes/faq.js +1 -0
- package/routes/integration.js +199 -0
- package/routes/kb.js +353 -0
- package/routes/kbsettings.js +6 -4
- package/routes/openai.js +53 -15
- package/routes/project.js +3 -4
- package/routes/quotes.js +52 -0
- package/routes/request.js +515 -499
- package/routes/users.js +5 -1
- package/services/QuoteManager.js +317 -0
- package/services/cacheEnabler.js +5 -0
- package/services/emailService.js +610 -586
- package/services/messageService.js +283 -202
- package/services/openaiService.js +198 -92
- package/services/requestService.js +1764 -1421
- package/services/trainingService.js +6 -2
- package/test/kbRoute.js +134 -0
- package/test/kbsettingsRoute.js +14 -12
- package/test/messageService.js +154 -92
- package/test/mock/MockTdCache.js +46 -0
- package/test/mock/emailMock.js +9 -0
- package/test/mock/messageMock.js +46 -0
- package/test/mock/projectMock.js +171 -0
- package/test/mock/requestMock.js +127 -0
- package/test/quoteManager.js +282 -0
- package/test/requestRoute.js +1 -1
- package/test/requestService.js +1196 -1079
- package/utils/TdCache.js +253 -0
@@ -1,103 +1,209 @@
|
|
1
1
|
var winston = require('../config/winston');
|
2
2
|
const axios = require("axios").default;
|
3
|
-
var configGlobal = require('../config/global');
|
4
3
|
require('dotenv').config();
|
5
4
|
|
6
5
|
let openai_endpoint = process.env.OPENAI_ENDPOINT;
|
7
6
|
let kb_endpoint = process.env.KB_ENDPOINT;
|
7
|
+
let kb_endpoint_dev = process.env.KB_ENDPOINT_DEV;
|
8
8
|
|
9
9
|
class OpenaiService {
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
}
|
10
|
+
|
11
|
+
// OPEN AI
|
12
|
+
completions(data, gptkey) {
|
13
|
+
|
14
|
+
winston.debug("[OPENAI SERVICE] openai endpoint: ", openai_endpoint);
|
15
|
+
|
16
|
+
return new Promise((resolve, reject) => {
|
17
|
+
|
18
|
+
axios({
|
19
|
+
url: openai_endpoint + "/chat/completions",
|
20
|
+
headers: {
|
21
|
+
'Content-Type': 'application/json',
|
22
|
+
'Authorization': "Bearer " + gptkey
|
23
|
+
},
|
24
|
+
data: data,
|
25
|
+
method: 'POST'
|
26
|
+
}).then((resbody) => {
|
27
|
+
resolve(resbody);
|
28
|
+
}).catch((err) => {
|
29
|
+
reject(err);
|
30
|
+
})
|
31
|
+
|
32
|
+
})
|
33
|
+
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
// PUGLIA AI
|
38
|
+
checkStatus(data) {
|
39
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
|
40
|
+
|
41
|
+
return new Promise((resolve, reject) => {
|
42
|
+
|
43
|
+
axios({
|
44
|
+
url: kb_endpoint + "/scrape/status",
|
45
|
+
headers: {
|
46
|
+
'Content-Type': 'application/json'
|
47
|
+
},
|
48
|
+
data: data,
|
49
|
+
method: 'POST'
|
50
|
+
}).then((resbody) => {
|
51
|
+
resolve(resbody);
|
52
|
+
}).catch((err) => {
|
53
|
+
console.log("checkStatus err: ", err)
|
54
|
+
reject(err);
|
55
|
+
})
|
56
|
+
|
57
|
+
})
|
58
|
+
}
|
59
|
+
|
60
|
+
startScrape(data) {
|
61
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
|
62
|
+
|
63
|
+
return new Promise((resolve, reject) => {
|
64
|
+
|
65
|
+
axios({
|
66
|
+
url: kb_endpoint + "/scrape",
|
67
|
+
headers: {
|
68
|
+
'Content-Type': 'application/json'
|
69
|
+
},
|
70
|
+
data: data,
|
71
|
+
method: 'POST'
|
72
|
+
}).then((resbody) => {
|
73
|
+
resolve(resbody);
|
74
|
+
}).catch((err) => {
|
75
|
+
reject(err);
|
76
|
+
})
|
77
|
+
|
78
|
+
})
|
79
|
+
}
|
80
|
+
|
81
|
+
ask(data) {
|
82
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
|
83
|
+
|
84
|
+
return new Promise((resolve, reject) => {
|
85
|
+
|
86
|
+
axios({
|
87
|
+
url: kb_endpoint + "/qa",
|
88
|
+
headers: {
|
89
|
+
'Content-Type': 'application/json'
|
90
|
+
},
|
91
|
+
data: data,
|
92
|
+
method: 'POST'
|
93
|
+
}).then((resbody) => {
|
94
|
+
resolve(resbody);
|
95
|
+
}).catch((err) => {
|
96
|
+
console.log("err: ", err);
|
97
|
+
reject(err);
|
98
|
+
})
|
99
|
+
|
100
|
+
})
|
101
|
+
}
|
102
|
+
|
103
|
+
// PUGLIA AI V2
|
104
|
+
singleScrape(data) {
|
105
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
|
106
|
+
|
107
|
+
return new Promise((resolve, reject) => {
|
108
|
+
|
109
|
+
axios({
|
110
|
+
url: kb_endpoint_dev + "/scrape/single",
|
111
|
+
headers: {
|
112
|
+
'Content-Type': 'application/json'
|
113
|
+
},
|
114
|
+
data: data,
|
115
|
+
method: 'POST'
|
116
|
+
}).then((resbody) => {
|
117
|
+
resolve(resbody);
|
118
|
+
}).catch((err) => {
|
119
|
+
reject(err);
|
120
|
+
})
|
121
|
+
|
122
|
+
})
|
123
|
+
}
|
124
|
+
|
125
|
+
scrapeStatus(data) {
|
126
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
|
127
|
+
|
128
|
+
return new Promise((resolve, reject) => {
|
129
|
+
|
130
|
+
axios({
|
131
|
+
url: kb_endpoint_dev + "/scrape/status",
|
132
|
+
headers: {
|
133
|
+
'Content-Type': 'application/json'
|
134
|
+
},
|
135
|
+
data: data,
|
136
|
+
method: 'POST'
|
137
|
+
}).then((resbody) => {
|
138
|
+
resolve(resbody);
|
139
|
+
}).catch((err) => {
|
140
|
+
reject(err);
|
141
|
+
})
|
142
|
+
})
|
143
|
+
}
|
144
|
+
|
145
|
+
askNamespace(data) {
|
146
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
|
147
|
+
|
148
|
+
return new Promise((resolve, reject) => {
|
149
|
+
|
150
|
+
axios({
|
151
|
+
url: kb_endpoint_dev + "/qa",
|
152
|
+
headers: {
|
153
|
+
'Content-Type': 'application/json'
|
154
|
+
},
|
155
|
+
data: data,
|
156
|
+
method: 'POST'
|
157
|
+
}).then((resbody) => {
|
158
|
+
resolve(resbody);
|
159
|
+
}).catch((err) => {
|
160
|
+
reject(err);
|
161
|
+
})
|
162
|
+
|
163
|
+
})
|
164
|
+
}
|
165
|
+
|
166
|
+
deleteIndex(data) {
|
167
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
|
168
|
+
|
169
|
+
return new Promise((resolve, reject) => {
|
170
|
+
|
171
|
+
axios({
|
172
|
+
url: kb_endpoint_dev + "/delete/id",
|
173
|
+
headers: {
|
174
|
+
'Content-Type': 'application/json'
|
175
|
+
},
|
176
|
+
data: data,
|
177
|
+
method: 'POST'
|
178
|
+
}).then((resbody) => {
|
179
|
+
resolve(resbody);
|
180
|
+
}).catch((err) => {
|
181
|
+
reject(err);
|
182
|
+
})
|
183
|
+
})
|
184
|
+
}
|
185
|
+
|
186
|
+
deleteNamespace(data) {
|
187
|
+
winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint_dev);
|
188
|
+
|
189
|
+
return new Promise((resolve, reject) => {
|
190
|
+
|
191
|
+
axios({
|
192
|
+
url: kb_endpoint_dev + "/delete/namespace",
|
193
|
+
headers: {
|
194
|
+
'Content-Type': 'application/json'
|
195
|
+
},
|
196
|
+
data: data,
|
197
|
+
method: 'POST'
|
198
|
+
}).then((resbody) => {
|
199
|
+
resolve(resbody);
|
200
|
+
}).catch((err) => {
|
201
|
+
reject(err);
|
202
|
+
})
|
203
|
+
})
|
204
|
+
}
|
205
|
+
|
206
|
+
|
101
207
|
}
|
102
208
|
|
103
209
|
var openaiService = new OpenaiService();
|