@futdevpro/nts-dynamo 1.14.35 → 1.14.37

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 (58) 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/bot/_models/bot-channel-wrapper.interface.d.ts +8 -2
  25. package/build/_modules/bot/_models/bot-channel-wrapper.interface.d.ts.map +1 -1
  26. package/build/_modules/bot/_models/bot-channel-wrapper.interface.js +31 -0
  27. package/build/_modules/bot/_models/bot-channel-wrapper.interface.js.map +1 -1
  28. package/build/_modules/bot/_models/bot-message-wrapper.interface.d.ts +6 -1
  29. package/build/_modules/bot/_models/bot-message-wrapper.interface.d.ts.map +1 -1
  30. package/build/_modules/bot/_models/bot-message-wrapper.interface.js +39 -0
  31. package/build/_modules/bot/_models/bot-message-wrapper.interface.js.map +1 -1
  32. package/build/_modules/bot/_models/bot-user-wrapper.interface.d.ts +2 -1
  33. package/build/_modules/bot/_models/bot-user-wrapper.interface.d.ts.map +1 -1
  34. package/build/_modules/bot/_models/bot-user-wrapper.interface.js +18 -0
  35. package/build/_modules/bot/_models/bot-user-wrapper.interface.js.map +1 -1
  36. package/build/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.js +9 -6
  37. package/build/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.js.map +1 -1
  38. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.js +9 -6
  39. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.js.map +1 -1
  40. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +9 -9
  41. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -1
  42. package/build/_modules/discord-assistant/_services/dias-io.control-service.js +2 -2
  43. package/build/_modules/discord-assistant/_services/dias-io.control-service.js.map +1 -1
  44. package/package.json +1 -1
  45. package/src/_modules/ai/_models/ai-input-interfaces.ts +63 -26
  46. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +99 -139
  47. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +246 -294
  48. package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +36 -16
  49. package/src/_modules/ai/_services/ai-llm.service-base.ts +272 -28
  50. package/src/_modules/ai/_services/ai-provider.service-base.ts +1 -1
  51. package/src/_modules/assistant/_services/ass-io.control-service.ts +2 -2
  52. package/src/_modules/bot/_models/bot-channel-wrapper.interface.ts +30 -4
  53. package/src/_modules/bot/_models/bot-message-wrapper.interface.ts +24 -2
  54. package/src/_modules/bot/_models/bot-user-wrapper.interface.ts +8 -2
  55. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.ts +6 -6
  56. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.ts +6 -6
  57. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +9 -9
  58. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +2 -2
@@ -13,14 +13,13 @@ import { DyNTS_OAI_LLM_ServiceBase } from './oai-llm.service-base';
13
13
  import { DyNTS_OAI_global_settings } from '../_collections/oai-global-settings.const';
14
14
  import { DyNTS_AI_LLMChat_ServiceBase } from '../../../_services/ai-llm-chat.service-base';
15
15
  import {
16
- DyFM_AI_ConversationQuestion_Input,
16
+ DyFM_AI_ConversationBase_Input,
17
17
  DyFM_AI_ConversationSelect_Input,
18
18
  DyFM_AI_ConversationGenericSelect_Input,
19
19
  DyFM_AI_ConversationMultiSelect_Input,
20
20
  DyFM_AI_ConversationGenericMultiSelect_Input,
21
21
  DyFM_AI_ConversationJSONKeysDescription_Input,
22
22
  DyFM_AI_ConversationJSONExactKeys_Input,
23
- DyFM_AI_ConversationGetAnswer_Input
24
23
  } from '../../../_models/ai-input-interfaces';
25
24
 
26
25
 
