@futdevpro/nts-dynamo 1.14.35 → 1.14.36

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 (37) hide show
  1. package/build/_modules/ai/_models/ai-input-interfaces.d.ts +20 -28
  2. package/build/_modules/ai/_models/ai-input-interfaces.d.ts.map +1 -1
  3. package/build/_modules/ai/_models/ai-input-interfaces.js +3 -0
  4. package/build/_modules/ai/_models/ai-input-interfaces.js.map +1 -1
  5. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +14 -58
  6. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts.map +1 -1
  7. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.js +138 -147
  8. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.js.map +1 -1
  9. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.d.ts +27 -180
  10. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.d.ts.map +1 -1
  11. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.js +147 -328
  12. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.js.map +1 -1
  13. package/build/_modules/ai/_services/ai-llm-chat.service-base.d.ts +22 -14
  14. package/build/_modules/ai/_services/ai-llm-chat.service-base.d.ts.map +1 -1
  15. package/build/_modules/ai/_services/ai-llm-chat.service-base.js.map +1 -1
  16. package/build/_modules/ai/_services/ai-llm.service-base.d.ts +52 -21
  17. package/build/_modules/ai/_services/ai-llm.service-base.d.ts.map +1 -1
  18. package/build/_modules/ai/_services/ai-llm.service-base.js +171 -0
  19. package/build/_modules/ai/_services/ai-llm.service-base.js.map +1 -1
  20. package/build/_modules/ai/_services/ai-provider.service-base.d.ts +1 -1
  21. package/build/_modules/ai/_services/ai-provider.service-base.d.ts.map +1 -1
  22. package/build/_modules/assistant/_services/ass-io.control-service.js +2 -2
  23. package/build/_modules/assistant/_services/ass-io.control-service.js.map +1 -1
  24. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +9 -9
  25. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -1
  26. package/build/_modules/discord-assistant/_services/dias-io.control-service.js +2 -2
  27. package/build/_modules/discord-assistant/_services/dias-io.control-service.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/_modules/ai/_models/ai-input-interfaces.ts +63 -26
  30. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +99 -139
  31. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +246 -294
  32. package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +36 -16
  33. package/src/_modules/ai/_services/ai-llm.service-base.ts +272 -28
  34. package/src/_modules/ai/_services/ai-provider.service-base.ts +1 -1
  35. package/src/_modules/assistant/_services/ass-io.control-service.ts +2 -2
  36. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +9 -9
  37. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +2 -2
@@ -20,14 +20,13 @@ import { DyNTS_OAI_global_settings } from '../_collections/oai-global-settings.c
20
20
  import { DyNTS_OAI_LLMDefaultPredefined_Requests } from '../_collections/oai-llm-predefined-requests.conts';
21
21
  import { DyNTS_AI_LLM_ServiceBase } from '../../../_services/ai-llm.service-base';
22
22
  import {
23
- DyFM_AI_Question_Input,
24
- DyFM_AI_ListSelect_Input,
23
+ DyFM_AI_Message_Input,
25
24
  DyFM_AI_GenericSelect_Input,
26
- DyFM_AI_MultiSelect_Input,
27
25
  DyFM_AI_GenericMultiSelect_Input,
28
26
  DyFM_AI_JSONKeysDescription_Input,
29
27
  DyFM_AI_JSONExactKeys_Input,
30
- DyFM_AI_SimpleMessage_Input
28
+ DyFM_AI_MultiSelect_Input,
29
+ DyFM_AI_ConversationBase_Input
31
30
  } from '../../../_models/ai-input-interfaces';
32
31
 
33
32
 
@@ -68,20 +67,19 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
68
67
  supportedModelTypes: ['gpt-4o', 'gpt-4o-mini', 'text-embedding-3-large', 'text-embedding-3-small']
69
68
  };
70
69
 
