@futdevpro/nts-dynamo 1.14.27 → 1.14.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/build/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.d.ts +0 -17
  2. package/build/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.d.ts.map +1 -1
  3. package/build/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.js +42 -39
  4. package/build/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.js.map +1 -1
  5. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.d.ts +0 -5
  6. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.d.ts.map +1 -1
  7. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js +6 -2
  8. package/build/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js.map +1 -1
  9. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.d.ts +22 -0
  10. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.d.ts.map +1 -0
  11. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.js +187 -0
  12. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-chunk-data.service.js.map +1 -0
  13. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.d.ts +27 -0
  14. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.d.ts.map +1 -0
  15. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.js +277 -0
  16. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-doc-page.data-service.js.map +1 -0
  17. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.d.ts +23 -0
  18. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.d.ts.map +1 -0
  19. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.js +319 -0
  20. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.js.map +1 -0
  21. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.d.ts +118 -0
  22. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.d.ts.map +1 -0
  23. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.js +460 -0
  24. package/build/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.js.map +1 -0
  25. package/build/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.d.ts +9 -1
  26. package/build/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.d.ts.map +1 -1
  27. package/build/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.js +14 -1
  28. package/build/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.js.map +1 -1
  29. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +73 -130
  30. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts.map +1 -1
  31. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.js +97 -12
  32. package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.js.map +1 -1
  33. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.d.ts +65 -7
  34. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.d.ts.map +1 -1
  35. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.js +192 -6
  36. package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.js.map +1 -1
  37. package/build/_modules/ai/_modules/open-ai/index.d.ts +4 -6
  38. package/build/_modules/ai/_modules/open-ai/index.d.ts.map +1 -1
  39. package/build/_modules/ai/_modules/open-ai/index.js +8 -7
  40. package/build/_modules/ai/_modules/open-ai/index.js.map +1 -1
  41. package/build/_modules/bot/_enums/bot-message-provider.enum.d.ts +1 -1
  42. package/build/_modules/bot/_enums/bot-message-provider.enum.d.ts.map +1 -1
  43. package/build/_modules/bot/_enums/bot-message-provider.enum.js +9 -9
  44. package/build/_modules/bot/_enums/bot-message-provider.enum.js.map +1 -1
  45. package/build/_modules/bot/_models/bot-message-wrapper.interface.d.ts +2 -2
  46. package/build/_modules/bot/_models/bot-message-wrapper.interface.d.ts.map +1 -1
  47. package/build/_modules/bot/_models/bot-messaging-provider.interface.d.ts +2 -2
  48. package/build/_modules/bot/_models/bot-messaging-provider.interface.d.ts.map +1 -1
  49. package/build/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.service.js +1 -1
  50. package/build/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.service.js.map +1 -1
  51. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.service.js +1 -1
  52. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.service.js.map +1 -1
  53. package/build/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.service.js +1 -1
  54. package/build/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.service.js.map +1 -1
  55. package/build/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.service.js +1 -1
  56. package/build/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.service.js.map +1 -1
  57. package/build/_modules/bot/_services/bot-messaging-provider-factory.service.js +5 -5
  58. package/build/_modules/bot/_services/bot-messaging-provider-factory.service.js.map +1 -1
  59. package/build/_modules/discord-assistant/_collections/dias.util.d.ts +3 -3
  60. package/build/_modules/discord-assistant/_collections/dias.util.d.ts.map +1 -1
  61. package/build/_modules/discord-assistant/_collections/dias.util.js +4 -4
  62. package/build/_modules/discord-assistant/_collections/dias.util.js.map +1 -1
  63. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts +5 -5
  64. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts.map +1 -1
  65. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +1 -1
  66. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -1
  67. package/build/_modules/discord-assistant/_services/dias.service-base.d.ts +2 -2
  68. package/build/_modules/discord-assistant/_services/dias.service-base.d.ts.map +1 -1
  69. package/build/_modules/discord-assistant/_services/dias.service-base.js.map +1 -1
  70. package/package.json +1 -1
  71. package/src/_modules/ai/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +42 -42
  72. package/src/_modules/ai/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +6 -6
  73. package/src/_modules/ai/_modules/open-ai/_services/{oai-doc-chunk-data.service.ts → data-services/oai-doc-chunk-data.service.ts} +8 -8
  74. package/src/_modules/ai/_modules/open-ai/_services/{oai-doc-page.data-service.ts → data-services/oai-doc-page.data-service.ts} +8 -8
  75. package/src/_modules/ai/_modules/open-ai/_services/{oai-document.data-service.ts → data-services/oai-document.data-service.ts} +7 -7
  76. package/src/_modules/ai/_modules/open-ai/_services/{oai-vector-data.service.ts → data-services/oai-vector-data.service.ts} +4 -4
  77. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.ts +18 -2
  78. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +138 -159
  79. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +247 -13
  80. package/src/_modules/ai/_modules/open-ai/index.ts +8 -7
  81. package/src/_modules/bot/_enums/bot-message-provider.enum.ts +1 -1
  82. package/src/_modules/bot/_models/bot-message-wrapper.interface.ts +4 -3
  83. package/src/_modules/bot/_models/bot-messaging-provider.interface.ts +2 -2
  84. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.service.ts +2 -2
  85. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.service.ts +2 -2
  86. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.service.ts +2 -2
  87. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.service.ts +2 -2
  88. package/src/_modules/bot/_services/bot-messaging-provider-factory.service.ts +6 -6
  89. package/src/_modules/discord-assistant/_collections/dias.util.ts +6 -7
  90. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +6 -6
  91. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +2 -2
  92. package/src/_modules/discord-assistant/_services/dias.service-base.ts +2 -3
  93. package/build/_modules/ai/_services/oai-to-ai-adapter.service.d.ts +0 -39
  94. package/build/_modules/ai/_services/oai-to-ai-adapter.service.d.ts.map +0 -1
  95. package/build/_modules/ai/_services/oai-to-ai-adapter.service.js +0 -218
  96. package/build/_modules/ai/_services/oai-to-ai-adapter.service.js.map +0 -1
  97. package/build/_modules/bot/_enums/bot-provider.enum.d.ts +0 -8
  98. package/build/_modules/bot/_enums/bot-provider.enum.d.ts.map +0 -1
  99. package/build/_modules/bot/_enums/bot-provider.enum.js +0 -12
  100. package/build/_modules/bot/_enums/bot-provider.enum.js.map +0 -1
  101. package/build/_modules/bot/_models/bot-provider.interface.d.ts +0 -65
  102. package/build/_modules/bot/_models/bot-provider.interface.d.ts.map +0 -1
  103. package/build/_modules/bot/_models/bot-provider.interface.js +0 -3
  104. package/build/_modules/bot/_models/bot-provider.interface.js.map +0 -1
  105. package/build/_modules/bot/_modules/discord-bot/_services/dib-provider.service.d.ts +0 -53
  106. package/build/_modules/bot/_modules/discord-bot/_services/dib-provider.service.d.ts.map +0 -1
  107. package/build/_modules/bot/_modules/discord-bot/_services/dib-provider.service.js +0 -369
  108. package/build/_modules/bot/_modules/discord-bot/_services/dib-provider.service.js.map +0 -1
  109. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.d.ts +0 -54
  110. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.d.ts.map +0 -1
  111. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.js +0 -310
  112. package/build/_modules/bot/_modules/dynamo-bot/_services/dyb-provider.service.js.map +0 -1
  113. package/build/_modules/bot/_modules/slack-bot/_services/slb-provider.service.d.ts +0 -40
  114. package/build/_modules/bot/_modules/slack-bot/_services/slb-provider.service.d.ts.map +0 -1
  115. package/build/_modules/bot/_modules/slack-bot/_services/slb-provider.service.js +0 -116
  116. package/build/_modules/bot/_modules/slack-bot/_services/slb-provider.service.js.map +0 -1
  117. package/build/_modules/bot/_modules/teams-bot/_services/teb-provider.service.d.ts +0 -40
  118. package/build/_modules/bot/_modules/teams-bot/_services/teb-provider.service.d.ts.map +0 -1
  119. package/build/_modules/bot/_modules/teams-bot/_services/teb-provider.service.js +0 -116
  120. package/build/_modules/bot/_modules/teams-bot/_services/teb-provider.service.js.map +0 -1
  121. package/build/_modules/bot/_services/bot-provider-factory.service.d.ts +0 -5
  122. package/build/_modules/bot/_services/bot-provider-factory.service.d.ts.map +0 -1
  123. package/build/_modules/bot/_services/bot-provider-factory.service.js +0 -31
  124. package/build/_modules/bot/_services/bot-provider-factory.service.js.map +0 -1
