@futdevpro/nts-dynamo 1.15.3 → 1.15.5
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/.cursor/rules/__main.mdc +3 -1
- package/.cursor/rules/default-command.mdc +324 -88
- package/_specifications/BACKLOG.md +15 -0
- package/_specifications/TODO.md +15 -0
- package/build/_modules/ai/_models/ai-test-generation-result.interface.d.ts +17 -0
- package/build/_modules/ai/_models/ai-test-generation-result.interface.d.ts.map +1 -0
- package/build/_modules/ai/_models/ai-test-generation-result.interface.js +3 -0
- package/build/_modules/ai/_models/ai-test-generation-result.interface.js.map +1 -0
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.d.ts +36 -0
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.d.ts.map +1 -0
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.js +118 -0
- package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.js.map +1 -0
- package/build/_modules/ai/_modules/anthropic/index.d.ts +3 -0
- package/build/_modules/ai/_modules/anthropic/index.d.ts.map +1 -0
- package/build/_modules/ai/_modules/anthropic/index.js +8 -0
- package/build/_modules/ai/_modules/anthropic/index.js.map +1 -0
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.d.ts +35 -0
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.d.ts.map +1 -0
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.js +129 -0
- package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.js.map +1 -0
- package/build/_modules/ai/_modules/fdp-ai/index.d.ts +3 -0
- package/build/_modules/ai/_modules/fdp-ai/index.d.ts.map +1 -0
- package/build/_modules/ai/_modules/fdp-ai/index.js +8 -0
- package/build/_modules/ai/_modules/fdp-ai/index.js.map +1 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.d.ts +40 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.d.ts.map +1 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.js +111 -0
- package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.js.map +1 -0
- package/build/_modules/ai/_modules/open-ai/index.d.ts +1 -0
- package/build/_modules/ai/_modules/open-ai/index.d.ts.map +1 -1
- package/build/_modules/ai/_modules/open-ai/index.js +1 -0
- package/build/_modules/ai/_modules/open-ai/index.js.map +1 -1
- package/build/_modules/ai/_services/ai-user-key.service-base.d.ts +45 -0
- package/build/_modules/ai/_services/ai-user-key.service-base.d.ts.map +1 -0
- package/build/_modules/ai/_services/ai-user-key.service-base.js +15 -0
- package/build/_modules/ai/_services/ai-user-key.service-base.js.map +1 -0
- package/build/_modules/ai/index.d.ts +2 -0
- package/build/_modules/ai/index.d.ts.map +1 -1
- package/build/_modules/ai/index.js +2 -0
- package/build/_modules/ai/index.js.map +1 -1
- package/build/_modules/socket/app-extended.server.js +1 -1
- package/build/_modules/socket/app-extended.server.js.map +1 -1
- package/build/_services/base/data.service.d.ts +1 -1
- package/build/_services/base/data.service.js +1 -1
- package/build/_services/base/db.service.d.ts +1 -1
- package/build/_services/base/db.service.js +1 -1
- package/build/_services/core/auth.service.d.ts +2 -2
- package/build/_services/core/auth.service.js +1 -1
- package/build/_services/core/email.service.js +1 -1
- package/build/_services/core/email.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts +1 -1
- package/build/_services/core/global.service.js +2 -2
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +11 -1
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +17 -4
- package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +16 -0
- package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +138 -0
- package/src/_modules/ai/_modules/anthropic/index.ts +5 -0
- package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +189 -0
- package/src/_modules/ai/_modules/fdp-ai/index.ts +5 -0
- package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +157 -0
- package/src/_modules/ai/_modules/open-ai/index.ts +1 -0
- package/src/_modules/ai/_services/ai-user-key.service-base.ts +59 -0
- package/src/_modules/ai/index.ts +2 -0
- package/src/_modules/socket/app-extended.server.ts +1 -1
- package/src/_services/base/data.service.ts +1 -1
- package/src/_services/base/db.service.ts +1 -1
- package/src/_services/core/auth.service.ts +2 -2
- package/src/_services/core/email.service.ts +1 -1
- package/src/_services/core/global.service.ts +2 -2
- package/src/_services/route/controller.service.ts +1 -1
- package/src/_services/server/app.server.ts +17 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@futdevpro/nts-dynamo",
|
|
3
|
-
"version": "01.15.
|
|
3
|
+
"version": "01.15.5",
|
|
4
4
|
"description": "Dynamic NodeTS (NodeJS-Typescript), MongoDB Backend System Framework by Future Development Program Ltd.",
|
|
5
5
|
"DyBu_settings": {
|
|
6
6
|
"packageType": "server-package",
|
|
@@ -92,6 +92,18 @@
|
|
|
92
92
|
"types": "./build/_modules/ai/_modules/open-ai/index.d.ts",
|
|
93
93
|
"typings": "./build/_modules/ai/_modules/open-ai/index.d.ts"
|
|
94
94
|
},
|
|
95
|
+
"./ai/anthropic": {
|
|
96
|
+
"default": "./build/_modules/ai/_modules/anthropic/index.js",
|
|
97
|
+
"module": "./build/_modules/ai/_modules/anthropic/index.js",
|
|
98
|
+
"types": "./build/_modules/ai/_modules/anthropic/index.d.ts",
|
|
99
|
+
"typings": "./build/_modules/ai/_modules/anthropic/index.d.ts"
|
|
100
|
+
},
|
|
101
|
+
"./ai/fdp-ai": {
|
|
102
|
+
"default": "./build/_modules/ai/_modules/fdp-ai/index.js",
|
|
103
|
+
"module": "./build/_modules/ai/_modules/fdp-ai/index.js",
|
|
104
|
+
"types": "./build/_modules/ai/_modules/fdp-ai/index.d.ts",
|
|
105
|
+
"typings": "./build/_modules/ai/_modules/fdp-ai/index.d.ts"
|
|
106
|
+
},
|
|
95
107
|
|
|
96
108
|
"./assistant": {
|
|
97
109
|
"default": "./build/_modules/assistant/index.js",
|
|
@@ -292,12 +304,12 @@
|
|
|
292
304
|
}
|
|
293
305
|
},
|
|
294
306
|
"DISABLED": {
|
|
295
|
-
"@futdevpro/fsm-dynamo": "file:../tgz-collection/dynamo-fsm/futdevpro-fsm-dynamo-01.15.
|
|
307
|
+
"@futdevpro/fsm-dynamo": "file:../tgz-collection/dynamo-fsm/futdevpro-fsm-dynamo-01.15.4.tgz",
|
|
296
308
|
|
|
297
309
|
"empty": ""
|
|
298
310
|
},
|
|
299
311
|
"peerDependencies": {
|
|
300
|
-
"@futdevpro/fsm-dynamo": "1.15.
|
|
312
|
+
"@futdevpro/fsm-dynamo": "1.15.4",
|
|
301
313
|
|
|
302
314
|
"@types/express": "4.17.21",
|
|
303
315
|
"@types/geoip-lite": "~1.4.1",
|
|
@@ -313,12 +325,13 @@
|
|
|
313
325
|
"ts-node": "~10.9.2"
|
|
314
326
|
},
|
|
315
327
|
"devDependencies": {
|
|
316
|
-
"@futdevpro/dynamo-eslint": "1.15.
|
|
328
|
+
"@futdevpro/dynamo-eslint": "1.15.3",
|
|
317
329
|
"@discordjs/opus": "^0.10.0",
|
|
318
330
|
"@discordjs/voice": "^0.18.0",
|
|
319
331
|
"@types/jasmine": "~4.3.5",
|
|
320
332
|
"@typescript-eslint/eslint-plugin": "^8.41.0",
|
|
321
333
|
"@typescript-eslint/parser": "^8.41.0",
|
|
334
|
+
"@anthropic-ai/sdk": "~0.39.0",
|
|
322
335
|
"crypto-js": "~4.2.0",
|
|
323
336
|
"discord.js": "~14.24.2",
|
|
324
337
|
"eslint": "^9.34.0",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Teszt generalas eredmenye
|
|
3
|
+
*
|
|
4
|
+
* A provider-specifikus testGeneration() metodus ezt adja vissza,
|
|
5
|
+
* tartalmazva a sikesseg flag-et, a valasz szoveget, a hasznalt modellt es a keses-idejet.
|
|
6
|
+
*/
|
|
7
|
+
export interface DyNTS_AI_TestGeneration_Result {
|
|
8
|
+
/** sikeres volt-e a teszt generalas */
|
|
9
|
+
success: boolean;
|
|
10
|
+
/** a provider valasza (sikertelen eseten undefined) */
|
|
11
|
+
response?: string;
|
|
12
|
+
/** a hasznalt modell azonosito */
|
|
13
|
+
model: string;
|
|
14
|
+
/** a keres-valasz ido milliszekundumban */
|
|
15
|
+
latencyMs: number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { DyFM_AI_Provider, DyFM_AI_Config } from '@futdevpro/fsm-dynamo/ai';
|
|
2
|
+
import { DyFM_AI_UserProviderConfig } from '@futdevpro/fsm-dynamo/ai';
|
|
3
|
+
import { DyFM_AAI_UserProviderConfig, DyFM_AAI_Model } from '@futdevpro/fsm-dynamo/ai/anthropic';
|
|
4
|
+
import { DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
5
|
+
|
|
6
|
+
import { DyNTS_AI_UserKey_ServiceBase } from '../../../_services/ai-user-key.service-base';
|
|
7
|
+
import { DyNTS_AI_TestGeneration_Result } from '../../../_models/ai-test-generation-result.interface';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Anthropic-specifikus user API key kezelo service
|
|
11
|
+
*
|
|
12
|
+
* A visszafejtett API kulcsbol Anthropic-specifikus konfigot allit ossze,
|
|
13
|
+
* es teszteli a kapcsolatot az Anthropic API-val.
|
|
14
|
+
*/
|
|
15
|
+
export class DyNTS_AAI_UserKey_ControlService extends DyNTS_AI_UserKey_ServiceBase {
|
|
16
|
+
|
|
17
|
+
static getInstance(): DyNTS_AAI_UserKey_ControlService {
|
|
18
|
+
return DyNTS_AAI_UserKey_ControlService.getSingletonInstance();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
readonly aiProvider: DyFM_AI_Provider = DyFM_AI_Provider.Anthropic;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Anthropic config osszeallitasa a visszafejtett kulcsbol
|
|
25
|
+
*/
|
|
26
|
+
resolveConfig(
|
|
27
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
28
|
+
decryptedApiKey: string
|
|
29
|
+
): DyFM_AI_Config {
|
|
30
|
+
const aaiConfig: DyFM_AAI_UserProviderConfig =
|
|
31
|
+
userProviderConfig as DyFM_AAI_UserProviderConfig;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
apiKey: decryptedApiKey,
|
|
35
|
+
baseURL: aaiConfig.baseURL,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Anthropic kapcsolat tesztelese egy minimal messages.create() hivassal
|
|
41
|
+
*/
|
|
42
|
+
async testConnection(
|
|
43
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
44
|
+
decryptedApiKey: string
|
|
45
|
+
): Promise<boolean> {
|
|
46
|
+
try {
|
|
47
|
+
const Anthropic = await import('@anthropic-ai/sdk');
|
|
48
|
+
const config: DyFM_AI_Config = this.resolveConfig(userProviderConfig, decryptedApiKey);
|
|
49
|
+
|
|
50
|
+
const client = new Anthropic.default({
|
|
51
|
+
apiKey: config.apiKey,
|
|
52
|
+
baseURL: config.baseURL || undefined,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
await client.messages.create({
|
|
56
|
+
model: DyFM_AAI_Model.claude_3_haiku_latest,
|
|
57
|
+
max_tokens: 5,
|
|
58
|
+
messages: [{ role: 'user', content: 'test' }],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return true;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
DyFM_Log.error(
|
|
64
|
+
'DyNTS_AAI_UserKey_ControlService',
|
|
65
|
+
'testConnection',
|
|
66
|
+
'Anthropic connection test failed',
|
|
67
|
+
{ error: error }
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Elerheto Anthropic modellek lekerdezese
|
|
76
|
+
* Az Anthropic API nem ad model list endpoint-ot, ezert a DyFM_AAI_Model enum-bol szolgalja ki
|
|
77
|
+
*/
|
|
78
|
+
async listAvailableModels(
|
|
79
|
+
_userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
80
|
+
_decryptedApiKey: string
|
|
81
|
+
): Promise<string[]> {
|
|
82
|
+
return Object.values(DyFM_AAI_Model);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Teszt generalas az Anthropic API-val
|
|
87
|
+
*/
|
|
88
|
+
async testGeneration(set: {
|
|
89
|
+
userProviderConfig: DyFM_AI_UserProviderConfig;
|
|
90
|
+
decryptedApiKey: string;
|
|
91
|
+
model: string;
|
|
92
|
+
}): Promise<DyNTS_AI_TestGeneration_Result> {
|
|
93
|
+
const startTime: number = Date.now();
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
const Anthropic = await import('@anthropic-ai/sdk');
|
|
97
|
+
const config: DyFM_AI_Config = this.resolveConfig(
|
|
98
|
+
set.userProviderConfig,
|
|
99
|
+
set.decryptedApiKey
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const client = new Anthropic.default({
|
|
103
|
+
apiKey: config.apiKey,
|
|
104
|
+
baseURL: config.baseURL || undefined,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const response = await client.messages.create({
|
|
108
|
+
model: set.model,
|
|
109
|
+
max_tokens: 10,
|
|
110
|
+
messages: [{ role: 'user', content: 'Hello, this is a test. Reply with "OK".' }],
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const textContent = response.content.find(
|
|
114
|
+
(block: { type: string }) => block.type === 'text'
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
success: true,
|
|
119
|
+
response: (textContent as { type: string; text: string })?.text,
|
|
120
|
+
model: set.model,
|
|
121
|
+
latencyMs: Date.now() - startTime,
|
|
122
|
+
};
|
|
123
|
+
} catch (error) {
|
|
124
|
+
DyFM_Log.error(
|
|
125
|
+
'DyNTS_AAI_UserKey_ControlService',
|
|
126
|
+
'testGeneration',
|
|
127
|
+
'Anthropic test generation failed',
|
|
128
|
+
{ error: error }
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
success: false,
|
|
133
|
+
model: set.model,
|
|
134
|
+
latencyMs: Date.now() - startTime,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { DyFM_AI_Provider, DyFM_AI_Config } from '@futdevpro/fsm-dynamo/ai';
|
|
2
|
+
import { DyFM_AI_UserProviderConfig } from '@futdevpro/fsm-dynamo/ai';
|
|
3
|
+
import { DyFM_FdpAI_UserProviderConfig } from '@futdevpro/fsm-dynamo/ai/fdp-ai';
|
|
4
|
+
import { DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
5
|
+
|
|
6
|
+
import { DyNTS_AI_UserKey_ServiceBase } from '../../../_services/ai-user-key.service-base';
|
|
7
|
+
import { DyNTS_AI_TestGeneration_Result } from '../../../_models/ai-test-generation-result.interface';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* FDP-AI-specifikus user API key kezelo service
|
|
11
|
+
*
|
|
12
|
+
* A visszafejtett API kulcsbol FDP-AI-specifikus konfigot allit ossze,
|
|
13
|
+
* es teszteli a kapcsolatot az FDP-AI endpoint-tal.
|
|
14
|
+
*/
|
|
15
|
+
export class DyNTS_FdpAI_UserKey_ControlService extends DyNTS_AI_UserKey_ServiceBase {
|
|
16
|
+
|
|
17
|
+
static getInstance(): DyNTS_FdpAI_UserKey_ControlService {
|
|
18
|
+
return DyNTS_FdpAI_UserKey_ControlService.getSingletonInstance();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
readonly aiProvider: DyFM_AI_Provider = DyFM_AI_Provider.FdpAI;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* FDP-AI config osszeallitasa a visszafejtett kulcsbol
|
|
25
|
+
*/
|
|
26
|
+
resolveConfig(
|
|
27
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
28
|
+
decryptedApiKey: string
|
|
29
|
+
): DyFM_AI_Config {
|
|
30
|
+
const fdpAiConfig: DyFM_FdpAI_UserProviderConfig =
|
|
31
|
+
userProviderConfig as DyFM_FdpAI_UserProviderConfig;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
apiKey: decryptedApiKey,
|
|
35
|
+
baseURL: fdpAiConfig.baseURL,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* FDP-AI kapcsolat tesztelese a health endpoint hivassal
|
|
41
|
+
*/
|
|
42
|
+
async testConnection(
|
|
43
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
44
|
+
decryptedApiKey: string
|
|
45
|
+
): Promise<boolean> {
|
|
46
|
+
try {
|
|
47
|
+
const config: DyFM_AI_Config = this.resolveConfig(userProviderConfig, decryptedApiKey);
|
|
48
|
+
|
|
49
|
+
if (!config.baseURL) {
|
|
50
|
+
DyFM_Log.error(
|
|
51
|
+
'DyNTS_FdpAI_UserKey_ControlService',
|
|
52
|
+
'testConnection',
|
|
53
|
+
'FDP-AI baseURL is required'
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const response = await fetch(`${config.baseURL}/health`, {
|
|
60
|
+
method: 'GET',
|
|
61
|
+
headers: {
|
|
62
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return response.ok;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
DyFM_Log.error(
|
|
69
|
+
'DyNTS_FdpAI_UserKey_ControlService',
|
|
70
|
+
'testConnection',
|
|
71
|
+
'FDP-AI connection test failed',
|
|
72
|
+
{ error: error }
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Elerheto FDP-AI modellek lekerdezese a /models endpoint-rol
|
|
81
|
+
*/
|
|
82
|
+
async listAvailableModels(
|
|
83
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
84
|
+
decryptedApiKey: string
|
|
85
|
+
): Promise<string[]> {
|
|
86
|
+
try {
|
|
87
|
+
const config: DyFM_AI_Config = this.resolveConfig(userProviderConfig, decryptedApiKey);
|
|
88
|
+
|
|
89
|
+
if (!config.baseURL) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const response = await fetch(`${config.baseURL}/models`, {
|
|
94
|
+
method: 'GET',
|
|
95
|
+
headers: {
|
|
96
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const data: { models: string[] } = await response.json() as { models: string[] };
|
|
105
|
+
|
|
106
|
+
return data.models ?? [];
|
|
107
|
+
} catch (error) {
|
|
108
|
+
DyFM_Log.error(
|
|
109
|
+
'DyNTS_FdpAI_UserKey_ControlService',
|
|
110
|
+
'listAvailableModels',
|
|
111
|
+
'FDP-AI model list failed',
|
|
112
|
+
{ error: error }
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Teszt generalas az FDP-AI endpoint-on
|
|
121
|
+
*/
|
|
122
|
+
async testGeneration(set: {
|
|
123
|
+
userProviderConfig: DyFM_AI_UserProviderConfig;
|
|
124
|
+
decryptedApiKey: string;
|
|
125
|
+
model: string;
|
|
126
|
+
}): Promise<DyNTS_AI_TestGeneration_Result> {
|
|
127
|
+
const startTime: number = Date.now();
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const config: DyFM_AI_Config = this.resolveConfig(
|
|
131
|
+
set.userProviderConfig,
|
|
132
|
+
set.decryptedApiKey
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
if (!config.baseURL) {
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
model: set.model,
|
|
139
|
+
latencyMs: Date.now() - startTime,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const response = await fetch(`${config.baseURL}/chat/completions`, {
|
|
144
|
+
method: 'POST',
|
|
145
|
+
headers: {
|
|
146
|
+
'Authorization': `Bearer ${config.apiKey}`,
|
|
147
|
+
'Content-Type': 'application/json',
|
|
148
|
+
},
|
|
149
|
+
body: JSON.stringify({
|
|
150
|
+
model: set.model,
|
|
151
|
+
messages: [{ role: 'user', content: 'Hello, this is a test. Reply with "OK".' }],
|
|
152
|
+
max_tokens: 10,
|
|
153
|
+
}),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
return {
|
|
158
|
+
success: false,
|
|
159
|
+
model: set.model,
|
|
160
|
+
latencyMs: Date.now() - startTime,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const data = await response.json() as {
|
|
165
|
+
choices?: { message?: { content?: string } }[];
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
success: true,
|
|
170
|
+
response: data?.choices?.[0]?.message?.content,
|
|
171
|
+
model: set.model,
|
|
172
|
+
latencyMs: Date.now() - startTime,
|
|
173
|
+
};
|
|
174
|
+
} catch (error) {
|
|
175
|
+
DyFM_Log.error(
|
|
176
|
+
'DyNTS_FdpAI_UserKey_ControlService',
|
|
177
|
+
'testGeneration',
|
|
178
|
+
'FDP-AI test generation failed',
|
|
179
|
+
{ error: error }
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
model: set.model,
|
|
185
|
+
latencyMs: Date.now() - startTime,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { OpenAI } from 'openai';
|
|
2
|
+
|
|
3
|
+
import { DyFM_AI_Provider, DyFM_AI_Config } from '@futdevpro/fsm-dynamo/ai';
|
|
4
|
+
import { DyFM_AI_UserProviderConfig } from '@futdevpro/fsm-dynamo/ai';
|
|
5
|
+
import { DyFM_OAI_UserProviderConfig } from '@futdevpro/fsm-dynamo/ai/open-ai';
|
|
6
|
+
import { DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
7
|
+
|
|
8
|
+
import { DyNTS_AI_UserKey_ServiceBase } from '../../../_services/ai-user-key.service-base';
|
|
9
|
+
import { DyNTS_AI_TestGeneration_Result } from '../../../_models/ai-test-generation-result.interface';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* OpenAI-specifikus user API key kezelo service
|
|
13
|
+
*
|
|
14
|
+
* A visszafejtett API kulcsbol OpenAI-specifikus konfigot allit ossze,
|
|
15
|
+
* es teszteli a kapcsolatot az OpenAI API-val.
|
|
16
|
+
*/
|
|
17
|
+
export class DyNTS_OAI_UserKey_ControlService extends DyNTS_AI_UserKey_ServiceBase {
|
|
18
|
+
|
|
19
|
+
static getInstance(): DyNTS_OAI_UserKey_ControlService {
|
|
20
|
+
return DyNTS_OAI_UserKey_ControlService.getSingletonInstance();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
readonly aiProvider: DyFM_AI_Provider = DyFM_AI_Provider.OpenAI;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* OpenAI config osszeallitasa a visszafejtett kulcsbol
|
|
27
|
+
*/
|
|
28
|
+
resolveConfig(
|
|
29
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
30
|
+
decryptedApiKey: string
|
|
31
|
+
): DyFM_AI_Config {
|
|
32
|
+
const oaiConfig: DyFM_OAI_UserProviderConfig =
|
|
33
|
+
userProviderConfig as DyFM_OAI_UserProviderConfig;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
apiKey: decryptedApiKey,
|
|
37
|
+
organization: oaiConfig.organization,
|
|
38
|
+
project: oaiConfig.project,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* OpenAI kapcsolat tesztelese a models.list() hivassal
|
|
44
|
+
*/
|
|
45
|
+
async testConnection(
|
|
46
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
47
|
+
decryptedApiKey: string
|
|
48
|
+
): Promise<boolean> {
|
|
49
|
+
try {
|
|
50
|
+
const config: DyFM_AI_Config = this.resolveConfig(userProviderConfig, decryptedApiKey);
|
|
51
|
+
const openai: OpenAI = new OpenAI({
|
|
52
|
+
apiKey: config.apiKey,
|
|
53
|
+
organization: config.organization,
|
|
54
|
+
project: config.project,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await openai.models.list();
|
|
58
|
+
|
|
59
|
+
return true;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
DyFM_Log.error(
|
|
62
|
+
'DyNTS_OAI_UserKey_ControlService',
|
|
63
|
+
'testConnection',
|
|
64
|
+
'OpenAI connection test failed',
|
|
65
|
+
{ error: error }
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Elerheto OpenAI modellek lekerdezese
|
|
74
|
+
* Szuri a chat/LLM modelleket (nem embedding, nem whisper stb.)
|
|
75
|
+
*/
|
|
76
|
+
async listAvailableModels(
|
|
77
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
78
|
+
decryptedApiKey: string
|
|
79
|
+
): Promise<string[]> {
|
|
80
|
+
const config: DyFM_AI_Config = this.resolveConfig(userProviderConfig, decryptedApiKey);
|
|
81
|
+
const openai: OpenAI = new OpenAI({
|
|
82
|
+
apiKey: config.apiKey,
|
|
83
|
+
organization: config.organization,
|
|
84
|
+
project: config.project,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const models = await openai.models.list();
|
|
88
|
+
|
|
89
|
+
return models.data
|
|
90
|
+
.map((m) => m.id)
|
|
91
|
+
.filter((id: string) => this.isLLMModel(id))
|
|
92
|
+
.sort();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Teszt generalas az OpenAI API-val
|
|
97
|
+
*/
|
|
98
|
+
async testGeneration(set: {
|
|
99
|
+
userProviderConfig: DyFM_AI_UserProviderConfig;
|
|
100
|
+
decryptedApiKey: string;
|
|
101
|
+
model: string;
|
|
102
|
+
}): Promise<DyNTS_AI_TestGeneration_Result> {
|
|
103
|
+
const startTime: number = Date.now();
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const config: DyFM_AI_Config = this.resolveConfig(
|
|
107
|
+
set.userProviderConfig,
|
|
108
|
+
set.decryptedApiKey
|
|
109
|
+
);
|
|
110
|
+
const openai: OpenAI = new OpenAI({
|
|
111
|
+
apiKey: config.apiKey,
|
|
112
|
+
organization: config.organization,
|
|
113
|
+
project: config.project,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const response = await openai.chat.completions.create({
|
|
117
|
+
model: set.model,
|
|
118
|
+
messages: [{ role: 'user', content: 'Hello, this is a test. Reply with "OK".' }],
|
|
119
|
+
max_tokens: 10,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
response: response.choices[0]?.message?.content,
|
|
125
|
+
model: set.model,
|
|
126
|
+
latencyMs: Date.now() - startTime,
|
|
127
|
+
};
|
|
128
|
+
} catch (error) {
|
|
129
|
+
DyFM_Log.error(
|
|
130
|
+
'DyNTS_OAI_UserKey_ControlService',
|
|
131
|
+
'testGeneration',
|
|
132
|
+
'OpenAI test generation failed',
|
|
133
|
+
{ error: error }
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
success: false,
|
|
138
|
+
model: set.model,
|
|
139
|
+
latencyMs: Date.now() - startTime,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* LLM/Chat modell szures -- kiszuri az embedding, whisper, tts stb. modelleket
|
|
146
|
+
*/
|
|
147
|
+
private isLLMModel(modelId: string): boolean {
|
|
148
|
+
const excludePatterns: string[] = [
|
|
149
|
+
'embedding', 'whisper', 'tts', 'dall-e',
|
|
150
|
+
'moderation', 'davinci', 'babbage', 'ada',
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
return !excludePatterns.some(
|
|
154
|
+
(pattern: string) => modelId.includes(pattern)
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -65,6 +65,7 @@ export * from './_services/oai-embedding.service'; */
|
|
|
65
65
|
export * from './_services/oai-embedding.control-service';
|
|
66
66
|
export * from './_services/oai-llm-chat.service-base';
|
|
67
67
|
export * from './_services/oai-llm.service-base';
|
|
68
|
+
export * from './_services/oai-user-key.control-service';
|
|
68
69
|
// services/DATA-SERVICES
|
|
69
70
|
export * from './_services/data-services/oai-doc-chunk-data.service';
|
|
70
71
|
export * from './_services/data-services/oai-doc-page.data-service';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DyFM_AI_Provider, DyFM_AI_Config } from '@futdevpro/fsm-dynamo/ai';
|
|
2
|
+
import { DyFM_AI_UserProviderConfig } from '@futdevpro/fsm-dynamo/ai';
|
|
3
|
+
|
|
4
|
+
import { DyNTS_SingletonService } from '../../../_services/base/singleton.service';
|
|
5
|
+
import { DyNTS_AI_TestGeneration_Result } from '../_models/ai-test-generation-result.interface';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Absztrakt bazis osztaly a user AI provider kulcs kezeleshez
|
|
9
|
+
*
|
|
10
|
+
* A titkositas/visszafejtes NEM itt tortenik -- azt az fdp-auth-service Auth_ControlService-e vegzi.
|
|
11
|
+
* Ezek a service-ek a mar visszafejtett config-ot es API kulcsot kapjak,
|
|
12
|
+
* es abbol allitjak ossze a provider-specifikus konfigot.
|
|
13
|
+
*/
|
|
14
|
+
export abstract class DyNTS_AI_UserKey_ServiceBase extends DyNTS_SingletonService {
|
|
15
|
+
/** melyik provider-hez tartozik ez a service */
|
|
16
|
+
abstract readonly aiProvider: DyFM_AI_Provider;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Visszafejtett user config + kulcs -> provider-specifikus AI config osszeallitas
|
|
20
|
+
* @param userProviderConfig - a user provider konfiguracioja
|
|
21
|
+
* @param decryptedApiKey - a mar visszafejtett API kulcs
|
|
22
|
+
*/
|
|
23
|
+
abstract resolveConfig(
|
|
24
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
25
|
+
decryptedApiKey: string
|
|
26
|
+
): DyFM_AI_Config;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Kapcsolat tesztelese a provider-rel a visszafejtett kulccsal
|
|
30
|
+
* @param userProviderConfig - a user provider konfiguracioja
|
|
31
|
+
* @param decryptedApiKey - a mar visszafejtett API kulcs
|
|
32
|
+
*/
|
|
33
|
+
abstract testConnection(
|
|
34
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
35
|
+
decryptedApiKey: string
|
|
36
|
+
): Promise<boolean>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Elerheto modellek lekerdezese a provider API-rol
|
|
40
|
+
* @param userProviderConfig - a user provider konfiguracioja
|
|
41
|
+
* @param decryptedApiKey - a mar visszafejtett API kulcs
|
|
42
|
+
*/
|
|
43
|
+
abstract listAvailableModels(
|
|
44
|
+
userProviderConfig: DyFM_AI_UserProviderConfig,
|
|
45
|
+
decryptedApiKey: string
|
|
46
|
+
): Promise<string[]>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Teszt generalas a provider-rel
|
|
50
|
+
* @param set.userProviderConfig - a user provider konfiguracioja
|
|
51
|
+
* @param set.decryptedApiKey - a mar visszafejtett API kulcs
|
|
52
|
+
* @param set.model - a hasznalando modell
|
|
53
|
+
*/
|
|
54
|
+
abstract testGeneration(set: {
|
|
55
|
+
userProviderConfig: DyFM_AI_UserProviderConfig;
|
|
56
|
+
decryptedApiKey: string;
|
|
57
|
+
model: string;
|
|
58
|
+
}): Promise<DyNTS_AI_TestGeneration_Result>;
|
|
59
|
+
}
|
package/src/_modules/ai/index.ts
CHANGED
|
@@ -3,9 +3,11 @@ export * from '@futdevpro/fsm-dynamo/ai';
|
|
|
3
3
|
|
|
4
4
|
// AI Input Interfaces (moved from FSM)
|
|
5
5
|
export * from './_models/ai-input-interfaces';
|
|
6
|
+
export * from './_models/ai-test-generation-result.interface';
|
|
6
7
|
|
|
7
8
|
// Abstract Services
|
|
8
9
|
export * from './_services/ai-provider.service-base';
|
|
9
10
|
export * from './_services/ai-llm.service-base';
|
|
10
11
|
export * from './_services/ai-llm-chat.service-base';
|
|
11
12
|
export * from './_services/ai-embedding.service-base';
|
|
13
|
+
export * from './_services/ai-user-key.service-base';
|
|
@@ -460,7 +460,7 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
460
460
|
`\n keyPath: FileSystem.PathLike,` +
|
|
461
461
|
`\n certPath: FileSystem.PathLike,` +
|
|
462
462
|
`\n }` +
|
|
463
|
-
`\nin
|
|
463
|
+
`\nin DynamoNTSServer - setupRoutingModules() to enable secure routes.`;
|
|
464
464
|
|
|
465
465
|
errorMsg += '\n\nThe socket services setted to use secure server:';
|
|
466
466
|
this.socketServices.forEach((service: DyNTS_SocketServerService<any>): void => {
|
|
@@ -2426,7 +2426,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
2426
2426
|
|
|
2427
2427
|
|
|
2428
2428
|
/**
|
|
2429
|
-
* setting up dependency dataHook by
|
|
2429
|
+
* setting up dependency dataHook by DynamoNTSDataModelParams
|
|
2430
2430
|
*/
|
|
2431
2431
|
private lookForDependencyDataSettings(): void {
|
|
2432
2432
|
const dependencyParams: DyFM_DataProperty_Params<any, T>[] =
|
|
@@ -1277,7 +1277,7 @@ export class DyNTS_DBService<T extends DyFM_Metadata> {
|
|
|
1277
1277
|
|
|
1278
1278
|
/**
|
|
1279
1279
|
* builds mongoose schema building settings object by dynamoDataModelParamsList
|
|
1280
|
-
* @param properties
|
|
1280
|
+
* @param properties DynamoNTSDataPropertyParams
|
|
1281
1281
|
* @returns mongoose schema object
|
|
1282
1282
|
*/
|
|
1283
1283
|
private buildMongooseSchemaSettingsObjByModelParams(properties: DyFM_DataProperties<T>): any {
|