71
- get debugLog(): boolean {
70
+ /* get _debugLog(): boolean {
72
71
  return this.defaultSettings.debugLog;
73
- }
72
+ } */
74
73
 
75
- get defaultSystemPrompt(): string {
74
+ /* get defaultSystemPrompt(): string {
76
75
  return this.defaultSettings.systemPrompt;
77
- }
76
+ } */
78
77
 
79
- get defaultModel(): DyFM_OAI_Model | string {
78
+ override get defaultModel(): DyFM_OAI_Model | string {
80
79
  return this.defaultSettings.useModel;
81
80
  }
82
81
 
83
- predefinedRequests: DyNTS_OAI_LLM_Predefined_Requests =
84
- DyNTS_OAI_LLMDefaultPredefined_Requests;
82
+ predefinedRequests: DyNTS_OAI_LLM_Predefined_Requests = DyNTS_OAI_LLMDefaultPredefined_Requests;
85
83
 
86
84
  constructor(
87
85
  set?: DyFM_OAI_Settings
@@ -103,8 +101,17 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
103
101
  DyNTS_OAI_global_settings.defaultSettings ??
104
102
  new DyFM_OAI_CallSettings();
105
103
  }
104
+
105
+ /**
106
+ * Inicializálja az OpenAI client-et a megadott config-gal
107
+ *
108
+ * Reinitializes the OpenAI client with the provided config
109
+ */
110
+ setup(config: DyFM_AI_Config): void {
111
+ this.openai = new OpenAI(config);
112
+ }
106
113
 
107
- readonly defaultLogReplacer: string = '...long-context...';
114
+ /* readonly defaultLogReplacer: string = '...long-context...'; */
108
115
 
109
116
  //#region Ask Questions
110
117
 
@@ -114,23 +121,16 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
114
121
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.request} to ask the question,
115
122
  * and the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.upperCaseYes} to check the answer
116
123
  */
117
- async askYesNoQuestion(
118
- set: {
119
- question: string,
120
- issuer: string,
121
- settings?: DyFM_OAI_CallSettings,
122
- debugLog?: boolean,
123
- /** this is used to readably replace too long contents to eg '...' in logs */
124
- replaceThisInLog?: string
125
- }
124
+ async requestYesNo(
125
+ set: DyFM_AI_Message_Input
126
126
  ): Promise<boolean> {
127
- set.question += this.predefinedRequests.yesNo.request;
127
+ set.message += this.predefinedRequests.yesNo.request;
128
128
 
129
- const answer = await this.askQuestion(set);
129
+ const answer = await this.requestSimpleMessage(set);
130
130
 
131
- return answer.toUpperCase().includes(this.predefinedRequests.yesNo.upperCaseYes);
131
+ return this.convertAnswerToBoolean(answer);
132
132
  }
133
- /** the exact same as {@link askYesNoQuestion} */
133
+ /** the exact same as {@link requestYesNo} */
134
134
  //yesNoQuestion = this.askYesNoQuestion;
135
135
 
136
136
  /**
@@ -138,32 +138,16 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
138
138
  *
139
139
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.percentageOnly} to ask the question
140
140
  */
141
- async askPercentageQuestion(
142
- set: {
143
- question: string,
144
- issuer: string,
145
- settings?: DyFM_OAI_CallSettings,
146
- debugLog?: boolean,
147
- /** this is used to readably replace too long contents to eg '...' in logs */
148
- replaceThisInLog?: string,
149
- }
141
+ async requestPercentage(
142
+ set: DyFM_AI_Message_Input
150
143
  ): Promise<number> {
151
- set.question += this.predefinedRequests.percentageOnly;
152
-
153
- const answer = await this.askQuestion(set);
154
-
155
- if (isNaN(+answer)) {
156
- DyFM_Log.error('GPT_ServiceBase', 'asykPercentageQuestion', 'Invalid answer', {
157
- question: set.question,
158
- answer,
159
- });
144
+ set.message += this.predefinedRequests.percentageOnly;
160
145
 
161
- return null;
162
- }
146
+ const answer = await this.requestSimpleMessage(set);
163
147
 
164
- return +answer;
148
+ return this.convertAnswerToNumber(answer, set.message);
165
149
  }
166
- /** the exact same as {@link askPercentageQuestion} */
150
+ /** the exact same as {@link requestPercentage} */
167
151
  //percentageQuestion = this.askPercentageQuestion;
168
152
 
169
153
  /**
@@ -171,25 +155,17 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
171
155
  *
172
156
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
173
157
  */
174
- async askSelectQuestion(
175
- set: {
176
- question: string,
177
- selectFrom: string[],
178
- issuer: string,
179
- settings?: DyFM_OAI_CallSettings,
180
- debugLog?: boolean,
181
- /** this is used to readably replace too long contents to eg '...' in logs */
182
- replaceThisInLog?: string,
183
- }
158
+ /* async askSelectQuestion(
159
+ set: DyFM_AI_GenericSelect_Input<string>
184
160
  ): Promise<string> {
185
161
  // replace the {{DyNTS_selectOptions}} with the list of options
186
162
  const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
187
163
  '{{DyNTS_selectOptions}}',
188
164
  this.getTextListAsText(set.selectFrom)
189
165
  );
190
- set.question += selectQuestionAddition;
166
+ set.message += selectQuestionAddition;
191
167
 
192
- let answer = await this.askQuestion(set);
168
+ let answer = await this.requestSimpleMessage(set);
193
169
 
194
170
  answer = answer.toLocaleUpperCase();
195
171
 
@@ -198,7 +174,7 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
198
174
  }
199
175
 
200
176
  return null;
201
- }
177
+ } */
202
178
  /** the exact same as {@link askSelectQuestion} */
203
179
  //selectQuestion = this.askSelectQuestion;
204
180
 
@@ -210,25 +186,18 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
210
186
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
211
187
  */
212
188
  async requestSelect<T>(
213
- set: {
214
- question: string,
215
- selectFrom: T[],
216
- issuer: string,
217
- settings?: DyFM_OAI_CallSettings,
218
- debugLog?: boolean,
219
- /** this is used to readably replace too long contents to eg '...' in logs */
220
- replaceThisInLog?: string,
221
- }
189
+ set: DyFM_AI_GenericSelect_Input<T>
222
190
  ): Promise<T | { unparsableResult: string }> {
191
+ const options: string[] = this.stringifySelectOptions(set.selectFrom);
223
192
  const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
224
193
  '{{DyNTS_selectOptions}}',
225
- this.getTextListAsText(set.selectFrom.map(item => `"${JSON.stringify(item)}"`))
194
+ this.getTextListAsText(options)
226
195
  );
227
- set.question += selectQuestionAddition;
196
+ set.message += selectQuestionAddition;
228
197
 
229
- const answer = await this.askQuestion(set);
198
+ const answer = await this.requestSimpleMessage(set);
230
199
 
231
- return DyFM_Object.safeParseJSON<T>(answer);
200
+ return this.convertAnswerToSelectOption<T>(answer, set.message, set.selectFrom);
232
201
  }
233
202
  /** the exact same as {@link requestSelect} */
234
203
  //selectRequest = this.requestSelect;
@@ -238,36 +207,40 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
238
207
  *
239
208
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
240
209
  */
241
- async askMultipleSelectQuestionWithOptions(
242
- set: {
243
- question: string,
244
- options: string[],
245
- issuer: string,
246
- settings?: DyFM_OAI_CallSettings,
247
- debugLog?: boolean,
248
- /** this is used to readably replace too long contents to eg '...' in logs */
249
- replaceThisInLog?: string,
250
- }
251
- ): Promise<string[]> {
210
+ async requestMultiselect<T>(
211
+ set: DyFM_AI_GenericMultiSelect_Input<T, DyFM_OAI_CallSettings>
212
+ ): Promise<T[] | { unparsableResult: string }> {
213
+ const options: string[] = this.stringifySelectOptions(set.options);
252
214
  const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
253
215
  '{{DyNTS_selectOptions}}',
254
- this.getTextListAsText(set.options)
216
+ this.getTextListAsText(options)
255
217
  );
256
- set.question += selectQuestionAddition;
218
+ set.message += selectQuestionAddition;
257
219
 
258
- let answer = await this.askQuestion(set);
220
+ let answer = await this.requestSimpleMessage(set);
259
221
 
260
222
  answer = answer.toLocaleUpperCase();
261
223
 
262
- const result: string[] = [];
224
+ return this.convertAnswerToSelectOptions<T>(answer, set.message, set.options);
225
+ /* const result: T[] = [];
263
226
 
264
- for (const item of set.options) {
227
+ for (const item of options) {
265
228
  if (answer.includes(item.toLocaleUpperCase())) {
266
- result.push(item);
229
+ const parsedItem: T | { unparsableResult: string } = DyFM_Object.safeParseJSON<T>(item);
230
+ if ((parsedItem as { unparsableResult: string }).unparsableResult) {
231
+ result.push(item as any);
232
+ } else {
233
+ result.push(parsedItem as T);
234
+ }
235
+
267
236
  }
268
237
  }
269
238
 
270
- return result;
239
+ if (!result.length && !answer.trim().length) {
240
+ return { unparsableResult: answer };
241
+ }
242
+
243
+ return result; */
271
244
  }
272
245
  /** the exact same as {@link askMultipleSelectQuestionWithOptions} */
273
246
  //multipleSelectQuestion = this.askMultipleSelectQuestionWithOptions;
@@ -279,27 +252,19 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
279
252
  *
280
253
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
281
254
  */
282
- async requestMultipleSelect<T>(
283
- set: {
284
- question: string,
285
- options: T[],
286
- issuer: string,
287
- settings?: DyFM_OAI_CallSettings,
288
- debugLog?: boolean,
289
- /** this is used to readably replace too long contents to eg '...' in logs */
290
- replaceThisInLog?: string,
291
- }
255
+ /* async requestMultiselect<T>(
256
+ set: DyFM_AI_GenericMultiSelect_Input<T, DyFM_OAI_CallSettings>
292
257
  ): Promise<T[]> {
293
258
  const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
294
259
  '{{DyNTS_selectOptions}}',
295
260
  this.getTextListAsText(set.options.map(item => `"${JSON.stringify(item)}"`))
296
261
  );
297
- set.question += selectQuestionAddition;
262
+ set.message += selectQuestionAddition;
298
263
 
299
- const answer = await this.askQuestion(set);
264
+ const answer = await this.requestSimpleMessage(set);
300
265
 
301
266
  return DyFM_Object.safeParseList<T[]>(answer);
302
- }
267
+ } */
303
268
  /** the exact same as {@link requestMultipleSelect} */
304
269
  //multipleSelectRequest = this.requestMultipleSelect;
305
270
 
@@ -312,21 +277,14 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
312
277
  *
313
278
  * (uses {@link DyFM_safeParseJSON})
314
279
  */
315
- async askJSONQuestion<T = any>(
316
- set: {
317
- question: string,
318
- issuer: string,
319
- settings?: DyFM_OAI_CallSettings,
320
- debugLog?: boolean,
321
- /** this is used to readably replace too long contents to eg '...' in logs */
322
- replaceThisInLog?: string,
323
- }
280
+ async requestJSON<T = any>(
281
+ set: DyFM_AI_Message_Input<DyFM_OAI_CallSettings>
324
282
  ): Promise<T | { unparsableResult: string }> {
325
- set.question += this.predefinedRequests.jsonRequest;
283
+ set.message += this.predefinedRequests.jsonRequest;
326
284
 
327
- const answer = await this.askQuestion(set);
285
+ const answer = await this.requestSimpleMessage(set);
328
286
 
329
- return DyFM_Object.safeParseJSON<T>(answer);
287
+ return this.convertAnswerToJSON<T>(answer, set.message);
330
288
  }
331
289
  /** the exact same as {@link askJSONQuestion} */
332
290
  //jsonQuestion = this.askJSONQuestion;
@@ -340,28 +298,20 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
340
298
  *
341
299
  * (uses {@link DyFM_safeParseJSON})
342
300
  */
343
- async askJSONQuestionWithKeysDescription<T = any>(
344
- set: {
345
- question: string,
346
- keysDescription: string,
347
- issuer: string,
348
- settings?: DyFM_OAI_CallSettings,
349
- debugLog?: boolean,
350
- /** this is used to readably replace too long contents to eg '...' in logs */
351
- replaceThisInLog?: string,
352
- }
301
+ async requestJSONQuestionWithKeysDescription<T = any>(
302
+ set: DyFM_AI_JSONKeysDescription_Input<DyFM_OAI_CallSettings>
353
303
  ): Promise<T | { unparsableResult: string }> {
354
304
  const jsonRequestWithKeysDescription = this.predefinedRequests.jsonRequestWithKeysDescription.replace(
355
305
  '{{DyNTS_jsonKeysDescription}}',
356
306
  set.keysDescription
357
307
  );
358
- set.question += jsonRequestWithKeysDescription;
308
+ set.message += jsonRequestWithKeysDescription;
359
309
 
360
- const answer = await this.askQuestion(set);
310
+ const answer = await this.requestSimpleMessage(set);
361
311
 
362
- return DyFM_Object.safeParseJSON<T>(answer);
312
+ return this.convertAnswerToJSON<T>(answer, set.message);
363
313
  }
364
- /** the exact same as {@link askJSONQuestionWithKeysDescription} */
314
+ /** the exact same as {@link requestJSONQuestionWithKeysDescription} */
365
315
  //jsonQuestionWithKeysDescription = this.askJSONQuestionWithKeysDescription;
366
316
 
367
317
  /**
@@ -373,26 +323,18 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
373
323
  *
374
324
  * (uses {@link DyFM_safeParseJSON})
375
325
  */
376
- async askJSONQuestionWithExactKeys<T = any>(
377
- set: {
378
- question: string,
379
- keys: string[],
380
- issuer: string,
381
- settings?: DyFM_OAI_CallSettings,
382
- debugLog?: boolean,
383
- /** this is used to readably replace too long contents to eg '...' in logs */
384
- replaceThisInLog?: string,
385
- }
326
+ async requestJSONWithExactKeys<T = any>(
327
+ set: DyFM_AI_JSONExactKeys_Input<DyFM_OAI_CallSettings>
386
328
  ): Promise<T | { unparsableResult: string }> {
387
329
  const jsonRequestWithExactKeys = this.predefinedRequests.jsonRequestWithExactKeys.replace(
388
330
  '{{DyNTS_jsonKeys}}',
389
331
  this.getTextListAsText(set.keys)
390
332
  );
391
- set.question += jsonRequestWithExactKeys;
333
+ set.message += jsonRequestWithExactKeys;
392
334
 
393
- const answer = await this.askQuestion(set);
335
+ const answer = await this.requestSimpleMessage(set);
394
336
 
395
- return DyFM_Object.safeParseJSON<T>(answer);
337
+ return this.convertAnswerToJSON<T>(answer, set.message);
396
338
  }
397
339
  /** the exact same as {@link askJSONQuestionWithExactKeys} */
398
340
  //jsonQuestionWithExactKeys = this.askJSONQuestionWithExactKeys;
@@ -406,99 +348,74 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
406
348
  *
407
349
  * (uses {@link DyFM_Object.safeParseList})
408
350
  */
409
- async askListQuestion(
410
- set: {
411
- question: string,
412
- issuer: string,
413
- settings?: DyFM_OAI_CallSettings,
414
- debugLog?: boolean,
415
- /** this is used to readably replace too long contents to eg '...' in logs */
416
- replaceThisInLog?: string,
417
- }
351
+ /* async requestList(
352
+ set: DyFM_AI_Base_Input<DyFM_OAI_CallSettings>
418
353
  ): Promise<string[]> {
419
- set.question += this.predefinedRequests.listRequest;
354
+ set.message += this.predefinedRequests.listRequest;
420
355
 
421
- const answer = await this.askQuestion(set);
356
+ const answer = await this.requestSimpleMessage(set);
422
357
 
423
- return DyFM_Object.safeParseList<string[]>(answer);
424
- }
358
+ return this.convertAnswerToList<string>(answer, set.message);
359
+ } */
425
360
  /** the exact same as {@link askListQuestion} */
426
361
  //listQuestion = this.askListQuestion;
427
362
  /** the exact same as {@link askListQuestion} */
428
363
  //listRequest = this.askListQuestion;
364
+
365
+ async requestList<T = any>(
366
+ set: DyFM_AI_Message_Input<DyFM_OAI_CallSettings>
367
+ ): Promise<T[]> {
368
+ set.message += this.predefinedRequests.listRequest;
369
+
370
+ const answer = await this.requestSimpleMessage(set);
371
+
372
+ return this.convertAnswerToList<T>(answer, set.message);
373
+ }
429
374
 
430
375
  /**
431
376
  * Asks the AI to answer a question
432
377
  *
433
378
  * Uses the {@link resolveSimpleUserMessage}
434
379
  */
435
- async askQuestion(
436
- set: {
437
- question: string,
438
- issuer: string,
439
- settings?: DyFM_OAI_CallSettings,
440
- debugLog?: boolean,
441
- /** this is used to readably replace too long contents to eg '...' in logs */
442
- replaceThisInLog?: string,
443
- }
380
+ async requestSimpleMessage(
381
+ set: DyFM_AI_Message_Input<DyFM_OAI_CallSettings>
444
382
  ): Promise<string> {
445
383
  this.logQuestion(set);
446
384
 
447
- const answer = await this.resolveSimpleUserMessage({
448
- message: set.question,
449
- issuer: set.issuer,
450
- settings: set.settings,
451
- });
385
+ const answer: string = await this.resolveMessage({
386
+ ...set,
387
+ conversation: [{ role: DyFM_AI_MessageRole.user, content: set.message }],
388
+ getFullResponse: false,
389
+ }) as string;
452
390
 
453
- if (this.debugLog) {
454
- console.log(' - ', answer);
455
- }
391
+ this.logAnswer(answer);
456
392
 
457
393
  return answer;
458
394
  }
459
- /** the exact same as {@link askQuestion} */
395
+ /** the exact same as {@link requestSimpleMessage} */
460
396
  //answer = this.askQuestion;
461
- /** the exact same as {@link askQuestion} */
397
+ /** the exact same as {@link requestSimpleMessage} */
462
398
  //getQuestionAnswer = this.askQuestion;
463
- /** the exact same as {@link askQuestion} */
399
+ /** the exact same as {@link requestSimpleMessage} */
464
400
  //simpleQuestion = this.askQuestion;
465
- /** the exact same as {@link askQuestion} */
401
+ /** the exact same as {@link requestSimpleMessage} */
466
402
  //askSimpleQuestion = this.askQuestion;
467
403
 
468
- // async askJSONListQuestion(
469
- // question: string,
470
- // issuer: string,
471
- // settings?: DyFM_OAI_CallSettings,
472
- // debugLog?: boolean,
473
- // /** this is used to readably replace too long contents to eg '...' in logs */
474
- // replaceThisInLog?: string,
475
- // ): Promise<{ key: string, input: string }[]> {
476
- // question += this.predefinedRequests.jsonListRequest;
477
- //
478
- // const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
479
- //
480
- // return DyFM_Object.safeParseList<{ key: string, input: string }[]>(answer);
481
- // }
482
-
483
404
  /**
484
405
  * Resolves a simple user message and returns the answer as string
485
406
  *
486
407
  * Uses the {@link resolveMessage}
487
408
  */
488
- async resolveSimpleUserMessage(
489
- set: {
490
- message: string,
491
- issuer: string,
492
- settings?: DyFM_OAI_CallSettings
493
- }
409
+ /* async resolveSimpleUserMessage(
410
+ set: DyFM_AI_Base_Input<DyFM_OAI_CallSettings>
494
411
  ): Promise<string> {
495
412
  return this.resolveMessage({
496
413
  conversation: [{ role: DyFM_AI_MessageRole.user, content: set.message }],
497
- issuer: set.issuer,
498
- settings: set.settings,
414
+ issuer: set.issuer ?? 'unknown',
415
+ settings: set.settings ?? this.defaultSettings,
499
416
  getFullResponse: false,
500
417
  }) as Promise<string>;
501
- }
418
+ } */
502
419
  /** the exact same as {@link resolveSimpleUserMessage} */
503
420
  //simpleUserMessage = this.resolveSimpleUserMessage;
504
421
 
@@ -510,16 +427,25 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
510
427
  * Uses the {@link getMessageCreateInput}
511
428
  */
512
429
  async resolveMessage(
513
- set: {
430
+ set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>
431
+ /* {
432
+ conversation: [{ role: DyFM_AI_MessageRole.user, content: set.message }],
433
+ issuer: set.issuer ?? 'unknown',
434
+ settings: set.settings ?? this.defaultSettings,
435
+ getFullResponse: false,
436
+ } */
437
+ /* {
514
438
  conversation: DyFM_AI_Message[],
515
439
  issuer: string,
516
440
  settings?: DyFM_OAI_CallSettings,
517
441
  getFullResponse?: boolean
518
- }
442
+ } */
519
443
  ): Promise<string | ChatCompletion> {
520
444
  try {
521
445
  set.conversation.unshift(this.getDefaultSystemMessage(set.settings));
522
446
 
447
+
448
+
523
449
  const result: ChatCompletion = await this.openai.chat.completions.create(
524
450
  this.getMessageCreateInput(set)
525
451
  ) as ChatCompletion;
@@ -538,41 +464,6 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
538
464
  }
539
465
  }
540
466
 
541
- //#region Tools
542
-
543
- /**
544
- * Logs the question if the debugLog is true
545
- */
546
- protected logQuestion(
547
- set: {
548
- question: string,
549
- replaceThisInLog?: string,
550
- debugLog?: boolean
551
- }
552
- ): void {
553
- if (set.debugLog ?? this.debugLog) {
554
- if (set.replaceThisInLog) {
555
- set.question = set.question.replace(set.replaceThisInLog, this.defaultLogReplacer);
556
- }
557
-
558
- console.log('\n - ', set.question);
559
- }
560
- }
561
-
562
- /**
563
- * olvasható mondatszerű-listaszerű formába teszi a listaelemeket
564
- * pl.: ['a', 'b', 'c'] -> '"a", "b" or "c"'
565
- */
566
- getTextListAsText(list: string[]): string {
567
- list = list.filter(item => item?.trim()).map(item => `"${item}"`);
568
-
569
- /* list = list.map(item => item.toLocaleLowerCase()); */
570
-
571
- list.push(list.pop() + ' or ' + list.pop());
572
-
573
- return list.join(', ');
574
- }
575
-
576
467
  /**
577
468
  * Creates a message create input
578
469
  *
@@ -626,14 +517,74 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
626
517
  }
627
518
  }
628
519
 
629
- protected getDefaultSystemMessage(settings: DyFM_OAI_CallSettings): DyFM_AI_Message {
520
+ /**
521
+ * Teszteli a kapcsolatot az OpenAI API-val
522
+ *
523
+ * Tests the connection to OpenAI API
524
+ */
525
+ async testConnection(issuer: string): Promise<boolean> {
526
+ try {
527
+ await this.openai.models.list();
528
+ return true;
529
+ } catch (error) {
530
+ DyFM_Log.error('DyNTS_OAI_LLM_ServiceBase', 'testConnection', 'Connection test failed', {
531
+ error,
532
+ issuer
533
+ });
534
+ return false;
535
+ }
536
+ }
537
+
538
+ // async askJSONListQuestion(
539
+ // question: string,
540
+ // issuer: string,
541
+ // settings?: DyFM_OAI_CallSettings,
542
+ // debugLog?: boolean,
543
+ // /** this is used to readably replace too long contents to eg '...' in logs */
544
+ // replaceThisInLog?: string,
545
+ // ): Promise<{ key: string, input: string }[]> {
546
+ // question += this.predefinedRequests.jsonListRequest;
547
+ //
548
+ // const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
549
+ //
550
+ // return DyFM_Object.safeParseList<{ key: string, input: string }[]>(answer);
551
+ // }
552
+
553
+ //#region Tools
554
+
555
+ /**
556
+ * Logs the question if the debugLog is true
557
+ */
558
+ /* protected logQuestion(
559
+ set: DyFM_AI_Base_Input<DyFM_OAI_CallSettings>
560
+ ): void {
561
+ if (set.settings?.debugLog ?? this._debugLog) {
562
+ console.log('\n - ', set.message);
563
+ }
564
+ } */
565
+
566
+ /**
567
+ * olvasható mondatszerű-listaszerű formába teszi a listaelemeket
568
+ * pl.: ['a', 'b', 'c'] -> '"a", "b" or "c"'
569
+ */
570
+ /* getTextListAsText(list: string[]): string {
571
+ list = list.filter(item => item?.trim()).map(item => `"${item}"`);
572
+
573
+ //list = list.map(item => item.toLocaleLowerCase());
574
+
575
+ list.push(list.pop() + ' or ' + list.pop());
576
+
577
+ return list.join(', ');
578
+ } */
579
+
580
+ /* protected getDefaultSystemMessage(settings: DyFM_OAI_CallSettings): DyFM_AI_Message {
630
581
  return {
631
582
  role: DyFM_AI_MessageRole.system,
632
583
  content: settings?.systemPrompt || this.defaultSystemPrompt,
633
584
  };
634
- }
585
+ } */
635
586
 
636
- protected validateConversation(conversation: DyFM_AI_Message[]): void {
587
+ /* protected validateConversation(conversation: DyFM_AI_Message[]): void {
637
588
  conversation.forEach((message: DyFM_AI_Message, index: number) => {
638
589
  if (!message.role) {
639
590
  throw new DyFM_Error({
@@ -655,7 +606,7 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
655
606
  });
656
607
  }
657
608
  });
658
- }
609
+ } */
659
610
 
660
611
  /* protected getDefaultErrorSettings(
661
612
  fnName: string,
@@ -679,33 +630,6 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
679
630
 
680
631
  //#region Provider Methods (from DyNTS_AI_Provider_ServiceBase)
681
632
 
682
- /**
683
- * Inicializálja az OpenAI client-et a megadott config-gal
684
- *
685
- * Reinitializes the OpenAI client with the provided config
686
- */
687
- initialize(config: DyFM_AI_Config): void {
688
- this.openai = new OpenAI(config);
689
- }
690
-
691
- /**
692
- * Teszteli a kapcsolatot az OpenAI API-val
693
- *
694
- * Tests the connection to OpenAI API
695
- */
696
- async testConnection(issuer: string): Promise<boolean> {
697
- try {
698
- await this.openai.models.list();
699
- return true;
700
- } catch (error) {
701
- DyFM_Log.error('DyNTS_OAI_LLM_ServiceBase', 'testConnection', 'Connection test failed', {
702
- error,
703
- issuer
704
- });
705
- return false;
706
- }
707
- }
708
-
709
633
  //#endregion
710
634
 
711
635
  //#region Abstract LLM Methods (from DyNTS_AI_LLM_ServiceBase)
@@ -715,7 +639,7 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
715
639
  *
716
640
  * Calls the LLM with system and user messages
717
641
  */
718
- async callLLM(
642
+ /* async callLLM(
719
643
  systemMessage: string,
720
644
  userMessage: string,
721
645
  settings?: DyFM_AI_CallSettings,
@@ -735,14 +659,14 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
735
659
  return result;
736
660
  }
737
661
  return '';
738
- }
662
+ } */
739
663
 
740
664
  /**
741
665
  * Meghívja az LLM-et üzenet history-val
742
666
  *
743
667
  * Calls the LLM with message history
744
668
  */
745
- async callLLMWithHistory(
669
+ /* async callLLMWithHistory(
746
670
  messages: DyFM_AI_Message[],
747
671
  settings?: DyFM_AI_CallSettings,
748
672
  issuer?: string
@@ -758,14 +682,14 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
758
682
  return result;
759
683
  }
760
684
  return '';
761
- }
685
+ } */
762
686
 
763
687
  /**
764
688
  * Meghívja az LLM-et és visszaadja a raw response-t
765
689
  *
766
690
  * Calls the LLM and returns raw response
767
691
  */
768
- async callLLMRaw(
692
+ /* async callLLMRaw(
769
693
  messages: DyFM_AI_Message[],
770
694
  settings?: DyFM_AI_CallSettings,
771
695
  issuer?: string
@@ -788,27 +712,27 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
788
712
  finishReason: result.choices[0].finish_reason,
789
713
  rawResponse: result
790
714
  };
791
- }
715
+ } */
792
716
 
793
717
  /**
794
718
  * Küld egy egyszerű üzenetet az LLM-nek
795
719
  *
796
720
  * Sends a simple message to the LLM
797
721
  */
798
- async sendMessage(set: DyFM_AI_SimpleMessage_Input): Promise<string> {
722
+ /* async sendMessage(set: DyFM_AI_Base_Input<DyFM_OAI_CallSettings>): Promise<string> {
799
723
  return await this.resolveSimpleUserMessage({
800
724
  message: set.message,
801
725
  issuer: set.issuer,
802
726
  settings: set.settings ? this.convertToOAISettings(set.settings) : undefined
803
727
  });
804
- }
728
+ } */
805
729
 
806
730
  /**
807
731
  * Kérdez egy kérdést és JSON választ vár exact keys-szel
808
732
  *
809
733
  * Asks a question and expects JSON response with exact keys
810
734
  */
811
- async requestJSONWithExactKeys<T = any>(
735
+ /* async requestJSONWithExactKeys<T = any>(
812
736
  set: DyFM_AI_JSONExactKeys_Input
813
737
  ): Promise<T> {
814
738
  const answer = await this.askJSONQuestionWithExactKeys({
@@ -829,18 +753,18 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
829
753
  }
830
754
 
831
755
  return answer as T;
832
- }
756
+ } */
833
757
 
834
758
  /**
835
759
  * Kérdez egy kérdést és több választ vár
836
760
  *
837
761
  * Asks a question and expects multiple responses
838
762
  */
839
- async requestMultiselect<T = any>(
763
+ /* async requestMultiselect<T = any>(
840
764
  set: DyFM_AI_GenericMultiSelect_Input<T>
841
765
  ): Promise<T[]> {
842
766
  const answer = await this.requestMultipleSelect({
843
- question: set.question,
767
+ question: set.message,
844
768
  options: set.options,
845
769
  issuer: set.issuer,
846
770
  settings: set.settings ? this.convertToOAISettings(set.settings) : undefined,
@@ -849,30 +773,58 @@ export class DyNTS_OAI_LLM_ServiceBase extends DyNTS_AI_LLM_ServiceBase {
849
773
  });
850
774
 
851
775
  return answer as T[];
852
- }
776
+ } */
853
777
 
854
778
  /**
855
779
  * Konvertálja a generic AI settings-et OpenAI specifikus settings-re
856
780
  *
857
781
  * Converts generic AI settings to OpenAI-specific settings
858
782
  */
859
- private convertToOAISettings(settings?: DyFM_AI_CallSettings): DyFM_OAI_CallSettings {
860
- if (!settings) return undefined;
783
+ /* private convertToOAISettings(settings?: DyFM_AI_CallSettings): DyFM_OAI_CallSettings {
784
+ if (!settings) {
785
+ return undefined;
786
+ }
861
787
 
862
788
  const oaiSettings = new DyFM_OAI_CallSettings();
863
789
 
864
- if (settings.systemPrompt) oaiSettings.systemPrompt = settings.systemPrompt;
865
- if (settings.useModel) oaiSettings.useModel = settings.useModel as DyFM_OAI_Model;
866
- if (settings.project) oaiSettings.project = settings.project;
867
- if (settings.debugLog !== undefined) oaiSettings.debugLog = settings.debugLog;
868
- if (settings.temperature !== undefined) oaiSettings.temperature = settings.temperature;
869
- if (settings.maxTokens !== undefined) oaiSettings.maxTokens = settings.maxTokens;
870
- if (settings.topP !== undefined) oaiSettings.topP = settings.topP;
871
- if (settings.frequencyPenalty !== undefined) oaiSettings.frequencyPenalty = settings.frequencyPenalty;
872
- if (settings.presencePenalty !== undefined) oaiSettings.presencePenalty = settings.presencePenalty;
790
+ if (settings.systemPrompt !== undefined) {
791
+ oaiSettings.systemPrompt = settings.systemPrompt;
792
+ }
793
+
794
+ if (settings.useModel !== undefined) {
795
+ oaiSettings.useModel = settings.useModel as DyFM_OAI_Model;
796
+ }
797
+
798
+ if (settings.project !== undefined) {
799
+ oaiSettings.project = settings.project;
800
+ }
801
+
802
+ if (settings.debugLog !== undefined) {
803
+ oaiSettings.debugLog = settings.debugLog;
804
+ }
805
+
806
+ if (settings.temperature !== undefined) {
807
+ oaiSettings.temperature = settings.temperature;
808
+ }
809
+
810
+ if (settings.maxTokens !== undefined) {
811
+ oaiSettings.maxTokens = settings.maxTokens;
812
+ }
813
+
814
+ if (settings.topP !== undefined) {
815
+ oaiSettings.topP = settings.topP;
816
+ }
817
+
818
+ if (settings.frequencyPenalty !== undefined) {
819
+ oaiSettings.frequencyPenalty = settings.frequencyPenalty;
820
+ }
821
+
822
+ if (settings.presencePenalty !== undefined) {
823
+ oaiSettings.presencePenalty = settings.presencePenalty;
824
+ }
873
825
 
874
826
  return oaiSettings;
875
- }
827
+ } */
876
828
 
877
829
  //#endregion
878
830
  }