@tiledesk/tiledesk-tybot-connector 2.0.29-rc5 → 2.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -32
- package/ExtApi.js +3 -0
- package/TdCache copy.js +242 -0
- package/engine/TiledeskChatbotConst.js +1 -8
- package/engine/mock/MockBotsDataSource.js +2 -1
- package/index.js +9 -7
- package/package.json +2 -2
- package/services/{LLMService.js → KbService.js} +3 -3
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +14 -43
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +1 -44
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +3 -5
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -1
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +418 -0
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -2
- package/utils/TiledeskChatbotUtil.js +0 -35
- package/tiledeskChatbotPlugs/directives/DirAiCondition.js +0 -483
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
const axios = require("axios").default;
|
|
2
|
-
const { TiledeskChatbot } = require("../../engine/TiledeskChatbot");
|
|
3
|
-
const { Filler } = require("../Filler");
|
|
4
|
-
let https = require("https");
|
|
5
|
-
const { DirIntent } = require("./DirIntent");
|
|
6
|
-
const { TiledeskChatbotConst } = require("../../engine/TiledeskChatbotConst");
|
|
7
|
-
const { TiledeskChatbotUtil } = require("../../utils/TiledeskChatbotUtil");
|
|
8
|
-
require('dotenv').config();
|
|
9
|
-
const winston = require('../../utils/winston');
|
|
10
|
-
const Utils = require("../../utils/HttpUtils");
|
|
11
|
-
const utils = require("../../utils/HttpUtils");
|
|
12
|
-
const httpUtils = require("../../utils/HttpUtils");
|
|
13
|
-
const integrationService = require("../../services/IntegrationService");
|
|
14
|
-
const { Logger } = require("../../Logger");
|
|
15
|
-
const { randomUUID } = require("crypto");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class DirAiCondition {
|
|
19
|
-
|
|
20
|
-
constructor(context) {
|
|
21
|
-
if (!context) {
|
|
22
|
-
throw new Error('context object is mandatory');
|
|
23
|
-
}
|
|
24
|
-
this.context = context;
|
|
25
|
-
this.chatbot = this.context.chatbot;
|
|
26
|
-
this.tdcache = this.context.tdcache;
|
|
27
|
-
this.requestId = this.context.requestId;
|
|
28
|
-
this.projectId = this.context.projectId;
|
|
29
|
-
this.token = this.context.token;
|
|
30
|
-
this.API_ENDPOINT = this.context.API_ENDPOINT;
|
|
31
|
-
|
|
32
|
-
this.intentDir = new DirIntent(context);
|
|
33
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.attributes?.intent_info?.intent_id });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
execute(directive, callback) {
|
|
37
|
-
winston.verbose("Execute AiAiCondition directive");
|
|
38
|
-
let action;
|
|
39
|
-
if (directive.action) {
|
|
40
|
-
action = directive.action;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.logger.error("Incorrect action for ", directive.name, directive)
|
|
44
|
-
winston.debug("DirAiAiCondition Incorrect directive: ", directive);
|
|
45
|
-
callback();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
this.go(action, (stop) => {
|
|
49
|
-
this.logger.native("[Ai Condition] Executed");
|
|
50
|
-
callback(stop);
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async go(action, callback) {
|
|
55
|
-
winston.debug("DirAiCondition action:", action);
|
|
56
|
-
if (!this.tdcache) {
|
|
57
|
-
winston.error("Error: DirAiCondition tdcache is mandatory");
|
|
58
|
-
callback();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let intents = action.intents;
|
|
63
|
-
// intents = [
|
|
64
|
-
// {
|
|
65
|
-
// "label": "26efa629-686e-4a23-a2f8-38c8f5beb408",
|
|
66
|
-
// "prompt": "user asking for medical information",
|
|
67
|
-
// "conditionIntentId": "#9b1c29c1671847dba6db561f771a142e"
|
|
68
|
-
// }
|
|
69
|
-
// ]
|
|
70
|
-
let falllbackIntent = action.falllbackIntent; // non condition met block
|
|
71
|
-
let falseIntent = action.falllbackIntent; // On error block
|
|
72
|
-
await this.checkMandatoryParameters(action).catch( async (missing_param) => {
|
|
73
|
-
const error = "AiPrompt Error: '" + missing_param + "' attribute is undefined"
|
|
74
|
-
this.logger.error(error);
|
|
75
|
-
await this.chatbot.addParameter("flowError", error);
|
|
76
|
-
if (falseIntent) {
|
|
77
|
-
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
78
|
-
callback(true);
|
|
79
|
-
return Promise.reject();
|
|
80
|
-
}
|
|
81
|
-
callback();
|
|
82
|
-
return Promise.reject();
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
// fill attributes
|
|
86
|
-
let requestVariables = null;
|
|
87
|
-
requestVariables =
|
|
88
|
-
await TiledeskChatbot.allParametersStatic(
|
|
89
|
-
this.tdcache, this.requestId
|
|
90
|
-
)
|
|
91
|
-
const filler = new Filler();
|
|
92
|
-
|
|
93
|
-
let conditions = "";
|
|
94
|
-
intents.forEach( function(intent) {
|
|
95
|
-
let filled_prompt = filler.fill(intent.prompt, requestVariables);
|
|
96
|
-
conditions += `- label: ${intent.label} when: ${filled_prompt}\n`
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
let instructions = filler.fill(action.instructions, requestVariables);
|
|
100
|
-
let condition_prompt = TiledeskChatbotUtil.AiConditionPromptBuilder(prompt_header, intents, instructions)
|
|
101
|
-
|
|
102
|
-
// let raw_condition_prompt = `Reply with the label satisfying the corresponding condition or with “fallback” if all conditions are false.
|
|
103
|
-
// If more than one condition is true, answer with the first label corresponding to the true condition, following the order from top to bottom.
|
|
104
|
-
// ${conditions}
|
|
105
|
-
// ${instructions}`
|
|
106
|
-
|
|
107
|
-
// const filled_question = condition_prompt; //filler.fill(action.question, requestVariables);
|
|
108
|
-
const filled_context = filler.fill(action.context, requestVariables);
|
|
109
|
-
|
|
110
|
-
// evaluate
|
|
111
|
-
|
|
112
|
-
let AI_endpoint = process.env.AI_ENDPOINT;
|
|
113
|
-
winston.verbose("DirAiPrompt AI_endpoint " + AI_endpoint);
|
|
114
|
-
|
|
115
|
-
let headers = {
|
|
116
|
-
'Content-Type': 'application/json'
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
let key;
|
|
120
|
-
let ollama_integration;
|
|
121
|
-
|
|
122
|
-
if (action.llm === 'ollama') {
|
|
123
|
-
ollama_integration = await integrationService.getIntegration(this.projectId, action.llm, this.token).catch( async (err) => {
|
|
124
|
-
this.logger.error("[AI Condition] Error getting ollama integration.")
|
|
125
|
-
winston.error("DirAiPrompt Error getting ollama integration: ", err);
|
|
126
|
-
await this.chatbot.addParameter("flowError", "Ollama integration not found");
|
|
127
|
-
if (falseIntent) {
|
|
128
|
-
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
129
|
-
callback(true);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
callback();
|
|
133
|
-
return;
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
} else {
|
|
137
|
-
key = await integrationService.getKeyFromIntegrations(this.projectId, action.llm, this.token);
|
|
138
|
-
|
|
139
|
-
if (!key) {
|
|
140
|
-
this.logger.error("[AI Condition] llm key not found in integrations");
|
|
141
|
-
winston.error("Error: DirAiPrompt llm key not found in integrations");
|
|
142
|
-
await this.chatbot.addParameter("flowError", "AiPrompt Error: missing key for llm " + action.llm);
|
|
143
|
-
if (falseIntent) {
|
|
144
|
-
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
145
|
-
callback(true);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
callback();
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
let json = {
|
|
154
|
-
question: condition_prompt,
|
|
155
|
-
llm: action.llm,
|
|
156
|
-
model: action.model,
|
|
157
|
-
llm_key: key,
|
|
158
|
-
temperature: action.temperature,
|
|
159
|
-
max_tokens: action.max_tokens
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (action.context) {
|
|
163
|
-
json.system_context = filled_context;
|
|
164
|
-
}
|
|
165
|
-
// if (transcript) {
|
|
166
|
-
// json.chat_history_dict = await this.transcriptToLLM(transcript);
|
|
167
|
-
// }
|
|
168
|
-
|
|
169
|
-
if (action.llm === 'ollama') {
|
|
170
|
-
json.llm_key = "";
|
|
171
|
-
json.model = {
|
|
172
|
-
name: action.model,
|
|
173
|
-
url: ollama_integration.value.url,
|
|
174
|
-
token: ollama_integration.value.token
|
|
175
|
-
}
|
|
176
|
-
json.stream = false
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
winston.debug("DirAiPrompt json: ", json);
|
|
181
|
-
|
|
182
|
-
const HTTPREQUEST = {
|
|
183
|
-
url: AI_endpoint + "/ask",
|
|
184
|
-
headers: headers,
|
|
185
|
-
json: json,
|
|
186
|
-
method: 'POST'
|
|
187
|
-
}
|
|
188
|
-
winston.debug("DirAiPrompt HttpRequest: ", HTTPREQUEST);
|
|
189
|
-
|
|
190
|
-
httpUtils.request(
|
|
191
|
-
HTTPREQUEST, async (err, resbody) => {
|
|
192
|
-
if (err) {
|
|
193
|
-
winston.error("DirAiPrompt openai err: ", err);
|
|
194
|
-
await this.#assignAttributes(action, answer);
|
|
195
|
-
let error;
|
|
196
|
-
if (err.response?.data?.detail[0]) {
|
|
197
|
-
error = err.response.data.detail[0]?.msg;
|
|
198
|
-
} else if (err.response?.data?.detail?.answer) {
|
|
199
|
-
error = err.response.data.detail.answer;
|
|
200
|
-
} else {
|
|
201
|
-
error = JSON.stringify(err.response.data);
|
|
202
|
-
}
|
|
203
|
-
this.logger.error("[AI Condition] error executing action: ", error);
|
|
204
|
-
if (falseIntent) {
|
|
205
|
-
await this.chatbot.addParameter("flowError", "AiPrompt Error: " + error);
|
|
206
|
-
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
207
|
-
callback(true);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
callback();
|
|
211
|
-
return;
|
|
212
|
-
} else {
|
|
213
|
-
|
|
214
|
-
winston.debug("DirAiPrompt resbody: ", resbody);
|
|
215
|
-
answer = resbody.answer;
|
|
216
|
-
this.logger.native("[AI Condition] answer: ", answer);
|
|
217
|
-
|
|
218
|
-
await this.#assignAttributes(action, answer);
|
|
219
|
-
|
|
220
|
-
if (answer === "fallback") {
|
|
221
|
-
if (falllbackIntent) {
|
|
222
|
-
this.#executeIntent(falllbackIntent, () => {
|
|
223
|
-
if (callback) {
|
|
224
|
-
callback(true);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
intents.forEach( i => {
|
|
232
|
-
if (i.label === answer) {
|
|
233
|
-
this.#executeIntent(i.conditionIntentId, () => {
|
|
234
|
-
if (callback) {
|
|
235
|
-
callback(true);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
this.logger.error("[AI Condition] error executing action: condition label not found in intents list");
|
|
243
|
-
if (falseIntent) {
|
|
244
|
-
await this.chatbot.addParameter("flowError", "[AI Condition] error executing action: condition label not found in intents list");
|
|
245
|
-
await this.#executeCondition(false, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes);
|
|
246
|
-
callback(true);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
callback();
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async checkMandatoryParameters(action) {
|
|
257
|
-
return new Promise((resolve, reject) => {
|
|
258
|
-
let params = ['question', 'llm', 'model']; // mandatory params
|
|
259
|
-
params.forEach((p) => {
|
|
260
|
-
if (!action[p]) {
|
|
261
|
-
reject(p)
|
|
262
|
-
}
|
|
263
|
-
})
|
|
264
|
-
resolve(true);
|
|
265
|
-
})
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Transforms the transcirpt array in a dictionary like '0': { "question": "xxx", "answer":"xxx"}
|
|
270
|
-
* merging consecutive messages with the same role in a single question or answer.
|
|
271
|
-
* If the first message was sent from assistant, this will be deleted.
|
|
272
|
-
*/
|
|
273
|
-
// async transcriptToLLM(transcript) {
|
|
274
|
-
|
|
275
|
-
// let objectTranscript = {};
|
|
276
|
-
|
|
277
|
-
// if (transcript.length === 0) {
|
|
278
|
-
// return objectTranscript;
|
|
279
|
-
// }
|
|
280
|
-
|
|
281
|
-
// let mergedTranscript = [];
|
|
282
|
-
// let current = transcript[0];
|
|
283
|
-
|
|
284
|
-
// for (let i = 1; i < transcript.length; i++) {
|
|
285
|
-
// if (transcript[i].role === current.role) {
|
|
286
|
-
// current.content += '\n' + transcript[i].content;
|
|
287
|
-
// } else {
|
|
288
|
-
// mergedTranscript.push(current);
|
|
289
|
-
// current = transcript[i]
|
|
290
|
-
// }
|
|
291
|
-
// }
|
|
292
|
-
// mergedTranscript.push(current);
|
|
293
|
-
|
|
294
|
-
// if (mergedTranscript[0].role === 'assistant') {
|
|
295
|
-
// mergedTranscript.splice(0, 1)
|
|
296
|
-
// }
|
|
297
|
-
|
|
298
|
-
// let counter = 0;
|
|
299
|
-
// for (let i = 0; i < mergedTranscript.length - 1; i += 2) {
|
|
300
|
-
// // Check if [i] is role user and [i+1] is role assistant??
|
|
301
|
-
// assert(mergedTranscript[i].role === 'user');
|
|
302
|
-
// assert(mergedTranscript[i+1].role === 'assistant');
|
|
303
|
-
|
|
304
|
-
// if (!mergedTranscript[i].content.startsWith('/')) {
|
|
305
|
-
// objectTranscript[counter] = {
|
|
306
|
-
// question: mergedTranscript[i].content,
|
|
307
|
-
// answer: mergedTranscript[i+1].content
|
|
308
|
-
// }
|
|
309
|
-
// counter++;
|
|
310
|
-
// }
|
|
311
|
-
// }
|
|
312
|
-
|
|
313
|
-
// return objectTranscript;
|
|
314
|
-
// }
|
|
315
|
-
|
|
316
|
-
async #executeCondition(result, trueIntent, trueIntentAttributes, falseIntent, falseIntentAttributes, callback) {
|
|
317
|
-
let trueIntentDirective = null;
|
|
318
|
-
if (trueIntent) {
|
|
319
|
-
trueIntentDirective = DirIntent.intentDirectiveFor(trueIntent, trueIntentAttributes);
|
|
320
|
-
}
|
|
321
|
-
let falseIntentDirective = null;
|
|
322
|
-
if (falseIntent) {
|
|
323
|
-
falseIntentDirective = DirIntent.intentDirectiveFor(falseIntent, falseIntentAttributes);
|
|
324
|
-
}
|
|
325
|
-
if (result === true) {
|
|
326
|
-
if (trueIntentDirective) {
|
|
327
|
-
this.logger.native("[AI Condition] executing true condition");
|
|
328
|
-
this.intentDir.execute(trueIntentDirective, () => {
|
|
329
|
-
if (callback) {
|
|
330
|
-
callback();
|
|
331
|
-
}
|
|
332
|
-
})
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
this.logger.native("[AI Condition] no block connected to true condition");
|
|
336
|
-
winston.debug("DirAiPrompt No trueIntentDirective specified");
|
|
337
|
-
if (callback) {
|
|
338
|
-
callback();
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
if (falseIntentDirective) {
|
|
344
|
-
this.logger.native("[AI Condition] executing false condition");
|
|
345
|
-
this.intentDir.execute(falseIntentDirective, () => {
|
|
346
|
-
if (callback) {
|
|
347
|
-
callback();
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
this.logger.native("[AI Condition] no block connected to false condition");
|
|
353
|
-
winston.debug("DirAiPrompt No falseIntentDirective specified");
|
|
354
|
-
if (callback) {
|
|
355
|
-
callback();
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
async #assignAttributes(action, answer) {
|
|
362
|
-
winston.debug("DirAiPrompt assignAttributes action: ", action)
|
|
363
|
-
winston.debug("DirAiPrompt assignAttributes answer: " + answer)
|
|
364
|
-
|
|
365
|
-
if (this.context.tdcache) {
|
|
366
|
-
if (action.assignReplyTo && answer) {
|
|
367
|
-
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, action.assignReplyTo, answer);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
async #executeIntent(destinationIntentId, callback) {
|
|
373
|
-
let intentDirective = null;
|
|
374
|
-
if (destinationIntentId) {
|
|
375
|
-
intentDirective = DirIntent.intentDirectiveFor(destinationIntentId, null);
|
|
376
|
-
}
|
|
377
|
-
if (intentDirective) {
|
|
378
|
-
this.logger.native("[AI Condition] executing destinationIntentId");
|
|
379
|
-
this.intentDir.execute(intentDirective, () => {
|
|
380
|
-
if (callback) {
|
|
381
|
-
callback();
|
|
382
|
-
}
|
|
383
|
-
})
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
this.logger.native("[AI Condition] no block connected to intentId:", destinationIntentId);
|
|
387
|
-
winston.debug("[AI Condition] no block connected to intentId:" + destinationIntentId);
|
|
388
|
-
if (callback) {
|
|
389
|
-
callback();
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
async getKeyFromKbSettings() {
|
|
395
|
-
return new Promise((resolve) => {
|
|
396
|
-
|
|
397
|
-
const KB_HTTPREQUEST = {
|
|
398
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/kbsettings",
|
|
399
|
-
headers: {
|
|
400
|
-
'Content-Type': 'application/json',
|
|
401
|
-
'Authorization': 'JWT ' + this.context.token
|
|
402
|
-
},
|
|
403
|
-
method: "GET"
|
|
404
|
-
}
|
|
405
|
-
winston.debug("DirAiPrompt KB HttpRequest", KB_HTTPREQUEST);
|
|
406
|
-
|
|
407
|
-
httpUtils.request(
|
|
408
|
-
KB_HTTPREQUEST, async (err, resbody) => {
|
|
409
|
-
if (err) {
|
|
410
|
-
winston.error("(httprequest) DirAiPrompt Get KnowledgeBase err: " + err.message);
|
|
411
|
-
resolve(null);
|
|
412
|
-
} else {
|
|
413
|
-
if (!resbody.gptkey) {
|
|
414
|
-
resolve(null);
|
|
415
|
-
} else {
|
|
416
|
-
resolve(resbody.gptkey);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
)
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
async checkQuoteAvailability() {
|
|
425
|
-
return new Promise((resolve) => {
|
|
426
|
-
|
|
427
|
-
const HTTPREQUEST = {
|
|
428
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/tokens",
|
|
429
|
-
headers: {
|
|
430
|
-
'Content-Type': 'application/json',
|
|
431
|
-
'Authorization': 'JWT ' + this.context.token
|
|
432
|
-
},
|
|
433
|
-
method: "GET"
|
|
434
|
-
}
|
|
435
|
-
winston.debug("DirAiPrompt check quote availability HttpRequest", HTTPREQUEST);
|
|
436
|
-
|
|
437
|
-
httpUtils.request(
|
|
438
|
-
HTTPREQUEST, async (err, resbody) => {
|
|
439
|
-
if (err) {
|
|
440
|
-
resolve(true)
|
|
441
|
-
} else {
|
|
442
|
-
if (resbody.isAvailable === true) {
|
|
443
|
-
resolve(true)
|
|
444
|
-
} else {
|
|
445
|
-
resolve(false)
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
)
|
|
450
|
-
})
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
async updateQuote(tokens_usage) {
|
|
454
|
-
return new Promise((resolve, reject) => {
|
|
455
|
-
|
|
456
|
-
const HTTPREQUEST = {
|
|
457
|
-
url: this.API_ENDPOINT + "/" + this.context.projectId + "/quotes/incr/tokens",
|
|
458
|
-
headers: {
|
|
459
|
-
'Content-Type': 'application/json',
|
|
460
|
-
'Authorization': 'JWT ' + this.context.token
|
|
461
|
-
},
|
|
462
|
-
json: tokens_usage,
|
|
463
|
-
method: "POST"
|
|
464
|
-
}
|
|
465
|
-
winston.debug("DirAiPrompt update quote HttpRequest", HTTPREQUEST);
|
|
466
|
-
|
|
467
|
-
httpUtils.request(
|
|
468
|
-
HTTPREQUEST, async (err, resbody) => {
|
|
469
|
-
if (err) {
|
|
470
|
-
winston.error("(httprequest) DirAiPrompt Increment tokens quote err: ", err);
|
|
471
|
-
reject(false)
|
|
472
|
-
} else {
|
|
473
|
-
winston.debug("(httprequest) DirAiPrompt Increment token quote resbody: ", resbody);
|
|
474
|
-
resolve(true);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
)
|
|
478
|
-
})
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
module.exports = { DirAiCondition }
|