@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.
@@ -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
- // 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
- reject(err);
54
- })
55
-
56
- })
57
- }
58
-
59
- startScrape(data) {
60
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
61
-
62
- return new Promise((resolve, reject) => {
63
-
64
- axios({
65
- url: kb_endpoint + "/scrape",
66
- headers: {
67
- 'Content-Type': 'application/json'
68
- },
69
- data: data,
70
- method: 'POST'
71
- }).then((resbody) => {
72
- resolve(resbody);
73
- }).catch((err) => {
74
- reject(err);
75
- })
76
-
77
- })
78
- }
79
-
80
- ask(data) {
81
- winston.debug("[OPENAI SERVICE] kb endpoint: ", kb_endpoint);
82
-
83
- return new Promise((resolve, reject) => {
84
-
85
- axios({
86
- url: kb_endpoint + "/qa",
87
- headers: {
88
- 'Content-Type': 'application/json'
89
- },
90
- data: data,
91
- method: 'POST'
92
- }).then((resbody) => {
93
- resolve(resbody);
94
- }).catch((err) => {
95
- console.log("err: ", err);
96
- reject(err);
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();