@futdevpro/nts-dynamo 1.10.25 → 1.10.27
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/_models/control-models/app-params.control-model.d.ts +30 -0
- package/build/_models/control-models/app-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/app-params.control-model.js +6 -0
- package/build/_models/control-models/app-params.control-model.js.map +1 -1
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts +3 -22
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts.map +1 -1
- package/build/_modules/open-ai/_services/embedding.control-service.js +13 -26
- package/build/_modules/open-ai/_services/embedding.control-service.js.map +1 -1
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts +5 -5
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts.map +1 -1
- package/build/_modules/open-ai/_services/gpt.service-base.js.map +1 -1
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts +4 -6
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts.map +1 -1
- package/build/_modules/open-ai/_services/open-ai.service-base.js +3 -3
- package/build/_modules/open-ai/_services/open-ai.service-base.js.map +1 -1
- package/build/_modules/open-ai/_services/vector-data.service.d.ts +32 -0
- package/build/_modules/open-ai/_services/vector-data.service.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/vector-data.service.js +126 -0
- package/build/_modules/open-ai/_services/vector-data.service.js.map +1 -0
- package/build/_modules/open-ai/index.d.ts +2 -4
- package/build/_modules/open-ai/index.d.ts.map +1 -1
- package/build/_modules/open-ai/index.js +2 -4
- package/build/_modules/open-ai/index.js.map +1 -1
- package/build/_modules/server/errors/errors.data-service.d.ts.map +1 -1
- package/build/_modules/server/errors/errors.data-service.js +6 -1
- package/build/_modules/server/errors/errors.data-service.js.map +1 -1
- package/build/_modules/socket/_models/socket-presence.control-model.js +1 -1
- package/build/_modules/socket/_services/socket-client.service.d.ts +2 -1
- package/build/_modules/socket/_services/socket-client.service.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-client.service.js +22 -19
- package/build/_modules/socket/_services/socket-client.service.js.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.d.ts +1 -1
- package/build/_modules/socket/_services/socket-server.service.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.js +40 -29
- package/build/_modules/socket/_services/socket-server.service.js.map +1 -1
- package/build/_services/base/data.service.d.ts +13 -4
- package/build/_services/base/data.service.d.ts.map +1 -1
- package/build/_services/base/data.service.js +16 -10
- package/build/_services/base/data.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +13 -4
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +3 -3
- package/src/_models/control-models/app-params.control-model.ts +9 -0
- package/src/_modules/open-ai/_services/embedding.control-service.ts +18 -28
- package/src/_modules/open-ai/_services/gpt.service-base.ts +7 -8
- package/src/_modules/open-ai/_services/open-ai.service-base.ts +6 -9
- package/src/_modules/open-ai/_services/vector-data.service.ts +188 -0
- package/src/_modules/open-ai/index.ts +2 -6
- package/src/_modules/server/errors/errors.data-service.ts +5 -1
- package/src/_modules/socket/_models/socket-presence.control-model.ts +1 -1
- package/src/_modules/socket/_services/socket-client.service.ts +23 -20
- package/src/_modules/socket/_services/socket-server.service.ts +40 -28
- package/src/_services/base/data.service.ts +14 -14
- package/src/_services/server/app.server.ts +13 -9
- package/build/_modules/open-ai/_enums/open-ai-model.enum.d.ts +0 -11
- package/build/_modules/open-ai/_enums/open-ai-model.enum.d.ts.map +0 -1
- package/build/_modules/open-ai/_enums/open-ai-model.enum.js +0 -110
- package/build/_modules/open-ai/_enums/open-ai-model.enum.js.map +0 -1
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.d.ts +0 -54
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.d.ts.map +0 -1
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.js +0 -65
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.js.map +0 -1
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.d.ts +0 -7
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.d.ts.map +0 -1
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.js +0 -3
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.js.map +0 -1
- package/build/_modules/open-ai/_models/open-ai-settings.interface.d.ts +0 -17
- package/build/_modules/open-ai/_models/open-ai-settings.interface.d.ts.map +0 -1
- package/build/_modules/open-ai/_models/open-ai-settings.interface.js +0 -25
- package/build/_modules/open-ai/_models/open-ai-settings.interface.js.map +0 -1
- package/src/_modules/open-ai/_enums/open-ai-model.enum.ts +0 -137
- package/src/_modules/open-ai/_models/gpt-call-settings.interface.ts +0 -69
- package/src/_modules/open-ai/_models/open-ai-api-env-settings.interface.ts +0 -12
- package/src/_modules/open-ai/_models/open-ai-settings.interface.ts +0 -31
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
import OpenAI from 'openai';
|
|
2
1
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { DyFM_OpenAIModel } from '@futdevpro/fsm-dynamo/open-ai';
|
|
3
|
+
import { DyFM_Error } from '@futdevpro/fsm-dynamo';
|
|
4
|
+
|
|
5
5
|
import { DyNTS_OpenAI_ServiceBase } from './open-ai.service-base';
|
|
6
|
+
import { DyNTS_global_settings } from '../../../_collections/global-settings.const';
|
|
6
7
|
|
|
7
|
-
/**
|
|
8
|
-
* Service for handling OpenAI text embeddings
|
|
9
|
-
* @class Embedding_ControlService
|
|
10
|
-
* @extends DyNTS_OpenAI_ServiceBase
|
|
11
|
-
*/
|
|
12
8
|
export class Embedding_ControlService extends DyNTS_OpenAI_ServiceBase {
|
|
13
9
|
|
|
14
|
-
/**
|
|
15
|
-
* Creates embeddings for the given text using the specified model
|
|
16
|
-
* @param {string} text - The text to create embeddings for
|
|
17
|
-
* @param {DyNTS_OpenAIModel} [model=DyNTS_GPTModel.textEmbedding_3Large] - The embedding model to use
|
|
18
|
-
* @returns {Promise<number[]>} The embedding vector
|
|
19
|
-
* @throws {Error} If the embedding creation fails
|
|
20
|
-
*/
|
|
21
10
|
async createEmbedding(
|
|
22
11
|
text: string,
|
|
23
|
-
model:
|
|
12
|
+
model: DyFM_OpenAIModel | string = DyFM_OpenAIModel.textEmbedding_3Large,
|
|
13
|
+
issuer: string
|
|
24
14
|
): Promise<number[]> {
|
|
25
15
|
try {
|
|
26
16
|
const response = await this.openai.embeddings.create({
|
|
@@ -30,21 +20,18 @@ export class Embedding_ControlService extends DyNTS_OpenAI_ServiceBase {
|
|
|
30
20
|
|
|
31
21
|
return response.data[0].embedding;
|
|
32
22
|
} catch (error) {
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
throw new DyFM_Error({
|
|
24
|
+
...this.getDefaultErrorSettings('createEmbedding', error, issuer),
|
|
25
|
+
|
|
26
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-ECS-CE0`,
|
|
27
|
+
});
|
|
35
28
|
}
|
|
36
29
|
}
|
|
37
30
|
|
|
38
|
-
/**
|
|
39
|
-
* Creates embeddings for multiple texts using the specified model
|
|
40
|
-
* @param {string[]} texts - Array of texts to create embeddings for
|
|
41
|
-
* @param {DyNTS_OpenAIModel} [model=DyNTS_GPTModel.textEmbedding_3Large] - The embedding model to use
|
|
42
|
-
* @returns {Promise<number[][]>} Array of embedding vectors
|
|
43
|
-
* @throws {Error} If the embedding creation fails
|
|
44
|
-
*/
|
|
45
31
|
async createEmbeddings(
|
|
46
32
|
texts: string[],
|
|
47
|
-
model:
|
|
33
|
+
model: DyFM_OpenAIModel | string = DyFM_OpenAIModel.textEmbedding_3Large,
|
|
34
|
+
issuer: string
|
|
48
35
|
): Promise<number[][]> {
|
|
49
36
|
try {
|
|
50
37
|
const response = await this.openai.embeddings.create({
|
|
@@ -54,8 +41,11 @@ export class Embedding_ControlService extends DyNTS_OpenAI_ServiceBase {
|
|
|
54
41
|
|
|
55
42
|
return response.data.map(item => item.embedding);
|
|
56
43
|
} catch (error) {
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
throw new DyFM_Error({
|
|
45
|
+
...this.getDefaultErrorSettings('createEmbeddings', error, issuer),
|
|
46
|
+
|
|
47
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-ECS-CES0`,
|
|
48
|
+
});
|
|
59
49
|
}
|
|
60
50
|
}
|
|
61
51
|
}
|
|
@@ -3,11 +3,10 @@ import { OpenAI, ClientOptions } from 'openai';
|
|
|
3
3
|
import { ChatCompletion, ChatCompletionMessageParam } from 'openai/resources';
|
|
4
4
|
|
|
5
5
|
import { DyFM_AnyError, DyFM_Error, DyFM_Error_Settings, DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
6
|
+
import { DyFM_GPTCall_Settings } from '@futdevpro/fsm-dynamo/open-ai';
|
|
6
7
|
|
|
7
|
-
import { DyNTS_OpenAIModel } from '../_enums/open-ai-model.enum';
|
|
8
8
|
import { DyNTS_global_settings } from '../../../_collections/global-settings.const';
|
|
9
9
|
import { DyNTS_OpenAI_ServiceBase } from './open-ai.service-base';
|
|
10
|
-
import { DyNTS_GPTCall_Settings } from '../_models/gpt-call-settings.interface';
|
|
11
10
|
import { RequestOptions } from 'openai/core';
|
|
12
11
|
import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions';
|
|
13
12
|
|
|
@@ -258,7 +257,7 @@ export class DyNTS_GPT_ServiceBase extends DyNTS_OpenAI_ServiceBase {
|
|
|
258
257
|
async getQuestionAnswer(
|
|
259
258
|
question: string,
|
|
260
259
|
issuer: string,
|
|
261
|
-
messageSettings:
|
|
260
|
+
messageSettings: DyFM_GPTCall_Settings = this.defaultSettings
|
|
262
261
|
): Promise<string> {
|
|
263
262
|
const answer = await this.resolveSimpleUserMessage(question, issuer, messageSettings);
|
|
264
263
|
|
|
@@ -287,7 +286,7 @@ export class DyNTS_GPT_ServiceBase extends DyNTS_OpenAI_ServiceBase {
|
|
|
287
286
|
async getAnswer(
|
|
288
287
|
question: string,
|
|
289
288
|
issuer: string,
|
|
290
|
-
settings?:
|
|
289
|
+
settings?: DyFM_GPTCall_Settings
|
|
291
290
|
): Promise<string> {
|
|
292
291
|
if (this.debugLog) {
|
|
293
292
|
console.log('\n - ', question);
|
|
@@ -305,7 +304,7 @@ export class DyNTS_GPT_ServiceBase extends DyNTS_OpenAI_ServiceBase {
|
|
|
305
304
|
async resolveSimpleUserMessage(
|
|
306
305
|
message: string,
|
|
307
306
|
issuer: string,
|
|
308
|
-
settings?:
|
|
307
|
+
settings?: DyFM_GPTCall_Settings
|
|
309
308
|
): Promise<string> {
|
|
310
309
|
return this.resolveConversation(
|
|
311
310
|
[{ role: 'user', content: message }],
|
|
@@ -318,7 +317,7 @@ export class DyNTS_GPT_ServiceBase extends DyNTS_OpenAI_ServiceBase {
|
|
|
318
317
|
async resolveConversation(
|
|
319
318
|
conversation: DyNTS_GPT_Message[],
|
|
320
319
|
issuer: string,
|
|
321
|
-
settings?:
|
|
320
|
+
settings?: DyFM_GPTCall_Settings,
|
|
322
321
|
getFullResponse?: boolean
|
|
323
322
|
): Promise<string | ChatCompletion> {
|
|
324
323
|
try {
|
|
@@ -346,7 +345,7 @@ export class DyNTS_GPT_ServiceBase extends DyNTS_OpenAI_ServiceBase {
|
|
|
346
345
|
private getMessageCreateInput(
|
|
347
346
|
messages: DyNTS_GPT_Message[],
|
|
348
347
|
issuer: string,
|
|
349
|
-
settings:
|
|
348
|
+
settings: DyFM_GPTCall_Settings = this.defaultSettings
|
|
350
349
|
): ChatCompletionCreateParamsBase {
|
|
351
350
|
try {
|
|
352
351
|
messages.unshift(this.getDefaultSystemMessage(settings));
|
|
@@ -386,7 +385,7 @@ export class DyNTS_GPT_ServiceBase extends DyNTS_OpenAI_ServiceBase {
|
|
|
386
385
|
}
|
|
387
386
|
}
|
|
388
387
|
|
|
389
|
-
private getDefaultSystemMessage(settings:
|
|
388
|
+
private getDefaultSystemMessage(settings: DyFM_GPTCall_Settings): DyNTS_GPT_Message {
|
|
390
389
|
return {
|
|
391
390
|
role: DyNTS_GPT_Message_Role.system,
|
|
392
391
|
content: settings.systemPrompt || this.defaultSystemPrompt,
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
1
|
import { OpenAI, ClientOptions } from 'openai';
|
|
3
2
|
import { ChatCompletion, ChatCompletionMessageParam } from 'openai/resources';
|
|
4
3
|
|
|
4
|
+
import { DyFM_OpenAI_Settings, DyFM_OpenAIModel, DyFM_GPTCall_Settings } from '@futdevpro/fsm-dynamo/open-ai';
|
|
5
5
|
import { DyFM_AnyError, DyFM_Error, DyFM_Error_Settings, DyFM_Log } from '@futdevpro/fsm-dynamo';
|
|
6
6
|
|
|
7
|
-
import { DyNTS_OpenAIModel } from '../_enums/open-ai-model.enum';
|
|
8
7
|
import { DyNTS_global_settings } from '../../../_collections/global-settings.const';
|
|
9
|
-
import { DyNTS_OpenAI_Settings } from '../_models/open-ai-settings.interface';
|
|
10
|
-
import { DyNTS_GPTCall_Settings } from '../_models/gpt-call-settings.interface';
|
|
11
8
|
|
|
12
9
|
|
|
13
10
|
/**
|
|
@@ -29,8 +26,8 @@ export class DyNTS_OpenAI_ServiceBase {
|
|
|
29
26
|
readonly openai: OpenAI;
|
|
30
27
|
|
|
31
28
|
/* readonly defaultSystemPrompt: string;
|
|
32
|
-
readonly defaultModel:
|
|
33
|
-
readonly defaultSettings:
|
|
29
|
+
readonly defaultModel: DyFM_OpenAIModel | string; */
|
|
30
|
+
readonly defaultSettings: DyFM_GPTCall_Settings;
|
|
34
31
|
|
|
35
32
|
get debugLog(): boolean {
|
|
36
33
|
return this.defaultSettings.debugLog;
|
|
@@ -40,15 +37,15 @@ export class DyNTS_OpenAI_ServiceBase {
|
|
|
40
37
|
return this.defaultSettings.systemPrompt;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
get defaultModel():
|
|
40
|
+
get defaultModel(): DyFM_OpenAIModel | string {
|
|
44
41
|
return this.defaultSettings.useModel;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
44
|
constructor(
|
|
48
|
-
set:
|
|
45
|
+
set: DyFM_OpenAI_Settings
|
|
49
46
|
) {
|
|
50
47
|
this.openai = new OpenAI(set.openAIConfig);
|
|
51
|
-
this.defaultSettings = set.defaultSettings ?? new
|
|
48
|
+
this.defaultSettings = set.defaultSettings ?? new DyFM_GPTCall_Settings();
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
protected getDefaultErrorSettings(
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
DyFM_Array,
|
|
4
|
+
DyFM_DataModel_Params,
|
|
5
|
+
DyFM_DataProperty_Params,
|
|
6
|
+
DyFM_Error,
|
|
7
|
+
DyFM_Metadata
|
|
8
|
+
} from '@futdevpro/fsm-dynamo';
|
|
9
|
+
import { DyFM_OpenAI_Settings, DyFM_OpenAIModel } from '@futdevpro/fsm-dynamo/open-ai';
|
|
10
|
+
|
|
11
|
+
import { DyNTS_global_settings } from '../../../_collections/global-settings.const';
|
|
12
|
+
import { DyNTS_DataService } from '../../../_services/base/data.service';
|
|
13
|
+
import { Embedding_ControlService } from './embedding.control-service';
|
|
14
|
+
|
|
15
|
+
export class DyNTS_VectorDataService<T extends DyFM_Metadata> extends DyNTS_DataService<T> {
|
|
16
|
+
|
|
17
|
+
readonly vectorizeProperties: DyFM_DataProperty_Params<any>[];
|
|
18
|
+
/* readonly vectorizeProperties: { from: string, to: string }[]; */
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
/**
|
|
22
|
+
* Initial data, this will be used by functions on default
|
|
23
|
+
*/
|
|
24
|
+
data: T,
|
|
25
|
+
/**
|
|
26
|
+
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
27
|
+
*/
|
|
28
|
+
dataParams: DyFM_DataModel_Params<T>,
|
|
29
|
+
/**
|
|
30
|
+
* OpenAI settings
|
|
31
|
+
*/
|
|
32
|
+
public readonly openAISettings: DyFM_OpenAI_Settings,
|
|
33
|
+
/**
|
|
34
|
+
* Initial set for issuer to be able to follow the issuer's activity
|
|
35
|
+
*/
|
|
36
|
+
issuer: string
|
|
37
|
+
) {
|
|
38
|
+
super(data, dataParams, issuer);
|
|
39
|
+
|
|
40
|
+
const vectorizePropertyKeys: string[] = Object.keys(dataParams.properties).filter(
|
|
41
|
+
(key: string): boolean => dataParams.properties[key].vectorizeFrom &&
|
|
42
|
+
dataParams.properties[key].vectorizeFrom !== key
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (!vectorizePropertyKeys.length) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
'vectorizedPropertyKeys is missing! ' +
|
|
48
|
+
`\nkeys with vectorizeFrom: ${Object.keys(dataParams.properties).filter(
|
|
49
|
+
(key: string): boolean => dataParams.properties[key].vectorizeFrom
|
|
50
|
+
).join(', ')}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.vectorizeProperties = vectorizePropertyKeys.map(
|
|
55
|
+
(key: string): DyFM_DataProperty_Params<any> => dataParams.properties[key]
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async vectorizeDataProperties(data?: T): Promise<T> {
|
|
60
|
+
try {
|
|
61
|
+
await DyFM_Array.asyncForEachAllAtOnce(
|
|
62
|
+
this.vectorizeProperties,
|
|
63
|
+
async (property: DyFM_DataProperty_Params<any>) => {
|
|
64
|
+
if (!data[property.key] || property.vectorizeAlways) {
|
|
65
|
+
data[property.key] = await this.vectorize(
|
|
66
|
+
data[property.key],
|
|
67
|
+
property.embeddingModel
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return data;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new DyFM_Error({
|
|
76
|
+
...this.getDefaultErrorSettings('vectorizeDataProperties', error),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async vectorize(
|
|
82
|
+
input: string,
|
|
83
|
+
useModel: DyFM_OpenAIModel | string = this.openAISettings.defaultSettings.useModel
|
|
84
|
+
): Promise<number[]> {
|
|
85
|
+
try {
|
|
86
|
+
const embedding_CS: Embedding_ControlService = new Embedding_ControlService(
|
|
87
|
+
this.openAISettings
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return await embedding_CS.createEmbedding(
|
|
91
|
+
input,
|
|
92
|
+
useModel,
|
|
93
|
+
this.issuer
|
|
94
|
+
);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw new DyFM_Error({
|
|
97
|
+
...this.getDefaultErrorSettings('vectorize', error),
|
|
98
|
+
|
|
99
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-VDB-V0`,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async vectorSearch(
|
|
105
|
+
input: string,
|
|
106
|
+
searchInKey: string,
|
|
107
|
+
/* useIndex: string, */
|
|
108
|
+
limit: number = 5,
|
|
109
|
+
useModel?: DyFM_OpenAIModel | string
|
|
110
|
+
): Promise<any> {
|
|
111
|
+
try {
|
|
112
|
+
const embedding_CS: Embedding_ControlService = new Embedding_ControlService(
|
|
113
|
+
this.openAISettings
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const property: DyFM_DataProperty_Params<any> = this.dataParams.properties[searchInKey];
|
|
117
|
+
|
|
118
|
+
if (!property) {
|
|
119
|
+
throw new DyFM_Error({
|
|
120
|
+
...this.getDefaultErrorSettings(
|
|
121
|
+
'vectorSearch',
|
|
122
|
+
new Error(`Property "${searchInKey}" not found!`)
|
|
123
|
+
),
|
|
124
|
+
|
|
125
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-VDB-VS0`,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const embeddedInput: number[] = await embedding_CS.createEmbedding(
|
|
130
|
+
input,
|
|
131
|
+
useModel ?? property.embeddingModel,
|
|
132
|
+
this.issuer
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const result = await this.dataDBService.aggregate(
|
|
136
|
+
[
|
|
137
|
+
{
|
|
138
|
+
$vectorSearch: {
|
|
139
|
+
index: property.vectorizeUseIndex,
|
|
140
|
+
queryVector: embeddedInput,
|
|
141
|
+
path: searchInKey,
|
|
142
|
+
numCandidates: 100,
|
|
143
|
+
limit: limit
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
/* {
|
|
148
|
+
$search: {
|
|
149
|
+
index: 'default',
|
|
150
|
+
knnBeta: {
|
|
151
|
+
vector: embeddedInput,
|
|
152
|
+
path: searchInKey,
|
|
153
|
+
numCandidates: 100,
|
|
154
|
+
limit: limit
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
} */
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return result;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
throw new DyFM_Error({
|
|
163
|
+
...this.getDefaultErrorSettings('vectorSearch', error),
|
|
164
|
+
|
|
165
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-VDB-VS0`,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
override async saveData(data?: T, dontSetToService?: boolean): Promise<T> {
|
|
171
|
+
try {
|
|
172
|
+
data = this.ensureData(data);
|
|
173
|
+
|
|
174
|
+
data = await this.vectorizeDataProperties(data);
|
|
175
|
+
|
|
176
|
+
return await super.saveData(data, dontSetToService);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
throw new DyFM_Error({
|
|
179
|
+
...this.getDefaultErrorSettings(
|
|
180
|
+
'saveData',
|
|
181
|
+
error
|
|
182
|
+
),
|
|
183
|
+
|
|
184
|
+
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-VDB-SD0`,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
export * from './_enums/open-ai-model.enum';
|
|
4
|
-
|
|
5
|
-
export * from './_models/gpt-call-settings.interface';
|
|
6
|
-
export * from './_models/open-ai-api-env-settings.interface';
|
|
7
|
-
export * from './_models/open-ai-settings.interface';
|
|
8
|
-
|
|
9
3
|
export * from './_services/embedding.control-service';
|
|
10
4
|
export * from './_services/gpt.service-base';
|
|
11
5
|
export * from './_services/open-ai.service-base';
|
|
6
|
+
export * from './_services/vector-data.service';
|
|
12
7
|
|
|
8
|
+
export * from '@futdevpro/fsm-dynamo/open-ai';
|
|
13
9
|
|
|
@@ -169,7 +169,11 @@ export class DyNTS_Errors_DataService<
|
|
|
169
169
|
DyFM_Log.warn('error saved');
|
|
170
170
|
}
|
|
171
171
|
} catch (error) {
|
|
172
|
-
|
|
172
|
+
if (error instanceof DyFM_Error) {
|
|
173
|
+
error.logSimple('recordError error');
|
|
174
|
+
} else {
|
|
175
|
+
DyFM_Log.error('recordError error:', error);
|
|
176
|
+
}
|
|
173
177
|
/* throw new DyFM_Error({
|
|
174
178
|
...this.getDefaultErrorSettings(
|
|
175
179
|
'recordError',
|
|
@@ -36,7 +36,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
36
36
|
tasks: [
|
|
37
37
|
async () => {
|
|
38
38
|
this._connected = true;
|
|
39
|
-
DyFM_Log.success(`< > socket-client(${this.params.name}) connected!`);
|
|
39
|
+
DyFM_Log.success(`< > socket-client (${this.params.name}) connected!`);
|
|
40
40
|
},
|
|
41
41
|
],
|
|
42
42
|
}),
|
|
@@ -46,7 +46,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
46
46
|
tasks: [
|
|
47
47
|
async () => {
|
|
48
48
|
this._connected = false;
|
|
49
|
-
DyFM_Log.warn(`<x > socket-client(${this.params.name}) disconnected!`);
|
|
49
|
+
DyFM_Log.warn(`<x > socket-client (${this.params.name}) disconnected!`);
|
|
50
50
|
|
|
51
51
|
if (this._params.reconnect) {
|
|
52
52
|
await DyFM_delay(this._params.reconnectDelay);
|
|
@@ -60,7 +60,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
60
60
|
eventKey: DyFM_SocketEvent_Key.subscriptionSuccessful,
|
|
61
61
|
tasks: [
|
|
62
62
|
async () => {
|
|
63
|
-
DyFM_Log.success(`<=--> socket-client(${this.params.name}) subscription successful!`);
|
|
63
|
+
DyFM_Log.success(`<=--> socket-client (${this.params.name}) subscription successful!`);
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
66
|
}),
|
|
@@ -70,9 +70,9 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
70
70
|
tasks: [
|
|
71
71
|
async (content: any) => {
|
|
72
72
|
if (content instanceof DyFM_Error) {
|
|
73
|
-
content.logSimple(`=--> socket-client(${this.params.name}) ERROR`);
|
|
73
|
+
content.logSimple(`=--> socket-client (${this.params.name}) ERROR`);
|
|
74
74
|
} else {
|
|
75
|
-
DyFM_Log.error(`=--> socket-client(${this.params.name}) ERROR:`, content);
|
|
75
|
+
DyFM_Log.error(`=--> socket-client (${this.params.name}) ERROR:`, content);
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
],
|
|
@@ -88,13 +88,13 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
88
88
|
!(error instanceof DyFM_Error)
|
|
89
89
|
) {
|
|
90
90
|
DyFM_Log.H_error(
|
|
91
|
-
`socket-client
|
|
91
|
+
`socket-client (${this.params?.name}) Service setup failed! ` +
|
|
92
92
|
`(DyNTS_SocketClientService constructor catch)`,
|
|
93
93
|
`\n ERROR:`, error
|
|
94
94
|
);
|
|
95
95
|
} else {
|
|
96
96
|
error.logSimple(
|
|
97
|
-
`socket-client
|
|
97
|
+
`socket-client (${this.params?.name}) Service setup failed! ` +
|
|
98
98
|
`(DyNTS_SocketClientService constructor catch)`
|
|
99
99
|
);
|
|
100
100
|
}
|
|
@@ -118,11 +118,11 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
118
118
|
|
|
119
119
|
await this.setupSocketEvents();
|
|
120
120
|
|
|
121
|
-
DyFM_Log.success(`\nsocket-client(${this.params?.name}) Service setup finished`);
|
|
121
|
+
DyFM_Log.success(`\nsocket-client (${this.params?.name}) Service setup finished`);
|
|
122
122
|
|
|
123
123
|
await this.connectSocket();
|
|
124
124
|
} catch (error) {
|
|
125
|
-
DyFM_Log.error(`socket-client(${this.params?.name}) Service setup failed!`, error);
|
|
125
|
+
DyFM_Log.error(`socket-client (${this.params?.name}) Service setup failed!`, error);
|
|
126
126
|
|
|
127
127
|
throw new DyFM_Error({
|
|
128
128
|
errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-SCS-001`,
|
|
@@ -149,7 +149,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
149
149
|
});
|
|
150
150
|
} catch (error) {
|
|
151
151
|
DyFM_Log.error(
|
|
152
|
-
`socket-client(${this.params.name}) Service Setup Default Events failed, ` +
|
|
152
|
+
`socket-client (${this.params.name}) Service Setup Default Events failed, ` +
|
|
153
153
|
`ERROR:`, error
|
|
154
154
|
);
|
|
155
155
|
|
|
@@ -159,7 +159,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
159
159
|
|
|
160
160
|
private async setupSocketEvents(): Promise<void> {
|
|
161
161
|
try {
|
|
162
|
-
if (this.debugLog) console.log(`Setup socket-client(${this.params.name}) Events...`);
|
|
162
|
+
if (this.debugLog) console.log(`Setup socket-client (${this.params.name}) Events...`);
|
|
163
163
|
|
|
164
164
|
await DyFM_Array.asyncForEach(
|
|
165
165
|
this.incomingEvents,
|
|
@@ -169,7 +169,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
169
169
|
try {
|
|
170
170
|
await event.executeEventTasks(content, this.params.service);
|
|
171
171
|
} catch (error) {
|
|
172
|
-
DyFM_Log.error(`socket-client(${this.params.name}) Event failed, ERROR:`, error);
|
|
172
|
+
DyFM_Log.error(`socket-client (${this.params.name}) Event failed, ERROR:`, error);
|
|
173
173
|
await this.emitEvent(DyFM_SocketEvent_Key.error, error);
|
|
174
174
|
}
|
|
175
175
|
});
|
|
@@ -177,7 +177,7 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
177
177
|
);
|
|
178
178
|
} catch (error) {
|
|
179
179
|
DyFM_Log.error(
|
|
180
|
-
`socket-client(${this.params.name}) Service Setup Socket Events failed, ` +
|
|
180
|
+
`socket-client (${this.params.name}) Service Setup Socket Events failed, ` +
|
|
181
181
|
`ERROR:`, error
|
|
182
182
|
);
|
|
183
183
|
|
|
@@ -185,21 +185,22 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
tryingToReconnect = false;
|
|
189
|
+
protected async connectSocket(): Promise<void> {
|
|
189
190
|
try {
|
|
190
191
|
DyFM_Log.info(
|
|
191
|
-
`< .. > socket-client(${this.params.name}) ` +
|
|
192
|
+
`< .. > socket-client (${this.params.name}) ` +
|
|
192
193
|
`connecting to ${this.params.address}:${this.params.port} ...`
|
|
193
194
|
);
|
|
194
195
|
|
|
195
196
|
this.socket.connect();
|
|
196
197
|
|
|
197
|
-
if (this.params.reconnect) {
|
|
198
|
+
if (this.params.reconnect && !this.tryingToReconnect) {
|
|
198
199
|
await this.tryReconnectIfNeeded();
|
|
199
200
|
}
|
|
200
201
|
} catch (error) {
|
|
201
202
|
DyFM_Log.error(
|
|
202
|
-
`socket-client(${this.params.name}) Service Connect Socket failed, ` +
|
|
203
|
+
`socket-client (${this.params.name}) Service Connect Socket failed, ` +
|
|
203
204
|
`ERROR:`, error
|
|
204
205
|
);
|
|
205
206
|
|
|
@@ -210,14 +211,16 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
210
211
|
private async tryReconnectIfNeeded(): Promise<void> {
|
|
211
212
|
try {
|
|
212
213
|
if (this.logFn) console.log(`\nFn:. tryReconnectIfNeeded`);
|
|
214
|
+
this.tryingToReconnect = true;
|
|
213
215
|
await DyFM_delay(this._params.reconnectDelay);
|
|
214
216
|
|
|
217
|
+
this.tryingToReconnect = false;
|
|
215
218
|
if (!this._connected) {
|
|
216
219
|
await this.connectSocket();
|
|
217
220
|
}
|
|
218
221
|
} catch (error) {
|
|
219
222
|
DyFM_Log.error(
|
|
220
|
-
`socket-client(${this.params.name}) Service Try Reconnect failed, ` +
|
|
223
|
+
`socket-client (${this.params.name}) Service Try Reconnect failed, ` +
|
|
221
224
|
`ERROR:`, error
|
|
222
225
|
);
|
|
223
226
|
|
|
@@ -232,11 +235,11 @@ export abstract class DyNTS_SocketClient_ServiceBase extends DyNTS_SingletonServ
|
|
|
232
235
|
*/
|
|
233
236
|
async emitEvent(eventType: string, content: any): Promise<void> {
|
|
234
237
|
try {
|
|
235
|
-
DyFM_Log.log(`<=-- outgoing socket-client(${this.params.name}) event: ${eventType}`);
|
|
238
|
+
DyFM_Log.log(`<=-- outgoing socket-client (${this.params.name}) event: ${eventType}`);
|
|
236
239
|
this.socket.emit(eventType, content);
|
|
237
240
|
} catch (error) {
|
|
238
241
|
DyFM_Log.error(
|
|
239
|
-
`socket-client(${this.params.name}) ` +
|
|
242
|
+
`socket-client (${this.params.name}) ` +
|
|
240
243
|
`Service Emit Event failed: ${this.params?.name} (${this.params?.port})`, error
|
|
241
244
|
);
|
|
242
245
|
|