@@ -1,14 +1,14 @@
1
1
  import { DyFM_Array, DyFM_Async, DyFM_DataModel_Params, DyFM_DBFilter, DyFM_DBFilterExpressions, DyFM_DBFilterSimple, DyFM_Error, DyFM_Log } from '@futdevpro/fsm-dynamo';
2
- import { DyNTS_DataService } from '../../../../../_services/base/data.service';
3
- import { DyNTS_DAI_DocChunk } from '../../document-ai/_models/data-models/dai-doc-chunk.data-model';
4
- import { DyNTS_DAI_DocPage } from '../../document-ai/_models/data-models/dai-doc-page.data-model';
5
- import { DyNTS_DAI_Document, DyNTS_DAI_document_dataParams } from '../../document-ai/_models/data-models/dai-document.data-model';
2
+ import { DyNTS_DataService } from '../../../../../../_services/base/data.service';
3
+ import { DyNTS_DAI_DocChunk } from '../../../document-ai/_models/data-models/dai-doc-chunk.data-model';
4
+ import { DyNTS_DAI_DocPage } from '../../../document-ai/_models/data-models/dai-doc-page.data-model';
5
+ import { DyNTS_DAI_Document, DyNTS_DAI_document_dataParams } from '../../../document-ai/_models/data-models/dai-document.data-model';
6
6
  import { DyNTS_OAI_DocChunkDataService } from './oai-doc-chunk-data.service';