@@ -37,49 +36,46 @@ import {
37
36
  export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase implements DyNTS_AI_LLMChat_ServiceBase {
38
37
 
39
38
  // History management
40
- private conversationHistories: Map<string, DyFM_AI_Message[]> = new Map();
39
+ /* private conversationHistories: Map<string, DyFM_AI_Message[]> = new Map(); */
41
40
 
42
41
  /**
43
42
  * Hozzáad egy üzenetet a conversation history-hoz
44
43
  *
45
44
  * Adds a message to conversation history
46
45
  */
47
- addMessageToHistory(message: DyFM_AI_Message, issuer: string): void {
46
+ /* addMessageToHistory(message: DyFM_AI_Message, issuer: string): void {
48
47
  if (!this.conversationHistories.has(issuer)) {
49
48
  this.conversationHistories.set(issuer, []);
50
49
  }
51
50
  this.conversationHistories.get(issuer).push(message);
52
- }
51
+ } */
53
52
 
54
53
  /**
55
54
  * Törli a conversation history-t
56
55
  *
57
56
  * Clears conversation history
58
57
  */
59
- clearHistory(issuer: string): void {
58
+ /* clearHistory(issuer: string): void {
60
59
  this.conversationHistories.delete(issuer);
61
- }
60
+ } */
62
61
 
63
62
  /**
64
63
  * Visszaadja a conversation history-t
65
64
  *
66
65
  * Gets conversation history
67
66
  */
68
- getHistory(issuer: string): DyFM_AI_Message[] {
67
+ /* getHistory(issuer: string): DyFM_AI_Message[] {
69
68
  return this.conversationHistories.get(issuer) || [];
70
- }
69
+ } */
71
70
 
72
71
  /**
73
72
  * Converts generic AI messages to OpenAI-specific format
74
73
  *
75
74
  * Az generic AI üzeneteket OpenAI-specifikus formátumra alakítja át
76
75
  */
77
- private convertToOAIMessages(messages: DyFM_AI_Message[]): DyFM_AI_Message[] {
78
- return messages.map(msg => ({
79
- role: msg.role as unknown as DyFM_AI_MessageRole,
80
- content: msg.content
81
- }));
82
- }
76
+ /* private convertToOAIMessages(messages: DyFM_AI_Message[]): DyFM_AI_Message[] {
77
+ return messages;
78
+ } */
83
79
 
84
80
  /**
85
81
  * Asks the AI to answer a yes/no question
@@ -87,14 +83,14 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
87
83
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.request} to ask the question,
88
84
  * and the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.upperCaseYes} to check the answer
89
85
  */
90
- async yesNoQuestionInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<boolean> {
91
- set.question += this.predefinedRequests.yesNo.request;
86
+ async requestYesNoInConversation(set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>): Promise<boolean> {
87
+ set.message += this.predefinedRequests.yesNo.request;
92
88
 
93
- this.logQuestion(set);
89
+ //this.logQuestion(set);
94
90
 
95
- const answer = await this.getQuestionAnswerInConversation(set);
91
+ const answer: string = await this.requestSimpleMessageInConversation(set);
96
92
 
97
- return answer.toUpperCase().includes(this.predefinedRequests.yesNo.upperCaseYes);
93
+ return this.convertAnswerToBoolean(answer);
98
94
  }
99
95
  //askYesNoQuestionInConversation: typeof this.yesNoQuestionInConversation = this.yesNoQuestionInConversation;
100
96
 
@@ -103,11 +99,13 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
103
99
  *
104
100
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.simpleQuestion} to ask the question
105
101
  */
106
- async simpleQuestionInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<string> {
102
+ /* async requestSimpleQuestionInConversation(
103
+ set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>
104
+ ): Promise<string> {
107
105
  this.logQuestion(set);
108
106
 
109
107
  return await this.getQuestionAnswerInConversation(set);
110
- }
108
+ } */
111
109
  //askSimpleQuestionInConversation: typeof this.simpleQuestionInConversation = this.simpleQuestionInConversation;
112
110
 
113
111
  /**
@@ -115,23 +113,16 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
115
113
  *
116
114
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.percentageOnly} to ask the question
117
115
  */
118
- async percentageQuestionInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<number> {
119
- set.question += this.predefinedRequests.percentageOnly;
120
-
121
- this.logQuestion(set);
122
-
123
- const answer = await this.getQuestionAnswerInConversation(set);
116
+ async requestPercentageInConversation(
117
+ set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>
118
+ ): Promise<number> {
119
+ set.message += this.predefinedRequests.percentageOnly;
124
120
 
125
- if (isNaN(+answer)) {
126
- DyFM_Log.error('GPT_ServiceBase', 'asykPercentageQuestion', 'Invalid answer', {
127
- question: set.question,
128
- answer,
129
- });
121
+ //this.logQuestion(set);
130
122
 
131
- return null;
132
- }
123
+ const answer: string = await this.requestSimpleMessageInConversation(set);
133
124
 
134
- return +answer;
125
+ return this.convertAnswerToNumber(answer, set.message);
135
126
  }
136
127
  //askPercentageQuestionInConversation: typeof this.percentageQuestionInConversation = this.percentageQuestionInConversation;
137
128
 
@@ -141,25 +132,21 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
141
132
  *
142
133
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
143
134
  */
144
- async selectQuestionInConversation(set: DyFM_AI_ConversationSelect_Input): Promise<string> {
135
+ async requestSelectInConversation<T>(
136
+ set: DyFM_AI_ConversationGenericSelect_Input<T, DyFM_OAI_CallSettings>
137
+ ): Promise<T | { unparsableResult: string }> {
145
138
  // replace the {{DyNTS_selectOptions}} with the list of options
146
139
  const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
147
140
  '{{DyNTS_selectOptions}}',
148
- this.getTextListAsText(set.selectFrom)
141
+ this.getTextListAsText(this.stringifySelectOptions(set.selectFrom))
149
142
  );
150
- set.question += selectQuestionAddition;
143
+ set.message += selectQuestionAddition;
151
144
 
152
- this.logQuestion(set);
145
+ //this.logQuestion(set);
153
146
 
154
- let answer = await this.getQuestionAnswerInConversation(set);
155
-
156
- answer = answer.toLocaleUpperCase();
147
+ const answer = await this.requestSimpleMessageInConversation(set);
157
148
 
158
- for (const item of set.selectFrom) {
159
- if (answer.includes(item.toLocaleUpperCase())) return item;
160
- }
161
-
162
- return null;
149
+ return this.convertAnswerToSelectOption<T>(answer, set.message, set.selectFrom);
163
150
  }
164
151
  //askSelectQuestionInConversation: typeof this.selectQuestionInConversation = this.selectQuestionInConversation;
165
152
 
@@ -170,21 +157,21 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
170
157
  *
171
158
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
172
159
  */
173
- async requestSelectInConversation<T>(
174
- set: DyFM_AI_ConversationGenericSelect_Input<T>
160
+ /* async requestSelectInConversation<T>(
161
+ set: DyFM_AI_ConversationGenericSelect_Input<T, DyFM_OAI_CallSettings>
175
162
  ): Promise<T | { unparsableResult: string }> {
176
163
  const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
177
164
  '{{DyNTS_selectOptions}}',
178
165
  this.getTextListAsText(set.selectFrom.map(item => `"${JSON.stringify(item)}"`))
179
166
  );
180
- set.question += selectQuestionAddition;
167
+ set.message += selectQuestionAddition;
181
168
 
182
169
  this.logQuestion(set);
183
170
 
184
171
  const answer = await this.getQuestionAnswerInConversation(set);
185
172
 
186
173
  return DyFM_Object.safeParseJSON<T>(answer);
187
- }
174
+ } */
188
175
  //askRequestSelectInConversation: typeof this.requestSelectInConversation = this.requestSelectInConversation;
189
176
 
190
177
  /**
@@ -192,12 +179,12 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
192
179
  *
193
180
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
194
181
  */
195
- async multipleSelectQuestionInConversationWithOptions(set: DyFM_AI_ConversationMultiSelect_Input): Promise<string[]> {
182
+ /* async requestMultiselectInConversation(set: DyFM_AI_ConversationMultiSelect_Input): Promise<string[]> {
196
183
  const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
197
184
  '{{DyNTS_selectOptions}}',
198
185
  this.getTextListAsText(set.options)
199
186
  );
200
- set.question += selectQuestionAddition;
187
+ set.message += selectQuestionAddition;
201
188
 
202
189
  let answer = await this.getQuestionAnswerInConversation(set);
203
190
 
@@ -212,7 +199,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
212
199
  }
213
200
 
214
201
  return result;
215
- }
202
+ } */
216
203
  //askMultipleSelectQuestionWithOptionsInConversation: typeof this.multipleSelectQuestionWithOptionsInConversation = this.multipleSelectQuestionWithOptionsInConversation;
217
204
 
218
205
  /**
@@ -223,19 +210,19 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
223
210
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
224
211
  */
225
212
  async requestMultiselectInConversation<T>(
226
- set: DyFM_AI_ConversationGenericMultiSelect_Input<T>
213
+ set: DyFM_AI_ConversationGenericMultiSelect_Input<T, DyFM_OAI_CallSettings>
227
214
  ): Promise<T[]> {
228
215
  const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
229
216
  '{{DyNTS_selectOptions}}',
230
- this.getTextListAsText(set.options.map(item => `"${JSON.stringify(item)}"`))
217
+ this.getTextListAsText(this.stringifySelectOptions(set.options))
231
218
  );
232
- set.question += selectQuestionAddition;
219
+ set.message += selectQuestionAddition;
233
220
 
234
- this.logQuestion(set);
221
+ //this.logQuestion(set);
235
222
 
236
- const answer = await this.getQuestionAnswerInConversation(set);
223
+ const answer = await this.requestSimpleMessageInConversation(set);
237
224
 
238
- return DyFM_Object.safeParseList<T[]>(answer);
225
+ return this.convertAnswerToList<T>(answer, set.message);
239
226
  }
240
227
  //askRequestMultipleSelectInConversation: typeof this.requestMultipleSelectInConversation = this.requestMultipleSelectInConversation;
241
228
 
@@ -248,14 +235,16 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
248
235
  *
249
236
  * (uses {@link DyFM_safeParseJSON})
250
237
  */
251
- async jsonQuestionInConversation<T = any>(set: DyFM_AI_ConversationQuestion_Input): Promise<T | { unparsableResult: string }> {
252
- set.question += this.predefinedRequests.jsonRequest;
238
+ async requestJSONInConversation<T = any>(
239
+ set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>
240
+ ): Promise<T | { unparsableResult: string }> {
241
+ set.message += this.predefinedRequests.jsonRequest;
253
242
 
254
- this.logQuestion(set);
243
+ //this.logQuestion(set);
255
244
 
256
- const answer = await this.getQuestionAnswerInConversation(set);
245
+ const answer = await this.requestSimpleMessageInConversation(set);
257
246
 
258
- return DyFM_Object.safeParseJSON<T>(answer);
247
+ return this.convertAnswerToJSON<T>(answer, set.message);
259
248
  }
260
249
  //askJsonQuestionInConversation: typeof this.jsonQuestionInConversation = this.jsonQuestionInConversation;
261
250
 
@@ -268,9 +257,11 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
268
257
  *
269
258
  * (uses {@link DyFM_safeParseJSON})
270
259
  */
271
- async JSONQuestionInConversationWithKeysDescription(set: DyFM_AI_ConversationJSONKeysDescription_Input): Promise<object> {
260
+ /* async requestJSONInConversationWithKeysDescription<T = any>(
261
+ set: DyFM_AI_ConversationJSONKeysDescription_Input<DyFM_OAI_CallSettings>
262
+ ): Promise<T | { unparsableResult: string }> {
272
263
  return this.jsonQuestionWithKeysDescriptionInConversation<any>(set);
273
- }
264
+ } */
274
265
 
275
266
  /**
276
267
  * Asks the AI to answer a question that must result a JSON object with specific key descriptions
@@ -281,20 +272,20 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
281
272
  *
282
273
  * (uses {@link DyFM_safeParseJSON})
283
274
  */
284
- async jsonQuestionWithKeysDescriptionInConversation<T = any>(
275
+ async requestJSONInConversationWithKeysDescription<T = any>(
285
276
  set: DyFM_AI_ConversationJSONKeysDescription_Input
286
277
  ): Promise<T | { unparsableResult: string }> {
287
278
  const jsonRequestWithKeysDescription = this.predefinedRequests.jsonRequestWithKeysDescription.replace(
288
279
  '{{DyNTS_jsonKeysDescription}}',
289
280
  set.keysDescription
290
281
  );
291
- set.question += jsonRequestWithKeysDescription;
282
+ set.message += jsonRequestWithKeysDescription;
292
283
 
293
- this.logQuestion(set);
284
+ //this.logQuestion(set);
294
285
 
295
- const answer = await this.getQuestionAnswerInConversation(set);
286
+ const answer = await this.requestSimpleMessageInConversation(set);
296
287
 
297
- return DyFM_Object.safeParseJSON<T>(answer);
288
+ return this.convertAnswerToJSON<T>(answer, set.message);
298
289
  }
299
290
  //askJsonQuestionWithKeysDescriptionInConversation: typeof this.jsonQuestionWithKeysDescriptionInConversation = this.jsonQuestionWithKeysDescriptionInConversation;
300
291
 
@@ -307,10 +298,10 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
307
298
  *
308
299
  * (uses {@link DyFM_safeParseJSON})
309
300
  */
310
- async JSONQuestionInConversationWithExactKeys(set: DyFM_AI_ConversationJSONExactKeys_Input): Promise<object> {
301
+ /* async requestJSONInConversationWithExactKeys(set: DyFM_AI_ConversationJSONExactKeys_Input): Promise<object> {
311
302
  const result = await this.jsonQuestionWithExactKeysInConversation<any>(set);
312
303
  return typeof result === 'object' ? result : {};
313
- }
304
+ } */
314
305
 
315
306
  /**
316
307
  * Asks the AI to answer a question that must result a JSON object with specific keys
@@ -321,20 +312,20 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
321
312
  *
322
313
  * (uses {@link DyFM_safeParseJSON})
323
314
  */
324
- async jsonQuestionWithExactKeysInConversation<T = any>(
315
+ async requestJSONInConversationWithExactKeys<T = any>(
325
316
  set: DyFM_AI_ConversationJSONExactKeys_Input
326
317
  ): Promise<T | { unparsableResult: string }> {
327
318
  const jsonRequestWithExactKeys = this.predefinedRequests.jsonRequestWithExactKeys.replace(
328
319
  '{{DyNTS_jsonKeys}}',
329
320
  this.getTextListAsText(set.keys)
330
321
  );
331
- set.question += jsonRequestWithExactKeys;
322
+ set.message += jsonRequestWithExactKeys;
332
323
 
333
- this.logQuestion(set);
324
+ //this.logQuestion(set);
334
325
 
335
- const answer = await this.getQuestionAnswerInConversation(set);
326
+ const answer = await this.requestSimpleMessageInConversation(set);
336
327
 
337
- return DyFM_Object.safeParseJSON<T>(answer);
328
+ return this.convertAnswerToJSON<T>(answer, set.message);
338
329
  }
339
330
  //askJsonQuestionWithExactKeysInConversation: typeof this.jsonQuestionWithExactKeysInConversation = this.jsonQuestionWithExactKeysInConversation;
340
331
 
@@ -347,14 +338,14 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
347
338
  *
348
339
  * (uses {@link DyFM_Object.safeParseList})
349
340
  */
350
- async listQuestionInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<string[]> {
351
- set.question += this.predefinedRequests.listRequest;
341
+ async requestListInConversation<T = any>(set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>): Promise<T[]> {
342
+ set.message += this.predefinedRequests.listRequest;
352
343
 
353
- this.logQuestion(set);
344
+ //this.logQuestion(set);
354
345
 
355
- const answer = await this.getQuestionAnswerInConversation(set);
346
+ const answer = await this.requestSimpleMessageInConversation(set);
356
347
 
357
- return DyFM_Object.safeParseList(answer);
348
+ return this.convertAnswerToList<T>(answer, set.message);
358
349
  }
359
350
  //askListQuestionInConversation: typeof this.listQuestionInConversation = this.listQuestionInConversation;
360
351
 
@@ -384,12 +375,12 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
384
375
  return answer;
385
376
  } */
386
377
 
387
- async getQuestionAnswerInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<string> {
378
+ /* async requestSimpleQuestionInConversation(set: DyFM_AI_ConversationMessage_Input): Promise<string> {
388
379
  return await this.getAnswerInConversation({
389
380
  ...set,
390
- newMessage: set.question,
381
+ newMessage: set.message,
391
382
  });
392
- }
383
+ } */
393
384
  /* getQuestionAnswerInConversation = this.getAnswerInConversation; */
394
385
  //getQuestionInConversation: typeof this.getQuestionAnswerInConversation = this.getQuestionAnswerInConversation;
395
386
  //askQuestionInConversation: typeof this.getQuestionAnswerInConversation = this.getQuestionAnswerInConversation;
@@ -402,42 +393,40 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
402
393
  *
403
394
  * Uses the {@link resolveConversation}
404
395
  */
405
- async getAnswerInConversation(set: DyFM_AI_ConversationGetAnswer_Input): Promise<string> {
396
+ async requestSimpleMessageInConversation(set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>): Promise<string> {
406
397
  // Convert generic AI messages to OpenAI-specific format
407
- const oaiConversation = this.convertToOAIMessages(set.conversation);
398
+ //const oaiConversation: DyFM_AI_Message[] = /* this.convertToOAIMessages(set.conversation) */ set.conversation;
408
399
 
409
- if (set.newMessage) {
410
- oaiConversation.push({
400
+ if (set.message) {
401
+ set.conversation.push({
411
402
  role: DyFM_AI_MessageRole.user,
412
- content: set.newMessage,
403
+ content: set.message,
413
404
  });
414
405
  }
415
406
 
416
- const answer: string = await this.resolveConversationMessage({
407
+ const answer: string = await this.resolveConversation({
417
408
  ...set,
418
- conversation: oaiConversation,
419
- });
409
+ getFullResponse: false,
410
+ }) as string;
420
411
 
421
- if (set.debugLog || this.debugLog) {
422
- console.log(' - answer: ', answer);
423
- }
412
+ this.logAnswer(answer);
424
413
 
425
414
  return answer;
426
415
  }
427
416
 
428
- async resolveConversationMessage(
417
+ /* async resolveConversationMessage(
429
418
  set: {
430
419
  conversation: DyFM_AI_Message[],
431
420
  issuer: string,
432
421
  settings?: DyFM_OAI_CallSettings,
433
422
  getFullResponse?: boolean,
434
423
  debugLog?: boolean,
435
- /** this is used to readably replace too long contents to eg '...' in logs */
424
+ * this is used to readably replace too long contents to eg '...' in logs
436
425
  replaceThisInLog?: string,
437
426
  }
438
427
  ): Promise<string> {
439
428
  return await this.resolveConversation(set) as string;
440
- }
429
+ } */
441
430
 
442
431
  /**
443
432
  * Resolves a conversation
@@ -445,15 +434,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
445
434
  * Uses the {@link getMessageCreateInput}
446
435
  */
447
436
  async resolveConversation(
448
- set: {
449
- conversation: DyFM_AI_Message[],
450
- issuer: string,
451
- settings?: DyFM_OAI_CallSettings,
452
- getFullResponse?: boolean,
453
- debugLog?: boolean,
454
- /** this is used to readably replace too long contents to eg '...' in logs */
455
- replaceThisInLog?: string,
456
- }
437
+ set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>
457
438
  ): Promise<string | ChatCompletion> {
458
439
  try {
459
440
  if (set.conversation.find(message => message.role === DyFM_AI_MessageRole.system)) {
@@ -476,6 +457,8 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
476
457
  const shortenedConversation = this.shortenConversation(set);
477
458
 
478
459
  this.validateConversation(shortenedConversation);
460
+
461
+ //this.logQuestion(set);
479
462
 
480
463
  this.logConversation({
481
464
  ...set,
@@ -505,11 +488,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
505
488
  //resolveSimpleUserMessageInConversation: typeof this.resolveConversation = this.resolveConversation;
506
489
 
507
490
  protected shortenConversation(
508
- set: {
509
- conversation: DyFM_AI_Message[],
510
- issuer: string,
511
- debugLog?: boolean,
512
- }
491
+ set: DyFM_AI_ConversationBase_Input<DyFM_OAI_CallSettings>
513
492
  ): DyFM_AI_Message[] {
514
493
  try {
515
494
  const clonedConversation = DyFM_Object.clone(set.conversation);
@@ -522,7 +501,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
522
501
  ).map(message => message.content);
523
502
  let stringifiedMessages = JSON.stringify(msgs);
524
503
 
525
- if (this.debugLog) {
504
+ if (this._debugLog) {
526
505
  DyFM_Log.info(
527
506
  ' DyNTS_OAI_LLMChat_ServiceBase: before shortening conversation', {
528
507
  stringifiedMessagesLength: stringifiedMessages.length,
@@ -546,7 +525,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
546
525
  lastStringifiedMessagesLength = stringifiedMessages.length;
547
526
  }
548
527
 
549
- if (this.debugLog || set.debugLog) {
528
+ if (this._debugLog || set.debugLog) {
550
529
  DyFM_Log.info(
551
530
  ' DyNTS_OAI_LLMChat_ServiceBase: after shortening conversation', {
552
531
  removedMessagesCount: removedMessagesCount,
@@ -578,31 +557,12 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
578
557
  }
579
558
  }
580
559
 
581
- protected logConversation(
582
- set: {
583
- conversation: DyFM_AI_Message[],
584
- debugLog?: boolean,
585
- /** this is used to readably replace too long contents to eg '...' in logs */
586
- replaceThisInLog?: string,
587
- }
588
- ) {
589
- if (set.debugLog || this.debugLog) {
590
- DyFM_Log.info('Conversation log at', DyFM_getLocalStackLocation());
591
-
592
- set.conversation.forEach(message => {
593
- console.log(
594
- ` - ${message.role}: ${message.content.replace(set.replaceThisInLog, this.defaultLogReplacer)}`
595
- );
596
- });
597
- }
598
- }
599
-
600
560
  /**
601
561
  * Kérdez egy kérdést és JSON választ vár exact keys-szel
602
562
  *
603
563
  * Asks a question and expects JSON response with exact keys
604
564
  */
605
- async requestJSONInConversationWithExactKeys<T>(
565
+ /* async requestJSONInConversationWithExactKeys<T>(
606
566
  set: DyFM_AI_ConversationJSONExactKeys_Input
607
567
  ): Promise<T> {
608
568
  const answer = await this.jsonQuestionWithExactKeysInConversation<any>(set);
@@ -616,5 +576,5 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase imp
616
576
  }
617
577
 
618
578
  return answer as T;
619
- }
579
+ } */
620
580
  }