@futdevpro/nts-dynamo 1.11.16 → 1.11.18

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.
Files changed (68) hide show
  1. package/build/_modules/discord-assistant/_collections/dias.util.d.ts +10 -1
  2. package/build/_modules/discord-assistant/_collections/dias.util.d.ts.map +1 -1
  3. package/build/_modules/discord-assistant/_collections/dias.util.js +45 -0
  4. package/build/_modules/discord-assistant/_collections/dias.util.js.map +1 -1
  5. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts +1 -1
  6. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts.map +1 -1
  7. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +31 -13
  8. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -1
  9. package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts +2 -1
  10. package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts.map +1 -1
  11. package/build/_modules/discord-assistant/_services/dias-io.control-service.js +6 -2
  12. package/build/_modules/discord-assistant/_services/dias-io.control-service.js.map +1 -1
  13. package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts +0 -1
  14. package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts.map +1 -1
  15. package/build/_modules/discord-assistant/_services/dias-main.control-service.js +0 -15
  16. package/build/_modules/discord-assistant/_services/dias-main.control-service.js.map +1 -1
  17. package/build/_modules/discord-assistant/index.d.ts +1 -0
  18. package/build/_modules/discord-assistant/index.d.ts.map +1 -1
  19. package/build/_modules/discord-assistant/index.js +1 -0
  20. package/build/_modules/discord-assistant/index.js.map +1 -1
  21. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts +1 -1
  22. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts.map +1 -1
  23. package/build/_modules/discord-bot/_models/dibo-global-settings.interface.d.ts +88 -0
  24. package/build/_modules/discord-bot/_models/dibo-global-settings.interface.d.ts.map +1 -0
  25. package/build/_modules/discord-bot/_models/dibo-global-settings.interface.js +3 -0
  26. package/build/_modules/discord-bot/_models/dibo-global-settings.interface.js.map +1 -0
  27. package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts +2 -2
  28. package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts.map +1 -1
  29. package/build/_modules/discord-bot/_services/dibo-commands.control-service.js +4 -4
  30. package/build/_modules/discord-bot/_services/dibo-commands.control-service.js.map +1 -1
  31. package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts +6 -5
  32. package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts.map +1 -1
  33. package/build/_modules/discord-bot/_services/dibo-io.control-service.js +24 -15
  34. package/build/_modules/discord-bot/_services/dibo-io.control-service.js.map +1 -1
  35. package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts.map +1 -1
  36. package/build/_modules/discord-bot/_services/dibo-main.control-service.js +2 -1
  37. package/build/_modules/discord-bot/_services/dibo-main.control-service.js.map +1 -1
  38. package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts +0 -1
  39. package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts.map +1 -1
  40. package/build/_modules/discord-bot/_services/dibo-routines.control-service.js +0 -3
  41. package/build/_modules/discord-bot/_services/dibo-routines.control-service.js.map +1 -1
  42. package/build/_modules/discord-bot/index.d.ts +1 -1
  43. package/build/_modules/discord-bot/index.d.ts.map +1 -1
  44. package/build/_modules/discord-bot/index.js +1 -1
  45. package/build/_modules/discord-bot/index.js.map +1 -1
  46. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +284 -58
  47. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts.map +1 -1
  48. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js +91 -104
  49. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js.map +1 -1
  50. package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts +246 -53
  51. package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts.map +1 -1
  52. package/build/_modules/open-ai/_services/oai-llm.service-base.js +86 -96
  53. package/build/_modules/open-ai/_services/oai-llm.service-base.js.map +1 -1
  54. package/package.json +1 -1
  55. package/src/_modules/discord-assistant/_collections/dias.util.ts +79 -1
  56. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +26 -25
  57. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +8 -7
  58. package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +2 -2
  59. package/src/_modules/discord-assistant/index.ts +1 -0
  60. package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +1 -1
  61. package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +3 -3
  62. package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +36 -20
  63. package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +2 -1
  64. package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +2 -2
  65. package/src/_modules/discord-bot/index.ts +1 -1
  66. package/src/_modules/open-ai/_services/oai-llm-chat.service-base.ts +233 -249
  67. package/src/_modules/open-ai/_services/oai-llm.service-base.ts +189 -147
  68. /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
- conversation: DyNTS_OAI_GPT_Message[],
36
- question: string,
37
- issuer: string,
38
- debugLog?: boolean,
39
- settings?: DyFM_GPTCall_Settings,
40
- /** this is used to readably replace too long contents to eg '...' in logs */
41
- replaceThisInLog?: string
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(question, replaceThisInLog, debugLog);
47
+ this.logQuestion(set);
46
48
 
47
- const answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
67
- question: string,
68
- issuer: string,
69
- settings?: DyFM_GPTCall_Settings,
70
- debugLog?: boolean,
71
- /** this is used to readably replace too long contents to eg '...' in logs */
72
- replaceThisInLog?: string
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(question, replaceThisInLog, debugLog);
71
+ this.logQuestion(set);
75
72
 