7
7
  import { DyNTS_OAI_DocPageDataService } from './oai-doc-page.data-service';
8
8
  import { DyFM_OAI_Settings } from '@futdevpro/fsm-dynamo/ai/open-ai';
9
- import { DyNTS_DAI_DocumentCompareResult } from '../../document-ai/_models/interfaces/dai-document-compare-result.interface';
10
- import { DyNTS_DAI_DocPageCompareResult } from '../../document-ai/_models/interfaces/dai-doc-page-compare-result.interface';
11
- import { DyNTS_DAI_CompareResult_Type } from '../../document-ai/_enums/dai-compare-result-type.enum';
9
+ import { DyNTS_DAI_DocumentCompareResult } from '../../../document-ai/_models/interfaces/dai-document-compare-result.interface';
10
+ import { DyNTS_DAI_DocPageCompareResult } from '../../../document-ai/_models/interfaces/dai-doc-page-compare-result.interface';
11
+ import { DyNTS_DAI_CompareResult_Type } from '../../../document-ai/_enums/dai-compare-result-type.enum';
12
12
 
13
13
 
14
14
  export class DyNTS_OAI_DocumentDataService<
@@ -11,10 +11,10 @@ import {
11
11
  } from '@futdevpro/fsm-dynamo';
12
12
  import { DyFM_OAI_Settings, DyFM_OAI_EmbeddingModel, DyFM_OAI_Model } from '@futdevpro/fsm-dynamo/ai/open-ai';
13
13
 
14
- import { DyNTS_global_settings } from '../../../../../_collections/global-settings.const';
15
- import { DyNTS_DataService } from '../../../../../_services/base/data.service';
16
- import { DyNTS_OAI_Embedding_ControlService } from './oai-embedding.control-service';
17
- import { DyNTS_OAI_global_settings } from '../_collections/oai-global-settings.const';
14
+ import { DyNTS_global_settings } from '../../../../../../_collections/global-settings.const';
15
+ import { DyNTS_DataService } from '../../../../../../_services/base/data.service';
16
+ import { DyNTS_OAI_Embedding_ControlService } from '../oai-embedding.control-service';
17
+ import { DyNTS_OAI_global_settings } from '../../_collections/oai-global-settings.const';
18
18
 
19
19
  /**
20
20
  * Vector Data Service that is connected to the relevant DBServices
@@ -1,11 +1,13 @@
1
- import { DyFM_OAI_Model } from '@futdevpro/fsm-dynamo/ai/open-ai';
1
+ import { DyFM_OAI_Model, DyFM_OAI_EmbeddingModelDimensions } from '@futdevpro/fsm-dynamo/ai/open-ai';
2
2
  import { DyFM_Error } from '@futdevpro/fsm-dynamo';
3
+ import { DyFM_AI_Provider } from '@futdevpro/fsm-dynamo/ai';
4
+ import { DyFM_DAI_EmbeddingInfo } from '@futdevpro/fsm-dynamo/ai/document-ai';
3
5
 
4
6
  import { DyNTS_OAI_LLM_ServiceBase } from './oai-llm.service-base';
5
7
  import { DyNTS_global_settings } from '../../../../../_collections/global-settings.const';
6
8
  import { DyNTS_AI_Embedding_ServiceBase } from '../../../_services/ai-embedding.service-base';
7
9
 
8
- export class DyNTS_OAI_Embedding_ControlService extends DyNTS_OAI_LLM_ServiceBase /* implements DyNTS_AI_Embedding_ServiceBase */ {
10
+ export class DyNTS_OAI_Embedding_ControlService extends DyNTS_OAI_LLM_ServiceBase implements DyNTS_AI_Embedding_ServiceBase {
9
11
 
10
12
  async createEmbedding(
11
13
  text: string,
@@ -64,4 +66,18 @@ export class DyNTS_OAI_Embedding_ControlService extends DyNTS_OAI_LLM_ServiceBas
64
66
  });
65
67
  }
