@futdevpro/nts-dynamo 1.10.23 → 1.10.25
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/oauth2/_routes/oauth2.controller.d.ts +17 -0
- package/build/_modules/oauth2/_routes/oauth2.controller.d.ts.map +1 -0
- package/build/_modules/oauth2/_routes/oauth2.controller.js +97 -0
- package/build/_modules/oauth2/_routes/oauth2.controller.js.map +1 -0
- package/build/_modules/oauth2/_services/oauth2.auth-service.d.ts +31 -0
- package/build/_modules/oauth2/_services/oauth2.auth-service.d.ts.map +1 -0
- package/build/_modules/oauth2/_services/oauth2.auth-service.js +216 -0
- package/build/_modules/oauth2/_services/oauth2.auth-service.js.map +1 -0
- package/build/_modules/oauth2/_services/oauth2.control-service.d.ts +133 -0
- package/build/_modules/oauth2/_services/oauth2.control-service.d.ts.map +1 -0
- package/build/_modules/oauth2/_services/oauth2.control-service.js +574 -0
- package/build/_modules/oauth2/_services/oauth2.control-service.js.map +1 -0
- package/build/_modules/oauth2/index.d.ts +4 -0
- package/build/_modules/oauth2/index.d.ts.map +1 -0
- package/build/_modules/oauth2/index.js +7 -0
- package/build/_modules/oauth2/index.js.map +1 -0
- package/build/_modules/open-ai/_enums/open-ai-model.enum.d.ts +11 -0
- package/build/_modules/open-ai/_enums/open-ai-model.enum.d.ts.map +1 -0
- package/build/_modules/open-ai/_enums/open-ai-model.enum.js +110 -0
- package/build/_modules/open-ai/_enums/open-ai-model.enum.js.map +1 -0
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.d.ts +54 -0
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.js +65 -0
- package/build/_modules/open-ai/_models/gpt-call-settings.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.d.ts +7 -0
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.js +3 -0
- package/build/_modules/open-ai/_models/open-ai-api-env-settings.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/open-ai-settings.interface.d.ts +17 -0
- package/build/_modules/open-ai/_models/open-ai-settings.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/open-ai-settings.interface.js +25 -0
- package/build/_modules/open-ai/_models/open-ai-settings.interface.js.map +1 -0
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts +26 -0
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/embedding.control-service.js +54 -0
- package/build/_modules/open-ai/_services/embedding.control-service.js.map +1 -0
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts +98 -0
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/gpt.service-base.js +284 -0
- package/build/_modules/open-ai/_services/gpt.service-base.js.map +1 -0
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts +23 -0
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/open-ai.service-base.js +50 -0
- package/build/_modules/open-ai/_services/open-ai.service-base.js.map +1 -0
- package/build/_modules/open-ai/index.d.ts +8 -0
- package/build/_modules/open-ai/index.d.ts.map +1 -0
- package/build/_modules/open-ai/index.js +11 -0
- package/build/_modules/open-ai/index.js.map +1 -0
- package/build/_services/base/db.service.d.ts +38 -0
- package/build/_services/base/db.service.d.ts.map +1 -1
- package/build/_services/base/db.service.js +40 -0
- package/build/_services/base/db.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts +17 -0
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +17 -0
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +47 -17
- package/src/_modules/oauth2/_routes/oauth2.controller.ts +99 -0
- package/src/_modules/oauth2/_services/oauth2.auth-service.ts +232 -0
- package/src/_modules/oauth2/_services/oauth2.control-service.ts +651 -0
- package/src/_modules/oauth2/index.ts +9 -0
- package/src/_modules/open-ai/_enums/open-ai-model.enum.ts +137 -0
- package/src/_modules/open-ai/_models/gpt-call-settings.interface.ts +69 -0
- package/src/_modules/open-ai/_models/open-ai-api-env-settings.interface.ts +12 -0
- package/src/_modules/open-ai/_models/open-ai-settings.interface.ts +31 -0
- package/src/_modules/open-ai/_services/embedding.control-service.ts +61 -0
- package/src/_modules/open-ai/_services/gpt.service-base.ts +440 -0
- package/src/_modules/open-ai/_services/open-ai.service-base.ts +73 -0
- package/src/_modules/open-ai/index.ts +13 -0
- package/src/_services/base/db.service.ts +41 -0
- package/src/_services/server/app.server.ts +18 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export enum DyNTS_OpenAIModel {
|
|
7
|
+
// GPT-3.5
|
|
8
|
+
/* gpt35_turbo = 'gpt-3.5-turbo',
|
|
9
|
+
gpt35_turbo0125 = 'gpt-3.5-turbo-0125',
|
|
10
|
+
gpt35_turbo1106 = 'gpt-3.5-turbo-1106',
|
|
11
|
+
gpt35_turbo16k = 'gpt-3.5-turbo-16k',
|
|
12
|
+
gpt35_turboInstruct = 'gpt-3.5-turbo-instruct',
|
|
13
|
+
gpt35_turboInstruct0914 = 'gpt-3.5-turbo-instruct-0914', */
|
|
14
|
+
|
|
15
|
+
// GPT-4
|
|
16
|
+
// gpt-4
|
|
17
|
+
gpt4o = 'gpt-4o',
|
|
18
|
+
// gpt-4o-2024-08-06
|
|
19
|
+
gpt4o_20240806 = 'gpt-4o-2024-08-06',
|
|
20
|
+
// gpt-4o-2024-05-13
|
|
21
|
+
gpt4o_20240513 = 'gpt-4o-2024-05-13',
|
|
22
|
+
|
|
23
|
+
/* gpt4 = 'gpt-4',
|
|
24
|
+
gpt4_0613 = 'gpt-4-0613',
|
|
25
|
+
gpt4_0125Preview = 'gpt-4-0125-preview',
|
|
26
|
+
gpt4_1106Preview = 'gpt-4-1106-preview',
|
|
27
|
+
gpt4_turbo = 'gpt-4-turbo',
|
|
28
|
+
gpt4_turbo20240409 = 'gpt-4-turbo-2024-04-09',
|
|
29
|
+
gpt4_turboPreview = 'gpt-4-turbo-preview', */
|
|
30
|
+
|
|
31
|
+
// GPT-Mini
|
|
32
|
+
// gpt-4o-mini
|
|
33
|
+
gpt4o_mini = 'gpt-4o-mini',
|
|
34
|
+
// gpt-4o-mini-2024-07-18
|
|
35
|
+
gpt4o_mini20240718 = 'gpt-4o-mini-2024-07-18',
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// GPT-4o
|
|
39
|
+
/* gpt4o = 'gpt-4o',
|
|
40
|
+
gpt4o_20240513 = 'gpt-4o-2024-05-13',
|
|
41
|
+
gpt4o_mini = 'gpt-4o-mini',
|
|
42
|
+
gpt4o_mini20240718 = 'gpt-4o-mini-2024-07-18', */
|
|
43
|
+
|
|
44
|
+
// DALL·E
|
|
45
|
+
/* dallE_2 = 'dall-e-2',
|
|
46
|
+
dallE_2_HD = 'dall-e-2',
|
|
47
|
+
dallE_3 = 'dall-e-3',
|
|
48
|
+
dallE_3_HD = 'dall-e-3', */
|
|
49
|
+
|
|
50
|
+
// Text-to-Speech (TTS)
|
|
51
|
+
/* tts1 = 'tts-1',
|
|
52
|
+
tts1_1106 = 'tts-1-1106',
|
|
53
|
+
tts1_HD = 'tts-1-hd',
|
|
54
|
+
tts1_HD_1106 = 'tts-1-hd-1106',
|
|
55
|
+
whisper_1 = 'whisper-1', */
|
|
56
|
+
|
|
57
|
+
// Text Embeddings
|
|
58
|
+
// text-embedding-3-small
|
|
59
|
+
textEmbedding_3Small = 'text-embedding-3-small',
|
|
60
|
+
// text-embedding-3-large
|
|
61
|
+
textEmbedding_3Large = 'text-embedding-3-large',
|
|
62
|
+
// text-embedding-ada-002
|
|
63
|
+
textEmbedding_ada002 = 'text-embedding-ada-002',
|
|
64
|
+
|
|
65
|
+
/* textEmbedding_ada002 = 'text-embedding-ada-002',
|
|
66
|
+
textEmbedding_3Small = 'text-embedding-3-small',
|
|
67
|
+
textEmbedding_3Large = 'text-embedding-3-large', */
|
|
68
|
+
|
|
69
|
+
// Moderation Models
|
|
70
|
+
/* textModeration_007 = 'text-moderation-007',
|
|
71
|
+
textModeration_latest = 'text-moderation-latest',
|
|
72
|
+
textModeration_stable = 'text-moderation-stable', */
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/* davinci002 = 'davinci-002', */
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
/* // GPT-3.5
|
|
88
|
+
gpt35_turbo = 'gpt-3.5-turbo',
|
|
89
|
+
gpt35_turbo0125 = 'gpt-3.5-turbo-0125',
|
|
90
|
+
gpt35_turbo1106 = 'gpt-3.5-turbo-1106',
|
|
91
|
+
gpt35_turbo16k = 'gpt-3.5-turbo-16k',
|
|
92
|
+
gpt35_turboInstruct = 'gpt-3.5-turbo-instruct',
|
|
93
|
+
gpt35_turboInstruct0914 = 'gpt-3.5-turbo-instruct-0914',
|
|
94
|
+
|
|
95
|
+
// GPT-4
|
|
96
|
+
gpt4 = 'gpt-4',
|
|
97
|
+
gpt4_0613 = 'gpt-4-0613',
|
|
98
|
+
gpt4_0125Preview = 'gpt-4-0125-preview',
|
|
99
|
+
gpt4_1106Preview = 'gpt-4-1106-preview',
|
|
100
|
+
gpt4_turbo = 'gpt-4-turbo',
|
|
101
|
+
gpt4_turbo20240409 = 'gpt-4-turbo-2024-04-09',
|
|
102
|
+
gpt4_turboPreview = 'gpt-4-turbo-preview',
|
|
103
|
+
|
|
104
|
+
// GPT-4o
|
|
105
|
+
gpt4o = 'gpt-4o',
|
|
106
|
+
gpt4o_20240513 = 'gpt-4o-2024-05-13',
|
|
107
|
+
gpt4o_mini = 'gpt-4o-mini',
|
|
108
|
+
gpt4o_mini20240718 = 'gpt-4o-mini-2024-07-18',
|
|
109
|
+
|
|
110
|
+
// DALL·E
|
|
111
|
+
dallE_2 = 'dall-e-2',
|
|
112
|
+
dallE_3 = 'dall-e-3',
|
|
113
|
+
|
|
114
|
+
// Text-to-Speech (TTS)
|
|
115
|
+
tts1 = 'tts-1',
|
|
116
|
+
tts1_1106 = 'tts-1-1106',
|
|
117
|
+
tts1_HD = 'tts-1-hd',
|
|
118
|
+
tts1_HD_1106 = 'tts-1-hd-1106',
|
|
119
|
+
whisper_1 = 'whisper-1',
|
|
120
|
+
|
|
121
|
+
// Text Embeddings
|
|
122
|
+
textEmbedding_ada002 = 'text-embedding-ada-002',
|
|
123
|
+
textEmbedding_3Small = 'text-embedding-3-small',
|
|
124
|
+
textEmbedding_3Large = 'text-embedding-3-large',
|
|
125
|
+
|
|
126
|
+
// Moderation Models
|
|
127
|
+
textModeration_007 = 'text-moderation-007',
|
|
128
|
+
textModeration_latest = 'text-moderation-latest',
|
|
129
|
+
textModeration_stable = 'text-moderation-stable',
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
davinci002 = 'davinci-002', */
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { ClientOptions } from 'openai';
|
|
4
|
+
import { DyNTS_OpenAIModel } from '../_enums/open-ai-model.enum';
|
|
5
|
+
|
|
6
|
+
export class DyNTS_GPTCall_Settings {
|
|
7
|
+
systemPrompt?: string = '';
|
|
8
|
+
useModel?: DyNTS_OpenAIModel | string = DyNTS_OpenAIModel.gpt4o;
|
|
9
|
+
gptProject?: string;
|
|
10
|
+
debugLog?: boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This parameter controls the randomness and creativity of the generated output.
|
|
14
|
+
*
|
|
15
|
+
* Lower values (e.g., 0.2) produce more focused, predictable results,
|
|
16
|
+
* while higher values (e.g., 0.8) introduce more variation and unexpected outputs,
|
|
17
|
+
* making the model more creative and exploratory.
|
|
18
|
+
*
|
|
19
|
+
* Adjust this setting to balance between creativity and consistency.
|
|
20
|
+
*/
|
|
21
|
+
temperature?: number = 0.5;
|
|
22
|
+
/**
|
|
23
|
+
* Defines the upper limit of tokens (words or parts of words)
|
|
24
|
+
* the model can generate in a single response.
|
|
25
|
+
*
|
|
26
|
+
* The total token count includes both the input (prompt) and the output (response).
|
|
27
|
+
*
|
|
28
|
+
* You can allocate up to 4096 tokens per request, but be mindful of prompt length,
|
|
29
|
+
* as it affects how many tokens remain for the response.
|
|
30
|
+
*/
|
|
31
|
+
maxTokens?: number = 2000;
|
|
32
|
+
/**
|
|
33
|
+
* This parameter adjusts the diversity of the output using nucleus sampling,
|
|
34
|
+
* where the model considers tokens based on cumulative probability.
|
|
35
|
+
*
|
|
36
|
+
* A value of 0.5 ensures that only the most likely half of all possible tokens
|
|
37
|
+
* are considered, while increasing the value (up to 1)
|
|
38
|
+
* allows for a broader range of token options, leading to more varied responses.
|
|
39
|
+
*/
|
|
40
|
+
topP?: number = 0.75;
|
|
41
|
+
/**
|
|
42
|
+
* This setting penalizes tokens that have already appeared frequently in the generated text,
|
|
43
|
+
* discouraging repetition and encouraging the model to introduce new content.
|
|
44
|
+
*
|
|
45
|
+
* Higher values result in less repetition, making the output more diverse.
|
|
46
|
+
*/
|
|
47
|
+
frequencyPenalty?: number = 0;
|
|
48
|
+
/**
|
|
49
|
+
* This parameter influences the model by penalizing tokens based on
|
|
50
|
+
* their presence in the text so far.
|
|
51
|
+
*
|
|
52
|
+
* It encourages the introduction of new topics or ideas by reducing the likelihood of
|
|
53
|
+
* generating tokens that have already appeared,
|
|
54
|
+
* helping to keep the conversation or text more varied and engaging.
|
|
55
|
+
*/
|
|
56
|
+
presencePenalty?: number = 0;
|
|
57
|
+
|
|
58
|
+
/* organizationId?: string;
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
project?: string; */
|
|
61
|
+
|
|
62
|
+
constructor(
|
|
63
|
+
set?: DyNTS_GPTCall_Settings
|
|
64
|
+
) {
|
|
65
|
+
if (set) {
|
|
66
|
+
Object.assign(this, set);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { ClientOptions } from 'openai';
|
|
4
|
+
import { DyNTS_OpenAIModel } from '../_enums/open-ai-model.enum';
|
|
5
|
+
import { DyNTS_GPTCall_Settings } from './gpt-call-settings.interface';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class DyNTS_OpenAI_Settings {
|
|
9
|
+
/**
|
|
10
|
+
* OpenAI API configuration.
|
|
11
|
+
*
|
|
12
|
+
* apiKey, organization and project are required.
|
|
13
|
+
* they are defaults to
|
|
14
|
+
* process.env['OPENAI_API_KEY'],
|
|
15
|
+
* process.env['OPENAI_ORG_ID'] and
|
|
16
|
+
* process.env['OPENAI_PROJECT_ID']
|
|
17
|
+
*/
|
|
18
|
+
openAIConfig: ClientOptions;
|
|
19
|
+
/* systemPrompt?: string;
|
|
20
|
+
useModel?: string | DyNTS_OpenAIModel = DyNTS_OpenAIModel.gpt4o; */
|
|
21
|
+
|
|
22
|
+
defaultSettings: DyNTS_GPTCall_Settings;
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
set: DyNTS_OpenAI_Settings
|
|
26
|
+
) {
|
|
27
|
+
if (set) {
|
|
28
|
+
Object.assign(this, set);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
|
|
3
|
+
import { DyNTS_SingletonService } from '../../../_services/base/singleton.service';
|
|
4
|
+
import { DyNTS_OpenAIModel } from '../_enums/open-ai-model.enum';
|
|
5
|
+
import { DyNTS_OpenAI_ServiceBase } from './open-ai.service-base';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Service for handling OpenAI text embeddings
|
|
9
|
+
* @class Embedding_ControlService
|
|
10
|
+
* @extends DyNTS_OpenAI_ServiceBase
|
|
11
|
+
*/
|
|
12
|
+
export class Embedding_ControlService extends DyNTS_OpenAI_ServiceBase {
|
|
13
|
+
|
|
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
|
+
async createEmbedding(
|
|
22
|
+
text: string,
|
|
23
|
+
model: DyNTS_OpenAIModel = DyNTS_OpenAIModel.textEmbedding_3Large
|
|
24
|
+
): Promise<number[]> {
|
|
25
|
+
try {
|
|
26
|
+
const response = await this.openai.embeddings.create({
|
|
27
|
+
model,
|
|
28
|
+
input: text,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return response.data[0].embedding;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error('Error creating embedding:', error);
|
|
34
|
+
throw new Error('Failed to create embedding');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
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
|
+
async createEmbeddings(
|
|
46
|
+
texts: string[],
|
|
47
|
+
model: DyNTS_OpenAIModel = DyNTS_OpenAIModel.textEmbedding_3Large
|
|
48
|
+
): Promise<number[][]> {
|
|
49
|
+
try {
|
|
50
|
+
const response = await this.openai.embeddings.create({
|
|
51
|
+
model,
|
|
52
|
+
input: texts,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return response.data.map(item => item.embedding);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Error creating embeddings:', error);
|
|
58
|
+
throw new Error('Failed to create embeddings');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|