76
- return await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
94
- question: string,
95
- issuer: string,
96
- settings?: DyFM_GPTCall_Settings,
97
- debugLog?: boolean,
98
- /** this is used to readably replace too long contents to eg '...' in logs */
99
- replaceThisInLog?: string
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(question, replaceThisInLog, debugLog);
95
+ this.logQuestion(set);
104
96
 
105
- const answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
135
- question: string,
136
- selectFrom: string[],
137
- issuer: string,
138
- settings?: DyFM_GPTCall_Settings,
139
- debugLog?: boolean,
140
- /** this is used to readably replace too long contents to eg '...' in logs */
141
- replaceThisInLog?: string
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(question, replaceThisInLog, debugLog);
137
+ this.logQuestion(set);
151
138
 
152
- let answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
180
- question: string,
181
- selectFrom: T[],
182
- issuer: string,
183
- settings?: DyFM_GPTCall_Settings,
184
- debugLog?: boolean,
185
- /** this is used to readably replace too long contents to eg '...' in logs */
186
- replaceThisInLog?: string,
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(question, null, debugLog);
176
+ this.logQuestion(set);
195
177
 
196
- const answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
216
- question: string,
217
- options: string[],
218
- issuer: string,
219
- settings?: DyFM_GPTCall_Settings,
220
- debugLog?: boolean,
221
- /** this is used to readably replace too long contents to eg '...' in logs */
222
- replaceThisInLog?: string
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.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
262
- question: string,
263
- options: T[],
264
- issuer: string,
265
- settings?: DyFM_GPTCall_Settings,
266
- debugLog?: boolean,
267
- /** this is used to readably replace too long contents to eg '...' in logs */
268
- replaceThisInLog?: string,
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(question, null, debugLog);
248
+ this.logQuestion(set);
277
249
 
278
- const answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
302
- question: string,
303
- issuer: string,
304
- settings?: DyFM_GPTCall_Settings,
305
- debugLog?: boolean,
306
- /** this is used to readably replace too long contents to eg '...' in logs */
307
- replaceThisInLog?: string
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(question, replaceThisInLog, debugLog);
278
+ this.logQuestion(set);
312
279
 
313
- const answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
337
- question: string,
338
- keysDescription: string,
339
- issuer: string,
340
- settings?: DyFM_GPTCall_Settings,
341
- debugLog?: boolean,
342
- /** this is used to readably replace too long contents to eg '...' in logs */
343
- replaceThisInLog?: string
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(question, replaceThisInLog, debugLog);
313
+ this.logQuestion(set);
352
314
 
353
- const answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
377
- question: string,
378
- keys: string[],
379
- issuer: string,
380
- settings?: DyFM_GPTCall_Settings,
381
- debugLog?: boolean,
382
- /** this is used to readably replace too long contents to eg '...' in logs */
383
- replaceThisInLog?: string
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(question, replaceThisInLog, debugLog);
348
+ this.logQuestion(set);
392
349
 
393
- const answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
417
- question: string,
418
- issuer: string,
419
- settings?: DyFM_GPTCall_Settings,
420
- debugLog?: boolean,
421
- /** this is used to readably replace too long contents to eg '...' in logs */
422
- replaceThisInLog?: string,
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(question, replaceThisInLog, debugLog);
378
+ this.logQuestion(set);
427
379
 
428
- const answer = await this.getAnswerInConversation(
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
- conversation: DyNTS_OAI_GPT_Message[],
476
- newMessage: string,
477
- issuer: string,
478
- settings?: DyFM_GPTCall_Settings,
479
- debugLog?: boolean,
480
- /** this is used to readably replace too long contents to eg '...' in logs */
481
- replaceThisInLog?: string,
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 = (await this.resolveConversation(
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
- getQuestionAnswerInConversation = this.getAnswerInConversation;
504
- getQuestionInConversation = this.getAnswerInConversation;
505
- askQuestionInConversation = this.getAnswerInConversation;
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
- conversation: DyNTS_OAI_GPT_Message[],
514
- issuer: string,
515
- settings?: DyFM_GPTCall_Settings,
516
- getFullResponse?: boolean,
517
- debugLog?: boolean,
518
- /** this is used to readably replace too long contents to eg '...' in logs */
519
- replaceThisInLog?: string,
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(conversation, issuer, debugLog);
498
+ const shortenedConversation = this.shortenConversation(set);
526
499
 
527
- this.logConversation(shortenedConversation, debugLog, replaceThisInLog);
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(shortenedConversation, issuer, settings)
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
- conversation: DyNTS_OAI_GPT_Message[],
550
- issuer: string,
551
- debugLog?: boolean,
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
- conversation: DyNTS_OAI_GPT_Message[],
609
- debugLog?: boolean,
610
- /** this is used to readably replace too long contents to eg '...' in logs */
611
- replaceThisInLog?: string,
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
  }