66
68
  }
69
+
70
+ /**
71
+ * Visszaadja az embedding model információkat
72
+ *
73
+ * Returns embedding model information
74
+ */
75
+ getEmbeddingInfo(model: string): DyFM_DAI_EmbeddingInfo {
76
+ const dimensions = DyFM_OAI_EmbeddingModelDimensions[model as keyof typeof DyFM_OAI_EmbeddingModelDimensions];
77
+
78
+ return {
79
+ provider: DyFM_AI_Provider.OpenAI,
80
+ model: model
81
+ };
82
+ }
67
83
  }
@@ -2,16 +2,26 @@ import { OpenAI } from 'openai';
2
2
 
3
3
  import { DyFM_OAI_Settings, DyFM_OAI_Model, DyFM_OAI_CallSettings } from '@futdevpro/fsm-dynamo/ai/open-ai';
4
4
  import { DyFM_AnyError, DyFM_Error, DyFM_Error_Settings, DyFM_getLocalStackLocation, DyFM_Log, DyFM_notNull, DyFM_Object, DyFM_Array } from '@futdevpro/fsm-dynamo';
5
+ import { DyFM_AI_Message } from '@futdevpro/fsm-dynamo/ai';
5
6
 
6
7
  import { DyNTS_global_settings } from '../../../../../_collections/global-settings.const';
7
- import { DyNTS_OAI_GPT_Message } from '../_models/interfaces/oai-gpt-message.interface';
8
8
  import { ChatCompletion } from 'openai/resources';
9
9
  import { ChatCompletionCreateParamsBase, ChatCompletionMessageParam } from 'openai/resources/chat/completions';
10
- import { DyNTS_OAI_GPT_Message_Role } from '../_enums/oai-gpt-message-role.enum';
10
+ import { DyFM_AI_MessageRole } from '@futdevpro/fsm-dynamo/ai';
11
11
  import { DyNTS_OAI_LLM_Predefined_Requests } from '../_models/interfaces/oai-llm-predefined-requests.interface';
12
12
  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
+ import {
16
+ DyFM_AI_ConversationQuestion_Input,
17
+ DyFM_AI_ConversationSelect_Input,
18
+ DyFM_AI_ConversationGenericSelect_Input,
19
+ DyFM_AI_ConversationMultiSelect_Input,
20
+ DyFM_AI_ConversationGenericMultiSelect_Input,
21
+ DyFM_AI_ConversationJSONKeysDescription_Input,
22
+ DyFM_AI_ConversationJSONExactKeys_Input,
23
+ DyFM_AI_ConversationGetAnswer_Input
24
+ } from '../../../_models/ai-input-interfaces';
15
25
 
16
26
 
