@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.
- package/build/_modules/ai/_models/ai-input-interfaces.d.ts +20 -28
- package/build/_modules/ai/_models/ai-input-interfaces.d.ts.map +1 -1
- package/build/_modules/ai/_models/ai-input-interfaces.js +3 -0
- package/build/_modules/ai/_models/ai-input-interfaces.js.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +14 -58
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.js +138 -147
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.js.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.d.ts +27 -180
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.d.ts.map +1 -1
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.js +147 -328
- package/build/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.js.map +1 -1
- package/build/_modules/ai/_services/ai-llm-chat.service-base.d.ts +22 -14
- package/build/_modules/ai/_services/ai-llm-chat.service-base.d.ts.map +1 -1
- package/build/_modules/ai/_services/ai-llm-chat.service-base.js.map +1 -1
- package/build/_modules/ai/_services/ai-llm.service-base.d.ts +52 -21
- package/build/_modules/ai/_services/ai-llm.service-base.d.ts.map +1 -1
- package/build/_modules/ai/_services/ai-llm.service-base.js +171 -0
- package/build/_modules/ai/_services/ai-llm.service-base.js.map +1 -1
- package/build/_modules/ai/_services/ai-provider.service-base.d.ts +1 -1
- package/build/_modules/ai/_services/ai-provider.service-base.d.ts.map +1 -1
- package/build/_modules/assistant/_services/ass-io.control-service.js +2 -2
- package/build/_modules/assistant/_services/ass-io.control-service.js.map +1 -1
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +9 -9
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -1
- package/build/_modules/discord-assistant/_services/dias-io.control-service.js +2 -2
- package/build/_modules/discord-assistant/_services/dias-io.control-service.js.map +1 -1
- package/package.json +1 -1
- package/src/_modules/ai/_models/ai-input-interfaces.ts +63 -26
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.ts +99 -139
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.ts +246 -294
- package/src/_modules/ai/_services/ai-llm-chat.service-base.ts +36 -16
- package/src/_modules/ai/_services/ai-llm.service-base.ts +272 -28
- package/src/_modules/ai/_services/ai-provider.service-base.ts +1 -1
- package/src/_modules/assistant/_services/ass-io.control-service.ts +2 -2
- package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +9 -9
- package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +2 -2
|
@@ -2,78 +2,115 @@ import { DyFM_AI_MessageRole } from '@futdevpro/fsm-dynamo/ai';
|
|
|
2
2
|
import { DyFM_AI_Message } from '@futdevpro/fsm-dynamo/ai';
|
|
3
3
|
import { DyFM_AI_CallSettings } from '@futdevpro/fsm-dynamo/ai';
|
|
4
4
|
|
|
5
|
-
export interface DyFM_AI_Base_Input
|
|
5
|
+
export interface DyFM_AI_Base_Input<
|
|
6
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
7
|
+
> {
|
|
8
|
+
/* message: string; */
|
|
6
9
|
issuer: string;
|
|
7
|
-
settings?:
|
|
10
|
+
settings?: T_AISettings;
|
|
8
11
|
debugLog?: boolean;
|
|
12
|
+
replaceThisInLog?: string;
|
|
13
|
+
getFullResponse?: boolean;
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
export interface DyFM_AI_Message_Input<
|
|
17
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
18
|
+
> extends DyFM_AI_Base_Input<T_AISettings> {
|
|
19
|
+
message: string;
|
|
14
20
|
}
|
|
15
21
|
|
|
16
|
-
export interface DyFM_AI_ListSelect_Input
|
|
22
|
+
export interface DyFM_AI_ListSelect_Input<
|
|
23
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings,
|
|
24
|
+
> extends DyFM_AI_Message_Input<T_AISettings> {
|
|
17
25
|
selectFrom: string[];
|
|
18
26
|
}
|
|
19
27
|
|
|
20
|
-
export interface DyFM_AI_GenericSelect_Input<
|
|
28
|
+
export interface DyFM_AI_GenericSelect_Input<
|
|
29
|
+
T,
|
|
30
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
31
|
+
> extends DyFM_AI_Message_Input<T_AISettings> {
|
|
21
32
|
selectFrom: T[];
|
|
22
33
|
}
|
|
23
34
|
|
|
24
|
-
export interface DyFM_AI_MultiSelect_Input
|
|
35
|
+
export interface DyFM_AI_MultiSelect_Input<
|
|
36
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
37
|
+
> extends DyFM_AI_Message_Input<T_AISettings> {
|
|
25
38
|
options: string[];
|
|
26
39
|
}
|
|
27
40
|
|
|
28
|
-
export interface DyFM_AI_GenericMultiSelect_Input<
|
|
41
|
+
export interface DyFM_AI_GenericMultiSelect_Input<
|
|
42
|
+
T,
|
|
43
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
44
|
+
> extends DyFM_AI_Message_Input<T_AISettings> {
|
|
29
45
|
options: T[];
|
|
30
46
|
}
|
|
31
47
|
|
|
32
|
-
export interface DyFM_AI_JSONKeysDescription_Input
|
|
48
|
+
export interface DyFM_AI_JSONKeysDescription_Input<
|
|
49
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
50
|
+
> extends DyFM_AI_Message_Input<T_AISettings> {
|
|
33
51
|
keysDescription: string;
|
|
34
52
|
}
|
|
35
53
|
|
|
36
|
-
export interface DyFM_AI_JSONExactKeys_Input
|
|
54
|
+
export interface DyFM_AI_JSONExactKeys_Input<
|
|
55
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
56
|
+
> extends DyFM_AI_Message_Input<T_AISettings> {
|
|
37
57
|
keys: string[];
|
|
38
58
|
}
|
|
39
59
|
|
|
40
|
-
export interface DyFM_AI_SimpleMessage_Input extends DyFM_AI_Base_Input {
|
|
60
|
+
/* export interface DyFM_AI_SimpleMessage_Input extends DyFM_AI_Base_Input {
|
|
41
61
|
message: string;
|
|
42
|
-
}
|
|
62
|
+
} */
|
|
43
63
|
|
|
44
|
-
export interface DyFM_AI_ConversationBase_Input
|
|
64
|
+
export interface DyFM_AI_ConversationBase_Input<
|
|
65
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
66
|
+
> extends DyFM_AI_Base_Input<T_AISettings> {
|
|
67
|
+
message?: string;
|
|
45
68
|
conversation: DyFM_AI_Message[];
|
|
46
|
-
replaceThisInLog?: string;
|
|
69
|
+
/* replaceThisInLog?: string; */
|
|
47
70
|
}
|
|
48
71
|
|
|
49
|
-
export interface
|
|
50
|
-
|
|
51
|
-
}
|
|
72
|
+
/* export interface DyFM_AI_ConversationMessage_Input extends DyFM_AI_ConversationBase_Input {
|
|
73
|
+
message: string;
|
|
74
|
+
} */
|
|
52
75
|
|
|
53
|
-
export interface DyFM_AI_ConversationSelect_Input
|
|
76
|
+
export interface DyFM_AI_ConversationSelect_Input<
|
|
77
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
78
|
+
> extends DyFM_AI_ConversationBase_Input<T_AISettings> {
|
|
54
79
|
selectFrom: string[];
|
|
55
80
|
}
|
|
56
81
|
|
|
57
|
-
export interface DyFM_AI_ConversationGenericSelect_Input<
|
|
82
|
+
export interface DyFM_AI_ConversationGenericSelect_Input<
|
|
83
|
+
T,
|
|
84
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
85
|
+
> extends DyFM_AI_ConversationBase_Input<T_AISettings> {
|
|
58
86
|
selectFrom: T[];
|
|
59
87
|
}
|
|
60
88
|
|
|
61
|
-
export interface DyFM_AI_ConversationMultiSelect_Input
|
|
89
|
+
export interface DyFM_AI_ConversationMultiSelect_Input<
|
|
90
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
91
|
+
> extends DyFM_AI_ConversationBase_Input<T_AISettings> {
|
|
62
92
|
options: string[];
|
|
63
93
|
}
|
|
64
94
|
|
|
65
|
-
export interface DyFM_AI_ConversationGenericMultiSelect_Input<
|
|
95
|
+
export interface DyFM_AI_ConversationGenericMultiSelect_Input<
|
|
96
|
+
T,
|
|
97
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
98
|
+
> extends DyFM_AI_ConversationBase_Input<T_AISettings> {
|
|
66
99
|
options: T[];
|
|
67
100
|
}
|
|
68
101
|
|
|
69
|
-
export interface DyFM_AI_ConversationJSONKeysDescription_Input
|
|
102
|
+
export interface DyFM_AI_ConversationJSONKeysDescription_Input<
|
|
103
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
104
|
+
> extends DyFM_AI_ConversationBase_Input<T_AISettings> {
|
|
70
105
|
keysDescription: string;
|
|
71
106
|
}
|
|
72
107
|
|
|
73
|
-
export interface DyFM_AI_ConversationJSONExactKeys_Input
|
|
108
|
+
export interface DyFM_AI_ConversationJSONExactKeys_Input<
|
|
109
|
+
T_AISettings extends DyFM_AI_CallSettings = DyFM_AI_CallSettings
|
|
110
|
+
> extends DyFM_AI_ConversationBase_Input<T_AISettings> {
|
|
74
111
|
keys: string[];
|
|
75
112
|
}
|
|
76
113
|
|
|
77
|
-
export interface DyFM_AI_ConversationGetAnswer_Input extends DyFM_AI_ConversationBase_Input {
|
|
114
|
+
/* export interface DyFM_AI_ConversationGetAnswer_Input extends DyFM_AI_ConversationBase_Input {
|
|
78
115
|
newMessage?: string;
|
|
79
|
-
}
|
|
116
|
+
} */
|
|
@@ -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
|
-
|
|
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
|
|
79
|
-
|
|
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
|
|
91
|
-
set.
|
|
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.
|
|
91
|
+
const answer: string = await this.requestSimpleMessageInConversation(set);
|
|
96
92
|
|
|
97
|
-
return
|
|
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
|
|
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
|
|
119
|
-
set
|
|
120
|
-
|
|
121
|
-
this.
|
|
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
|
-
|
|
126
|
-
DyFM_Log.error('GPT_ServiceBase', 'asykPercentageQuestion', 'Invalid answer', {
|
|
127
|
-
question: set.question,
|
|
128
|
-
answer,
|
|
129
|
-
});
|
|
121
|
+
//this.logQuestion(set);
|
|
130
122
|
|
|
131
|
-
|
|
132
|
-
}
|
|
123
|
+
const answer: string = await this.requestSimpleMessageInConversation(set);
|
|
133
124
|
|
|
134
|
-
return
|
|
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
|
|
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.
|
|
143
|
+
set.message += selectQuestionAddition;
|
|
151
144
|
|
|
152
|
-
this.logQuestion(set);
|
|
145
|
+
//this.logQuestion(set);
|
|
153
146
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
answer = answer.toLocaleUpperCase();
|
|
147
|
+
const answer = await this.requestSimpleMessageInConversation(set);
|
|
157
148
|
|
|
158
|
-
|
|
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.
|
|
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
|
|
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.
|
|
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
|
|
217
|
+
this.getTextListAsText(this.stringifySelectOptions(set.options))
|
|
231
218
|
);
|
|
232
|
-
set.
|
|
219
|
+
set.message += selectQuestionAddition;
|
|
233
220
|
|
|
234
|
-
this.logQuestion(set);
|
|
221
|
+
//this.logQuestion(set);
|
|
235
222
|
|
|
236
|
-
const answer = await this.
|
|
223
|
+
const answer = await this.requestSimpleMessageInConversation(set);
|
|
237
224
|
|
|
238
|
-
return
|
|
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
|
|
252
|
-
set
|
|
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.
|
|
245
|
+
const answer = await this.requestSimpleMessageInConversation(set);
|
|
257
246
|
|
|
258
|
-
return
|
|
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
|
|
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
|
|
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.
|
|
282
|
+
set.message += jsonRequestWithKeysDescription;
|
|
292
283
|
|
|
293
|
-
this.logQuestion(set);
|
|
284
|
+
//this.logQuestion(set);
|
|
294
285
|
|
|
295
|
-
const answer = await this.
|
|
286
|
+
const answer = await this.requestSimpleMessageInConversation(set);
|
|
296
287
|
|
|
297
|
-
return
|
|
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
|
|
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
|
|
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.
|
|
322
|
+
set.message += jsonRequestWithExactKeys;
|
|
332
323
|
|
|
333
|
-
this.logQuestion(set);
|
|
324
|
+
//this.logQuestion(set);
|
|
334
325
|
|
|
335
|
-
const answer = await this.
|
|
326
|
+
const answer = await this.requestSimpleMessageInConversation(set);
|
|
336
327
|
|
|
337
|
-
return
|
|
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
|
|
351
|
-
set.
|
|
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.
|
|
346
|
+
const answer = await this.requestSimpleMessageInConversation(set);
|
|
356
347
|
|
|
357
|
-
return
|
|
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
|
|
378
|
+
/* async requestSimpleQuestionInConversation(set: DyFM_AI_ConversationMessage_Input): Promise<string> {
|
|
388
379
|
return await this.getAnswerInConversation({
|
|
389
380
|
...set,
|
|
390
|
-
newMessage: set.
|
|
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
|
|
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.
|
|
410
|
-
|
|
400
|
+
if (set.message) {
|
|
401
|
+
set.conversation.push({
|
|
411
402
|
role: DyFM_AI_MessageRole.user,
|
|
412
|
-
content: set.
|
|
403
|
+
content: set.message,
|
|
413
404
|
});
|
|
414
405
|
}
|
|
415
406
|
|
|
416
|
-
const answer: string = await this.
|
|
407
|
+
const answer: string = await this.resolveConversation({
|
|
417
408
|
...set,
|
|
418
|
-
|
|
419
|
-
});
|
|
409
|
+
getFullResponse: false,
|
|
410
|
+
}) as string;
|
|
420
411
|
|
|
421
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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
|
}
|