@futdevpro/nts-dynamo 1.11.15 → 1.11.17
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/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts +1 -1
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts.map +1 -1
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +31 -13
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -1
- package/build/_modules/discord-assistant/_services/dias-io.control-service.js +6 -2
- package/build/_modules/discord-assistant/_services/dias-io.control-service.js.map +1 -1
- package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts +1 -1
- package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts.map +1 -1
- package/build/_modules/discord-bot/_models/dibo-global-settings.interface.d.ts +88 -0
- package/build/_modules/discord-bot/_models/dibo-global-settings.interface.d.ts.map +1 -0
- package/build/_modules/discord-bot/_models/dibo-global-settings.interface.js +3 -0
- package/build/_modules/discord-bot/_models/dibo-global-settings.interface.js.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts +0 -1
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts.map +1 -1
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.js +0 -3
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.js.map +1 -1
- package/build/_modules/discord-bot/index.d.ts +1 -1
- package/build/_modules/discord-bot/index.d.ts.map +1 -1
- package/build/_modules/discord-bot/index.js +1 -1
- package/build/_modules/discord-bot/index.js.map +1 -1
- package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +284 -58
- package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts.map +1 -1
- package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js +91 -104
- package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js.map +1 -1
- package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts +246 -53
- package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts.map +1 -1
- package/build/_modules/open-ai/_services/oai-llm.service-base.js +86 -96
- package/build/_modules/open-ai/_services/oai-llm.service-base.js.map +1 -1
- package/package.json +3 -3
- package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +26 -25
- package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +6 -6
- package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +1 -1
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +2 -2
- package/src/_modules/discord-bot/index.ts +1 -1
- package/src/_modules/open-ai/_services/oai-llm-chat.service-base.ts +233 -249
- package/src/_modules/open-ai/_services/oai-llm.service-base.ts +189 -147
- /package/src/_modules/discord-bot/_models/{global-bot-log-settings.interface.ts → dibo-global-settings.interface.ts} +0 -0
|
@@ -32,26 +32,21 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
32
32
|
* and the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.upperCaseYes} to check the answer
|
|
33
33
|
*/
|
|
34
34
|
async yesNoQuestionInConversation(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
set: {
|
|
36
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
37
|
+
question: string,
|
|
38
|
+
issuer: string,
|
|
39
|
+
settings?: DyFM_GPTCall_Settings,
|
|
40
|
+
debugLog?: boolean,
|
|
41
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
42
|
+
replaceThisInLog?: string,
|
|
43
|
+
}
|
|
42
44
|
): Promise<boolean> {
|
|
43
|
-
question += this.predefinedRequests.yesNo.request;
|
|
45
|
+
set.question += this.predefinedRequests.yesNo.request;
|
|
44
46
|
|
|
45
|
-
this.logQuestion(
|
|
47
|
+
this.logQuestion(set);
|
|
46
48
|
|
|
47
|
-
const answer = await this.
|
|
48
|
-
conversation,
|
|
49
|
-
question,
|
|
50
|
-
issuer,
|
|
51
|
-
settings,
|
|
52
|
-
debugLog,
|
|
53
|
-
replaceThisInLog
|
|
54
|
-
);
|
|
49
|
+
const answer = await this.getQuestionAnswerInConversation(set);
|
|
55
50
|
|
|
56
51
|
return answer.toUpperCase().includes(this.predefinedRequests.yesNo.upperCaseYes);
|
|
57
52
|
}
|
|
@@ -63,24 +58,19 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
63
58
|
* Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.simpleQuestion} to ask the question
|
|
64
59
|
*/
|
|
65
60
|
async simpleQuestionInConversation(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
set: {
|
|
62
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
63
|
+
question: string,
|
|
64
|
+
issuer: string,
|
|
65
|
+
settings?: DyFM_GPTCall_Settings,
|
|
66
|
+
debugLog?: boolean,
|
|
67
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
68
|
+
replaceThisInLog?: string,
|
|
69
|
+
}
|
|
73
70
|
): Promise<string> {
|
|
74
|
-
this.logQuestion(
|
|
71
|
+
this.logQuestion(set);
|
|
75
72
|
|
|
76
|
-
return await this.
|
|
77
|
-
conversation,
|
|
78
|
-
question,
|
|
79
|
-
issuer,
|
|
80
|
-
settings,
|
|
81
|
-
debugLog,
|
|
82
|
-
replaceThisInLog
|
|
83
|
-
);
|
|
73
|
+
return await this.getQuestionAnswerInConversation(set);
|
|
84
74
|
}
|
|
85
75
|
askSimpleQuestionInConversation = this.simpleQuestionInConversation;
|
|
86
76
|
|
|
@@ -90,30 +80,25 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
90
80
|
* Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.percentageOnly} to ask the question
|
|
91
81
|
*/
|
|
92
82
|
async percentageQuestionInConversation(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
set: {
|
|
84
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
85
|
+
question: string,
|
|
86
|
+
issuer: string,
|
|
87
|
+
settings?: DyFM_GPTCall_Settings,
|
|
88
|
+
debugLog?: boolean,
|
|
89
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
90
|
+
replaceThisInLog?: string,
|
|
91
|
+
}
|
|
100
92
|
): Promise<number> {
|
|
101
|
-
question += this.predefinedRequests.percentageOnly;
|
|
93
|
+
set.question += this.predefinedRequests.percentageOnly;
|
|
102
94
|
|
|
103
|
-
this.logQuestion(
|
|
95
|
+
this.logQuestion(set);
|
|
104
96
|
|
|
105
|
-
const answer = await this.
|
|
106
|
-
conversation,
|
|
107
|
-
question,
|
|
108
|
-
issuer,
|
|
109
|
-
settings,
|
|
110
|
-
debugLog,
|
|
111
|
-
replaceThisInLog
|
|
112
|
-
);
|
|
97
|
+
const answer = await this.getQuestionAnswerInConversation(set);
|
|
113
98
|
|
|
114
99
|
if (isNaN(+answer)) {
|
|
115
100
|
DyFM_Log.error('GPT_ServiceBase', 'asykPercentageQuestion', 'Invalid answer', {
|
|
116
|
-
question,
|
|
101
|
+
question: set.question,
|
|
117
102
|
answer,
|
|
118
103
|
});
|
|
119
104
|
|
|
@@ -131,36 +116,31 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
131
116
|
* Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
|
|
132
117
|
*/
|
|
133
118
|
async selectQuestionInConversation(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
119
|
+
set: {
|
|
120
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
121
|
+
question: string,
|
|
122
|
+
selectFrom: string[],
|
|
123
|
+
issuer: string,
|
|
124
|
+
settings?: DyFM_GPTCall_Settings,
|
|
125
|
+
debugLog?: boolean,
|
|
126
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
127
|
+
replaceThisInLog?: string,
|
|
128
|
+
}
|
|
142
129
|
): Promise<string> {
|
|
143
130
|
// replace the {{DyNTS_selectOptions}} with the list of options
|
|
144
131
|
const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
|
|
145
132
|
'{{DyNTS_selectOptions}}',
|
|
146
|
-
this.getTextListAsText(selectFrom)
|
|
133
|
+
this.getTextListAsText(set.selectFrom)
|
|
147
134
|
);
|
|
148
|
-
question += selectQuestionAddition;
|
|
135
|
+
set.question += selectQuestionAddition;
|
|
149
136
|
|
|
150
|
-
this.logQuestion(
|
|
137
|
+
this.logQuestion(set);
|
|
151
138
|
|
|
152
|
-
let answer = await this.
|
|
153
|
-
conversation,
|
|
154
|
-
question,
|
|
155
|
-
issuer,
|
|
156
|
-
settings,
|
|
157
|
-
debugLog,
|
|
158
|
-
replaceThisInLog
|
|
159
|
-
);
|
|
139
|
+
let answer = await this.getQuestionAnswerInConversation(set);
|
|
160
140
|
|
|
161
141
|
answer = answer.toLocaleUpperCase();
|
|
162
142
|
|
|
163
|
-
for (const item of selectFrom) {
|
|
143
|
+
for (const item of set.selectFrom) {
|
|
164
144
|
if (answer.includes(item.toLocaleUpperCase())) return item;
|
|
165
145
|
}
|
|
166
146
|
|
|
@@ -176,31 +156,26 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
176
156
|
* Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
|
|
177
157
|
*/
|
|
178
158
|
async requestSelectInConversation<T>(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
159
|
+
set: {
|
|
160
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
161
|
+
question: string,
|
|
162
|
+
selectFrom: T[],
|
|
163
|
+
issuer: string,
|
|
164
|
+
settings?: DyFM_GPTCall_Settings,
|
|
165
|
+
debugLog?: boolean,
|
|
166
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
167
|
+
replaceThisInLog?: string,
|
|
168
|
+
}
|
|
187
169
|
): Promise<T | { unparsableResult: string }> {
|
|
188
170
|
const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
|
|
189
171
|
'{{DyNTS_selectOptions}}',
|
|
190
|
-
this.getTextListAsText(selectFrom.map(item => `"${JSON.stringify(item)}"`))
|
|
172
|
+
this.getTextListAsText(set.selectFrom.map(item => `"${JSON.stringify(item)}"`))
|
|
191
173
|
);
|
|
192
|
-
question += selectQuestionAddition;
|
|
174
|
+
set.question += selectQuestionAddition;
|
|
193
175
|
|
|
194
|
-
this.logQuestion(
|
|
176
|
+
this.logQuestion(set);
|
|
195
177
|
|
|
196
|
-
const answer = await this.
|
|
197
|
-
conversation,
|
|
198
|
-
question,
|
|
199
|
-
issuer,
|
|
200
|
-
settings,
|
|
201
|
-
debugLog,
|
|
202
|
-
replaceThisInLog
|
|
203
|
-
);
|
|
178
|
+
const answer = await this.getQuestionAnswerInConversation(set);
|
|
204
179
|
|
|
205
180
|
return DyFM_safeParseJSON<T>(answer);
|
|
206
181
|
}
|
|
@@ -212,35 +187,30 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
212
187
|
* Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
|
|
213
188
|
*/
|
|
214
189
|
async multipleSelectQuestionWithOptionsInConversation(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
190
|
+
set: {
|
|
191
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
192
|
+
question: string,
|
|
193
|
+
options: string[],
|
|
194
|
+
issuer: string,
|
|
195
|
+
settings?: DyFM_GPTCall_Settings,
|
|
196
|
+
debugLog?: boolean,
|
|
197
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
198
|
+
replaceThisInLog?: string,
|
|
199
|
+
}
|
|
223
200
|
): Promise<string[]> {
|
|
224
201
|
const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
|
|
225
202
|
'{{DyNTS_selectOptions}}',
|
|
226
|
-
this.getTextListAsText(options)
|
|
203
|
+
this.getTextListAsText(set.options)
|
|
227
204
|
);
|
|
228
|
-
question += selectQuestionAddition;
|
|
205
|
+
set.question += selectQuestionAddition;
|
|
229
206
|
|
|
230
|
-
let answer = await this.
|
|
231
|
-
conversation,
|
|
232
|
-
question,
|
|
233
|
-
issuer,
|
|
234
|
-
settings,
|
|
235
|
-
debugLog,
|
|
236
|
-
replaceThisInLog
|
|
237
|
-
);
|
|
207
|
+
let answer = await this.getQuestionAnswerInConversation(set);
|
|
238
208
|
|
|
239
209
|
answer = answer.toLocaleUpperCase();
|
|
240
210
|
|
|
241
211
|
const result: string[] = [];
|
|
242
212
|
|
|
243
|
-
for (const item of options) {
|
|
213
|
+
for (const item of set.options) {
|
|
244
214
|
if (answer.includes(item.toLocaleUpperCase())) {
|
|
245
215
|
result.push(item);
|
|
246
216
|
}
|
|
@@ -258,31 +228,26 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
258
228
|
* Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
|
|
259
229
|
*/
|
|
260
230
|
async requestMultipleSelectInConversation<T>(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
231
|
+
set: {
|
|
232
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
233
|
+
question: string,
|
|
234
|
+
options: T[],
|
|
235
|
+
issuer: string,
|
|
236
|
+
settings?: DyFM_GPTCall_Settings,
|
|
237
|
+
debugLog?: boolean,
|
|
238
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
239
|
+
replaceThisInLog?: string,
|
|
240
|
+
}
|
|
269
241
|
): Promise<T[]> {
|
|
270
242
|
const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
|
|
271
243
|
'{{DyNTS_selectOptions}}',
|
|
272
|
-
this.getTextListAsText(options.map(item => `"${JSON.stringify(item)}"`))
|
|
244
|
+
this.getTextListAsText(set.options.map(item => `"${JSON.stringify(item)}"`))
|
|
273
245
|
);
|
|
274
|
-
question += selectQuestionAddition;
|
|
246
|
+
set.question += selectQuestionAddition;
|
|
275
247
|
|
|
276
|
-
this.logQuestion(
|
|
248
|
+
this.logQuestion(set);
|
|
277
249
|
|
|
278
|
-
const answer = await this.
|
|
279
|
-
conversation,
|
|
280
|
-
question,
|
|
281
|
-
issuer,
|
|
282
|
-
settings,
|
|
283
|
-
debugLog,
|
|
284
|
-
replaceThisInLog
|
|
285
|
-
);
|
|
250
|
+
const answer = await this.getQuestionAnswerInConversation(set);
|
|
286
251
|
|
|
287
252
|
return DyFM_safeParseList<T[]>(answer);
|
|
288
253
|
}
|
|
@@ -298,26 +263,21 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
298
263
|
* (uses {@link DyFM_safeParseJSON})
|
|
299
264
|
*/
|
|
300
265
|
async jsonQuestionInConversation<T = any>(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
266
|
+
set: {
|
|
267
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
268
|
+
question: string,
|
|
269
|
+
issuer: string,
|
|
270
|
+
settings?: DyFM_GPTCall_Settings,
|
|
271
|
+
debugLog?: boolean,
|
|
272
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
273
|
+
replaceThisInLog?: string,
|
|
274
|
+
}
|
|
308
275
|
): Promise<T | { unparsableResult: string }> {
|
|
309
|
-
question += this.predefinedRequests.jsonRequest;
|
|
276
|
+
set.question += this.predefinedRequests.jsonRequest;
|
|
310
277
|
|
|
311
|
-
this.logQuestion(
|
|
278
|
+
this.logQuestion(set);
|
|
312
279
|
|
|
313
|
-
const answer = await this.
|
|
314
|
-
conversation,
|
|
315
|
-
question,
|
|
316
|
-
issuer,
|
|
317
|
-
settings,
|
|
318
|
-
debugLog,
|
|
319
|
-
replaceThisInLog
|
|
320
|
-
);
|
|
280
|
+
const answer = await this.getQuestionAnswerInConversation(set);
|
|
321
281
|
|
|
322
282
|
return DyFM_safeParseJSON<T>(answer);
|
|
323
283
|
}
|
|
@@ -333,31 +293,26 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
333
293
|
* (uses {@link DyFM_safeParseJSON})
|
|
334
294
|
*/
|
|
335
295
|
async jsonQuestionWithKeysDescriptionInConversation<T = any>(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
296
|
+
set: {
|
|
297
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
298
|
+
question: string,
|
|
299
|
+
keysDescription: string,
|
|
300
|
+
issuer: string,
|
|
301
|
+
settings?: DyFM_GPTCall_Settings,
|
|
302
|
+
debugLog?: boolean,
|
|
303
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
304
|
+
replaceThisInLog?: string,
|
|
305
|
+
}
|
|
344
306
|
): Promise<T | { unparsableResult: string }> {
|
|
345
307
|
const jsonRequestWithKeysDescription = this.predefinedRequests.jsonRequestWithKeysDescription.replace(
|
|
346
308
|
'{{DyNTS_jsonKeysDescription}}',
|
|
347
|
-
keysDescription
|
|
309
|
+
set.keysDescription
|
|
348
310
|
);
|
|
349
|
-
question += jsonRequestWithKeysDescription;
|
|
311
|
+
set.question += jsonRequestWithKeysDescription;
|
|
350
312
|
|
|
351
|
-
this.logQuestion(
|
|
313
|
+
this.logQuestion(set);
|
|
352
314
|
|
|
353
|
-
const answer = await this.
|
|
354
|
-
conversation,
|
|
355
|
-
question,
|
|
356
|
-
issuer,
|
|
357
|
-
settings,
|
|
358
|
-
debugLog,
|
|
359
|
-
replaceThisInLog
|
|
360
|
-
);
|
|
315
|
+
const answer = await this.getQuestionAnswerInConversation(set);
|
|
361
316
|
|
|
362
317
|
return DyFM_safeParseJSON<T>(answer);
|
|
363
318
|
}
|
|
@@ -373,31 +328,26 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
373
328
|
* (uses {@link DyFM_safeParseJSON})
|
|
374
329
|
*/
|
|
375
330
|
async jsonQuestionWithExactKeysInConversation<T = any>(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
331
|
+
set: {
|
|
332
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
333
|
+
question: string,
|
|
334
|
+
keys: string[],
|
|
335
|
+
issuer: string,
|
|
336
|
+
settings?: DyFM_GPTCall_Settings,
|
|
337
|
+
debugLog?: boolean,
|
|
338
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
339
|
+
replaceThisInLog?: string,
|
|
340
|
+
}
|
|
384
341
|
): Promise<T | { unparsableResult: string }> {
|
|
385
342
|
const jsonRequestWithExactKeys = this.predefinedRequests.jsonRequestWithExactKeys.replace(
|
|
386
343
|
'{{DyNTS_jsonKeys}}',
|
|
387
|
-
this.getTextListAsText(keys)
|
|
344
|
+
this.getTextListAsText(set.keys)
|
|
388
345
|
);
|
|
389
|
-
question += jsonRequestWithExactKeys;
|
|
346
|
+
set.question += jsonRequestWithExactKeys;
|
|
390
347
|
|
|
391
|
-
this.logQuestion(
|
|
348
|
+
this.logQuestion(set);
|
|
392
349
|
|
|
393
|
-
const answer = await this.
|
|
394
|
-
conversation,
|
|
395
|
-
question,
|
|
396
|
-
issuer,
|
|
397
|
-
settings,
|
|
398
|
-
debugLog,
|
|
399
|
-
replaceThisInLog
|
|
400
|
-
);
|
|
350
|
+
const answer = await this.getQuestionAnswerInConversation(set);
|
|
401
351
|
|
|
402
352
|
return DyFM_safeParseJSON<T>(answer);
|
|
403
353
|
}
|
|
@@ -413,26 +363,21 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
413
363
|
* (uses {@link DyFM_safeParseList})
|
|
414
364
|
*/
|
|
415
365
|
async listQuestionInConversation(
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
366
|
+
set: {
|
|
367
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
368
|
+
question: string,
|
|
369
|
+
issuer: string,
|
|
370
|
+
settings?: DyFM_GPTCall_Settings,
|
|
371
|
+
debugLog?: boolean,
|
|
372
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
373
|
+
replaceThisInLog?: string,
|
|
374
|
+
}
|
|
423
375
|
): Promise<string[]> {
|
|
424
|
-
question += this.predefinedRequests.listRequest;
|
|
376
|
+
set.question += this.predefinedRequests.listRequest;
|
|
425
377
|
|
|
426
|
-
this.logQuestion(
|
|
378
|
+
this.logQuestion(set);
|
|
427
379
|
|
|
428
|
-
const answer = await this.
|
|
429
|
-
conversation,
|
|
430
|
-
question,
|
|
431
|
-
issuer,
|
|
432
|
-
settings,
|
|
433
|
-
debugLog,
|
|
434
|
-
replaceThisInLog
|
|
435
|
-
);
|
|
380
|
+
const answer = await this.getQuestionAnswerInConversation(set);
|
|
436
381
|
|
|
437
382
|
return DyFM_safeParseList(answer);
|
|
438
383
|
}
|
|
@@ -463,6 +408,26 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
463
408
|
|
|
464
409
|
return answer;
|
|
465
410
|
} */
|
|
411
|
+
|
|
412
|
+
async getQuestionAnswerInConversation(
|
|
413
|
+
set: {
|
|
414
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
415
|
+
question: string,
|
|
416
|
+
issuer: string,
|
|
417
|
+
settings?: DyFM_GPTCall_Settings,
|
|
418
|
+
debugLog?: boolean,
|
|
419
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
420
|
+
replaceThisInLog?: string,
|
|
421
|
+
}
|
|
422
|
+
): Promise<string> {
|
|
423
|
+
return await this.getAnswerInConversation({
|
|
424
|
+
...set,
|
|
425
|
+
newMessage: set.question,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
/* getQuestionAnswerInConversation = this.getAnswerInConversation; */
|
|
429
|
+
getQuestionInConversation = this.getQuestionAnswerInConversation;
|
|
430
|
+
askQuestionInConversation = this.getQuestionAnswerInConversation;
|
|
466
431
|
|
|
467
432
|
/**
|
|
468
433
|
* Asks the AI to answer a question using the whole conversation
|
|
@@ -472,37 +437,43 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
472
437
|
* Uses the {@link resolveConversation}
|
|
473
438
|
*/
|
|
474
439
|
async getAnswerInConversation(
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
440
|
+
set: {
|
|
441
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
442
|
+
newMessage: string,
|
|
443
|
+
issuer: string,
|
|
444
|
+
settings?: DyFM_GPTCall_Settings,
|
|
445
|
+
debugLog?: boolean,
|
|
446
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
447
|
+
replaceThisInLog?: string,
|
|
448
|
+
}
|
|
482
449
|
): Promise<string> {
|
|
483
|
-
conversation.push({
|
|
450
|
+
set.conversation.push({
|
|
484
451
|
role: DyNTS_OAI_GPT_Message_Role.user,
|
|
485
|
-
content: newMessage,
|
|
452
|
+
content: set.newMessage,
|
|
486
453
|
});
|
|
487
454
|
|
|
488
|
-
const answer: string =
|
|
489
|
-
conversation,
|
|
490
|
-
issuer,
|
|
491
|
-
settings,
|
|
492
|
-
false,
|
|
493
|
-
debugLog,
|
|
494
|
-
replaceThisInLog,
|
|
495
|
-
)) as string;
|
|
455
|
+
const answer: string = await this.resolveConversationMessage(set);
|
|
496
456
|
|
|
497
|
-
if (debugLog || this.debugLog) {
|
|
457
|
+
if (set.debugLog || this.debugLog) {
|
|
498
458
|
console.log(' - answer: ', answer);
|
|
499
459
|
}
|
|
500
460
|
|
|
501
461
|
return answer;
|
|
502
462
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
463
|
+
|
|
464
|
+
async resolveConversationMessage(
|
|
465
|
+
set: {
|
|
466
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
467
|
+
issuer: string,
|
|
468
|
+
settings?: DyFM_GPTCall_Settings,
|
|
469
|
+
getFullResponse?: boolean,
|
|
470
|
+
debugLog?: boolean,
|
|
471
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
472
|
+
replaceThisInLog?: string,
|
|
473
|
+
}
|
|
474
|
+
): Promise<string> {
|
|
475
|
+
return await this.resolveConversation(set) as string;
|
|
476
|
+
}
|
|
506
477
|
|
|
507
478
|
/**
|
|
508
479
|
* Resolves a conversation
|
|
@@ -510,34 +481,42 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
510
481
|
* Uses the {@link getMessageCreateInput}
|
|
511
482
|
*/
|
|
512
483
|
async resolveConversation(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
484
|
+
set: {
|
|
485
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
486
|
+
issuer: string,
|
|
487
|
+
settings?: DyFM_GPTCall_Settings,
|
|
488
|
+
getFullResponse?: boolean,
|
|
489
|
+
debugLog?: boolean,
|
|
490
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
491
|
+
replaceThisInLog?: string,
|
|
492
|
+
}
|
|
520
493
|
): Promise<string | ChatCompletion> {
|
|
521
494
|
try {
|
|
522
|
-
conversation.unshift(this.getDefaultSystemMessage(settings));
|
|
495
|
+
set.conversation.unshift(this.getDefaultSystemMessage(set.settings));
|
|
523
496
|
|
|
524
497
|
// conversation shortening
|
|
525
|
-
const shortenedConversation = this.shortenConversation(
|
|
498
|
+
const shortenedConversation = this.shortenConversation(set);
|
|
526
499
|
|
|
527
|
-
this.logConversation(
|
|
500
|
+
this.logConversation({
|
|
501
|
+
...set,
|
|
502
|
+
conversation: shortenedConversation,
|
|
503
|
+
});
|
|
528
504
|
|
|
529
505
|
const result: ChatCompletion = await this.openai.chat.completions.create(
|
|
530
|
-
this.getMessageCreateInput(
|
|
506
|
+
this.getMessageCreateInput({
|
|
507
|
+
...set,
|
|
508
|
+
conversation: shortenedConversation,
|
|
509
|
+
})
|
|
531
510
|
) as ChatCompletion;
|
|
532
511
|
|
|
533
|
-
if (getFullResponse) {
|
|
512
|
+
if (set.getFullResponse) {
|
|
534
513
|
return result;
|
|
535
514
|
}
|
|
536
515
|
|
|
537
516
|
return result.choices[0].message.content;
|
|
538
517
|
} catch (error) {
|
|
539
518
|
throw new DyFM_Error({
|
|
540
|
-
...this.getDefaultErrorSettings('resolveConversation', error, issuer),
|
|
519
|
+
...this.getDefaultErrorSettings('resolveConversation', error, set.issuer),
|
|
541
520
|
|
|
542
521
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-OAB-RC0`,
|
|
543
522
|
});
|
|
@@ -546,12 +525,14 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
546
525
|
resolveSimpleUserMessageInConversation = this.resolveConversation;
|
|
547
526
|
|
|
548
527
|
protected shortenConversation(
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
528
|
+
set: {
|
|
529
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
530
|
+
issuer: string,
|
|
531
|
+
debugLog?: boolean,
|
|
532
|
+
}
|
|
552
533
|
): DyNTS_OAI_GPT_Message[] {
|
|
553
534
|
try {
|
|
554
|
-
const clonedConversation = DyFM_clone(conversation);
|
|
535
|
+
const clonedConversation = DyFM_clone(set.conversation);
|
|
555
536
|
const systemMessages = clonedConversation.filter(
|
|
556
537
|
message => message.role === DyNTS_OAI_GPT_Message_Role.system
|
|
557
538
|
);
|
|
@@ -561,7 +542,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
561
542
|
).map(message => message.content);
|
|
562
543
|
let stringifiedMessages = JSON.stringify(msgs);
|
|
563
544
|
|
|
564
|
-
if (this.debugLog || debugLog) {
|
|
545
|
+
if (this.debugLog || set.debugLog) {
|
|
565
546
|
console.log('stringifiedMessagesCount before removing', stringifiedMessages.length);
|
|
566
547
|
}
|
|
567
548
|
|
|
@@ -579,7 +560,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
579
560
|
lastStringifiedMessagesLength = stringifiedMessages.length;
|
|
580
561
|
}
|
|
581
562
|
|
|
582
|
-
if (this.debugLog || debugLog) {
|
|
563
|
+
if (this.debugLog || set.debugLog) {
|
|
583
564
|
console.log('removedMessagesCount', removedMessagesCount);
|
|
584
565
|
console.log('lastStringifiedMessagesLength', lastStringifiedMessagesLength);
|
|
585
566
|
}
|
|
@@ -587,7 +568,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
587
568
|
if (!clonedConversation.length) {
|
|
588
569
|
DyFM_Log.error('No conversation messages (left)', {
|
|
589
570
|
/* conversation: DyFM_clone(conversation), */
|
|
590
|
-
conversationLength: conversation.length,
|
|
571
|
+
conversationLength: set.conversation.length,
|
|
591
572
|
clonedConversation: DyFM_clone(clonedConversation),
|
|
592
573
|
});
|
|
593
574
|
throw new Error('No conversation messages (left)');
|
|
@@ -596,8 +577,9 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
596
577
|
return [ ...systemMessages, ...clonedConversation ];
|
|
597
578
|
} catch (error) {
|
|
598
579
|
console.error('❌❌ Error shortening conversation:', error);
|
|
580
|
+
|
|
599
581
|
throw new DyFM_Error({
|
|
600
|
-
...this.getDefaultErrorSettings('shortenConversation', error, issuer),
|
|
582
|
+
...this.getDefaultErrorSettings('shortenConversation', error, set.issuer),
|
|
601
583
|
|
|
602
584
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-OAB-SC0`,
|
|
603
585
|
});
|
|
@@ -605,15 +587,17 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
|
|
|
605
587
|
}
|
|
606
588
|
|
|
607
589
|
protected logConversation(
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
590
|
+
set: {
|
|
591
|
+
conversation: DyNTS_OAI_GPT_Message[],
|
|
592
|
+
debugLog?: boolean,
|
|
593
|
+
/** this is used to readably replace too long contents to eg '...' in logs */
|
|
594
|
+
replaceThisInLog?: string,
|
|
595
|
+
}
|
|
612
596
|
) {
|
|
613
|
-
if (debugLog || this.debugLog) {
|
|
614
|
-
conversation.forEach(message => {
|
|
597
|
+
if (set.debugLog || this.debugLog) {
|
|
598
|
+
set.conversation.forEach(message => {
|
|
615
599
|
console.log(
|
|
616
|
-
` - ${message.role}: ${message.content.replace(replaceThisInLog, this.defaultLogReplacer)}`
|
|
600
|
+
` - ${message.role}: ${message.content.replace(set.replaceThisInLog, this.defaultLogReplacer)}`
|
|
617
601
|
);
|
|
618
602
|
});
|
|
619
603
|
}
|