17
27
  /**
@@ -24,25 +34,60 @@ import { DyNTS_AI_LLMChat_ServiceBase } from '../../../_services/ai-llm-chat.ser
24
34
 
25
35
  // Di Dictionary DiModel DiEz DiAz
26
36
 
27
- export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /* implements DyNTS_AI_LLMChat_ServiceBase */ {
37
+ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase implements DyNTS_AI_LLMChat_ServiceBase {
28
38
 
39
+ // History management
40
+ private conversationHistories: Map<string, DyFM_AI_Message[]> = new Map();
41
+
42
+ /**
43
+ * Hozzáad egy üzenetet a conversation history-hoz
44
+ *
45
+ * Adds a message to conversation history
46
+ */
47
+ addMessageToHistory(message: DyFM_AI_Message, issuer: string): void {
48
+ if (!this.conversationHistories.has(issuer)) {
49
+ this.conversationHistories.set(issuer, []);
50
+ }
51
+ this.conversationHistories.get(issuer).push(message);
52
+ }
53
+
54
+ /**
55
+ * Törli a conversation history-t
56
+ *
57
+ * Clears conversation history
58
+ */
59
+ clearHistory(issuer: string): void {
60
+ this.conversationHistories.delete(issuer);
61
+ }
62
+
63
+ /**
64
+ * Visszaadja a conversation history-t
65
+ *
66
+ * Gets conversation history
67
+ */
68
+ getHistory(issuer: string): DyFM_AI_Message[] {
69
+ return this.conversationHistories.get(issuer) || [];
70
+ }
71
+
72
+ /**
73
+ * Converts generic AI messages to OpenAI-specific format
74
+ *
75
+ * Az generic AI üzeneteket OpenAI-specifikus formátumra alakítja át
76
+ */
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
+ }
83
+
29
84
  /**
30
85
  * Asks the AI to answer a yes/no question
31
86
  *
32
87
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.request} to ask the question,
33
88
  * and the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.upperCaseYes} to check the answer
34
89
  */
35
- async yesNoQuestionInConversation(
36
- set: {
37
- conversation: DyNTS_OAI_GPT_Message[],
38
- question: string,
39
- issuer: string,
40
- settings?: DyFM_OAI_CallSettings,
41
- debugLog?: boolean,
42
- /** this is used to readably replace too long contents to eg '...' in logs */
43
- replaceThisInLog?: string,
44
- }
45
- ): Promise<boolean> {
90
+ async yesNoQuestionInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<boolean> {
46
91
  set.question += this.predefinedRequests.yesNo.request;
47
92
 
48
93
  this.logQuestion(set);
@@ -58,17 +103,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
58
103
  *
59
104
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.simpleQuestion} to ask the question
60
105
  */
61
- async simpleQuestionInConversation(
62
- set: {
63
- conversation: DyNTS_OAI_GPT_Message[],
64
- question: string,
65
- issuer: string,
66
- settings?: DyFM_OAI_CallSettings,
67
- debugLog?: boolean,
68
- /** this is used to readably replace too long contents to eg '...' in logs */
69
- replaceThisInLog?: string,
70
- }
71
- ): Promise<string> {
106
+ async simpleQuestionInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<string> {
72
107
  this.logQuestion(set);
73
108
 
74
109
  return await this.getQuestionAnswerInConversation(set);
@@ -80,17 +115,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
80
115
  *
81
116
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.percentageOnly} to ask the question
82
117
  */
83
- async percentageQuestionInConversation(
84
- set: {
85
- conversation: DyNTS_OAI_GPT_Message[],
86
- question: string,
87
- issuer: string,
88
- settings?: DyFM_OAI_CallSettings,
89
- debugLog?: boolean,
90
- /** this is used to readably replace too long contents to eg '...' in logs */
91
- replaceThisInLog?: string,
92
- }
93
- ): Promise<number> {
118
+ async percentageQuestionInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<number> {
94
119
  set.question += this.predefinedRequests.percentageOnly;
95
120
 
96
121
  this.logQuestion(set);
@@ -116,18 +141,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
116
141
  *
117
142
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
118
143
  */
119
- async selectQuestionInConversation(
120
- set: {
121
- conversation: DyNTS_OAI_GPT_Message[],
122
- question: string,
123
- selectFrom: string[],
124
- issuer: string,
125
- settings?: DyFM_OAI_CallSettings,
126
- debugLog?: boolean,
127
- /** this is used to readably replace too long contents to eg '...' in logs */
128
- replaceThisInLog?: string,
129
- }
130
- ): Promise<string> {
144
+ async selectQuestionInConversation(set: DyFM_AI_ConversationSelect_Input): Promise<string> {
131
145
  // replace the {{DyNTS_selectOptions}} with the list of options
132
146
  const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
133
147
  '{{DyNTS_selectOptions}}',
@@ -157,16 +171,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
157
171
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
158
172
  */
159
173
  async requestSelectInConversation<T>(
160
- set: {
161
- conversation: DyNTS_OAI_GPT_Message[],
162
- question: string,
163
- selectFrom: T[],
164
- issuer: string,
165
- settings?: DyFM_OAI_CallSettings,
166
- debugLog?: boolean,
167
- /** this is used to readably replace too long contents to eg '...' in logs */
168
- replaceThisInLog?: string,
169
- }
174
+ set: DyFM_AI_ConversationGenericSelect_Input<T>
170
175
  ): Promise<T | { unparsableResult: string }> {
171
176
  const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
172
177
  '{{DyNTS_selectOptions}}',
@@ -187,18 +192,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
187
192
  *
188
193
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
189
194
  */
190
- async multipleSelectQuestionWithOptionsInConversation(
191
- set: {
192
- conversation: DyNTS_OAI_GPT_Message[],
193
- question: string,
194
- options: string[],
195
- issuer: string,
196
- settings?: DyFM_OAI_CallSettings,
197
- debugLog?: boolean,
198
- /** this is used to readably replace too long contents to eg '...' in logs */
199
- replaceThisInLog?: string,
200
- }
201
- ): Promise<string[]> {
195
+ async multipleSelectQuestionInConversationWithOptions(set: DyFM_AI_ConversationMultiSelect_Input): Promise<string[]> {
202
196
  const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
203
197
  '{{DyNTS_selectOptions}}',
204
198
  this.getTextListAsText(set.options)
@@ -228,17 +222,8 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
228
222
  *
229
223
  * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
230
224
  */
231
- async requestMultipleSelectInConversation<T>(
232
- set: {
233
- conversation: DyNTS_OAI_GPT_Message[],
234
- question: string,
235
- options: T[],
236
- issuer: string,
237
- settings?: DyFM_OAI_CallSettings,
238
- debugLog?: boolean,
239
- /** this is used to readably replace too long contents to eg '...' in logs */
240
- replaceThisInLog?: string,
241
- }
225
+ async requestMultiselectInConversation<T>(
226
+ set: DyFM_AI_ConversationGenericMultiSelect_Input<T>
242
227
  ): Promise<T[]> {
243
228
  const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
244
229
  '{{DyNTS_selectOptions}}',
@@ -263,17 +248,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
263
248
  *
264
249
  * (uses {@link DyFM_safeParseJSON})
265
250
  */
266
- async jsonQuestionInConversation<T = any>(
267
- set: {
268
- conversation: DyNTS_OAI_GPT_Message[],
269
- question: string,
270
- issuer: string,
271
- settings?: DyFM_OAI_CallSettings,
272
- debugLog?: boolean,
273
- /** this is used to readably replace too long contents to eg '...' in logs */
274
- replaceThisInLog?: string,
275
- }
276
- ): Promise<T | { unparsableResult: string }> {
251
+ async jsonQuestionInConversation<T = any>(set: DyFM_AI_ConversationQuestion_Input): Promise<T | { unparsableResult: string }> {
277
252
  set.question += this.predefinedRequests.jsonRequest;
278
253
 
279
254
  this.logQuestion(set);
@@ -284,6 +259,19 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
284
259
  }
285
260
  //askJsonQuestionInConversation: typeof this.jsonQuestionInConversation = this.jsonQuestionInConversation;
286
261
 
262
+ /**
263
+ * Asks the AI to answer a question that must result a JSON object with specific key descriptions
264
+ *
265
+ * If the answer is not a valid JSON object, it will return { unparsableResult: answer }
266
+ *
267
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.jsonRequestWithKeysDescription} to ask the question
268
+ *
269
+ * (uses {@link DyFM_safeParseJSON})
270
+ */
271
+ async JSONQuestionInConversationWithKeysDescription(set: DyFM_AI_ConversationJSONKeysDescription_Input): Promise<object> {
272
+ return this.jsonQuestionWithKeysDescriptionInConversation<any>(set);
273
+ }
274
+
287
275
  /**
288
276
  * Asks the AI to answer a question that must result a JSON object with specific key descriptions
289
277
  *
@@ -294,16 +282,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
294
282
  * (uses {@link DyFM_safeParseJSON})
295
283
  */
296
284
  async jsonQuestionWithKeysDescriptionInConversation<T = any>(
297
- set: {
298
- conversation: DyNTS_OAI_GPT_Message[],
299
- question: string,
300
- keysDescription: string,
301
- issuer: string,
302
- settings?: DyFM_OAI_CallSettings,
303
- debugLog?: boolean,
304
- /** this is used to readably replace too long contents to eg '...' in logs */
305
- replaceThisInLog?: string,
306
- }
285
+ set: DyFM_AI_ConversationJSONKeysDescription_Input
307
286
  ): Promise<T | { unparsableResult: string }> {
308
287
  const jsonRequestWithKeysDescription = this.predefinedRequests.jsonRequestWithKeysDescription.replace(
309
288
  '{{DyNTS_jsonKeysDescription}}',
@@ -319,6 +298,20 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
319
298
  }
320
299
  //askJsonQuestionWithKeysDescriptionInConversation: typeof this.jsonQuestionWithKeysDescriptionInConversation = this.jsonQuestionWithKeysDescriptionInConversation;
321
300
 
301
+ /**
302
+ * Asks the AI to answer a question that must result a JSON object with specific keys
303
+ *
304
+ * If the answer is not a valid JSON object, it will return { unparsableResult: answer }
305
+ *
306
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.jsonRequestWithExactKeys} to ask the question
307
+ *
308
+ * (uses {@link DyFM_safeParseJSON})
309
+ */
310
+ async JSONQuestionInConversationWithExactKeys(set: DyFM_AI_ConversationJSONExactKeys_Input): Promise<object> {
311
+ const result = await this.jsonQuestionWithExactKeysInConversation<any>(set);
312
+ return typeof result === 'object' ? result : {};
313
+ }
314
+
322
315
  /**
323
316
  * Asks the AI to answer a question that must result a JSON object with specific keys
324
317
  *
@@ -329,16 +322,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
329
322
  * (uses {@link DyFM_safeParseJSON})
330
323
  */
331
324
  async jsonQuestionWithExactKeysInConversation<T = any>(
332
- set: {
333
- conversation: DyNTS_OAI_GPT_Message[],
334
- question: string,
335
- keys: string[],
336
- issuer: string,
337
- settings?: DyFM_OAI_CallSettings,
338
- debugLog?: boolean,
339
- /** this is used to readably replace too long contents to eg '...' in logs */
340
- replaceThisInLog?: string,
341
- }
325
+ set: DyFM_AI_ConversationJSONExactKeys_Input
342
326
  ): Promise<T | { unparsableResult: string }> {
343
327
  const jsonRequestWithExactKeys = this.predefinedRequests.jsonRequestWithExactKeys.replace(
344
328
  '{{DyNTS_jsonKeys}}',
@@ -363,17 +347,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
363
347
  *
364
348
  * (uses {@link DyFM_Object.safeParseList})
365
349
  */
366
- async listQuestionInConversation(
367
- set: {
368
- conversation: DyNTS_OAI_GPT_Message[],
369
- question: string,
370
- issuer: string,
371
- settings?: DyFM_OAI_CallSettings,
372
- debugLog?: boolean,
373
- /** this is used to readably replace too long contents to eg '...' in logs */
374
- replaceThisInLog?: string,
375
- }
376
- ): Promise<string[]> {
350
+ async listQuestionInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<string[]> {
377
351
  set.question += this.predefinedRequests.listRequest;
378
352
 
379
353
  this.logQuestion(set);
@@ -390,7 +364,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
390
364
  * Uses the {@link resolveSimpleUserMessage}
391
365
  */
392
366
  /* async getQuestionAnswerInConversation(
393
- conversation: DyNTS_OAI_GPT_Message[],
367
+ conversation: DyFM_AI_Message[],
394
368
  question: string,
395
369
  issuer: string,
396
370
  debugLog?: boolean,
@@ -410,17 +384,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
410
384
  return answer;
411
385
  } */
412
386
 
413
- async getQuestionAnswerInConversation(
414
- set: {
415
- conversation: DyNTS_OAI_GPT_Message[],
416
- question?: string,
417
- issuer: string,
418
- settings?: DyFM_OAI_CallSettings,
419
- debugLog?: boolean,
420
- /** this is used to readably replace too long contents to eg '...' in logs */
421
- replaceThisInLog?: string,
422
- }
423
- ): Promise<string> {
387
+ async getQuestionAnswerInConversation(set: DyFM_AI_ConversationQuestion_Input): Promise<string> {
424
388
  return await this.getAnswerInConversation({
425
389
  ...set,
426
390
  newMessage: set.question,
@@ -438,27 +402,21 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
438
402
  *
439
403
  * Uses the {@link resolveConversation}
440
404
  */
441
- async getAnswerInConversation(
442
- set: {
443
- conversation: DyNTS_OAI_GPT_Message[],
444
- newMessage?: string,
445
- issuer: string,
446
- settings?: DyFM_OAI_CallSettings,
447
- debugLog?: boolean,
448
- /** this is used to readably replace too long contents to eg '...' in logs */
449
- replaceThisInLog?: string,
450
- }
451
- ): Promise<string> {
452
- if (set.newMessage) {
453
- set.conversation = DyFM_Object.clone(set.conversation);
405
+ async getAnswerInConversation(set: DyFM_AI_ConversationGetAnswer_Input): Promise<string> {
406
+ // Convert generic AI messages to OpenAI-specific format
407
+ const oaiConversation = this.convertToOAIMessages(set.conversation);
454
408
 
455
- set.conversation.push({
456
- role: DyNTS_OAI_GPT_Message_Role.user,
409
+ if (set.newMessage) {
410
+ oaiConversation.push({
411
+ role: DyFM_AI_MessageRole.user,
457
412
  content: set.newMessage,
458
413
  });
459
414
  }
460
415
 
461
- const answer: string = await this.resolveConversationMessage(set);
416
+ const answer: string = await this.resolveConversationMessage({
417
+ ...set,
418
+ conversation: oaiConversation,
419
+ });
462
420
 
463
421
  if (set.debugLog || this.debugLog) {
464
422
  console.log(' - answer: ', answer);
@@ -469,7 +427,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
469
427
 
470
428
  async resolveConversationMessage(
471
429
  set: {
472
- conversation: DyNTS_OAI_GPT_Message[],
430
+ conversation: DyFM_AI_Message[],
473
431
  issuer: string,
474
432
  settings?: DyFM_OAI_CallSettings,
475
433
  getFullResponse?: boolean,
@@ -488,7 +446,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
488
446
  */
489
447
  async resolveConversation(
490
448
  set: {
491
- conversation: DyNTS_OAI_GPT_Message[],
449
+ conversation: DyFM_AI_Message[],
492
450
  issuer: string,
493
451
  settings?: DyFM_OAI_CallSettings,
494
452
  getFullResponse?: boolean,
@@ -498,7 +456,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
498
456
  }
499
457
  ): Promise<string | ChatCompletion> {
500
458
  try {
501
- if (set.conversation.find(message => message.role === DyNTS_OAI_GPT_Message_Role.system)) {
459
+ if (set.conversation.find(message => message.role === DyFM_AI_MessageRole.system)) {
502
460
  /* throw new DyFM_Error({
503
461
  ...this.getDefaultErrorSettings(
504
462
  'resolveConversation',
@@ -548,19 +506,19 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
548
506
 
549
507
  protected shortenConversation(
550
508
  set: {
551
- conversation: DyNTS_OAI_GPT_Message[],
509
+ conversation: DyFM_AI_Message[],
552
510
  issuer: string,
553
511
  debugLog?: boolean,
554
512
  }
555
- ): DyNTS_OAI_GPT_Message[] {
513
+ ): DyFM_AI_Message[] {
556
514
  try {
557
515
  const clonedConversation = DyFM_Object.clone(set.conversation);
558
516
  const systemMessages = clonedConversation.filter(
559
- message => message.role === DyNTS_OAI_GPT_Message_Role.system
517
+ message => message.role === DyFM_AI_MessageRole.system
560
518
  );
561
519
  const systemMessagesStringLength = JSON.stringify(systemMessages).length;
562
520
  const msgs: string[] = clonedConversation.filter(
563
- message => message.role !== DyNTS_OAI_GPT_Message_Role.system
521
+ message => message.role !== DyFM_AI_MessageRole.system
564
522
  ).map(message => message.content);
565
523
  let stringifiedMessages = JSON.stringify(msgs);
566
524
 
@@ -622,7 +580,7 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
622
580
 
623
581
  protected logConversation(
624
582
  set: {
625
- conversation: DyNTS_OAI_GPT_Message[],
583
+ conversation: DyFM_AI_Message[],
626
584
  debugLog?: boolean,
627
585
  /** this is used to readably replace too long contents to eg '...' in logs */
628
586
  replaceThisInLog?: string,
@@ -638,4 +596,25 @@ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase /*
638
596
  });
639
597
  }
640
598
  }
599
+
600
+ /**
601
+ * Kérdez egy kérdést és JSON választ vár exact keys-szel
602
+ *
603
+ * Asks a question and expects JSON response with exact keys
604
+ */
605
+ async requestJSONInConversationWithExactKeys<T>(
606
+ set: DyFM_AI_ConversationJSONExactKeys_Input
607
+ ): Promise<T> {
608
+ const answer = await this.jsonQuestionWithExactKeysInConversation<any>(set);
609
+
610
+ if ('unparsableResult' in answer) {
611
+ throw new DyFM_Error({
612
+ message: 'Invalid JSON response from AI',
613
+ additionalContent: { answer },
614
+ userMessage: 'Failed to parse AI response'
615
+ });
616
+ }
617
+
618
+ return answer as T;
619
+ }
641
620
  }