@drax/ai-back 3.40.0 → 3.42.0
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/dist/agents/DraxAgent.js +1 -1
- package/dist/config/DeepSeekConfig.js +9 -0
- package/dist/config/ElevenLabsTTSConfig.js +10 -0
- package/dist/controllers/AICrudController.js +1 -1
- package/dist/controllers/AIGenericController.js +1 -1
- package/dist/controllers/TTSGenericController.js +61 -0
- package/dist/factory/AiProviderFactory.js +4 -0
- package/dist/factory/DeepSeekProviderFactory.js +14 -0
- package/dist/factory/ElevenLabsTTSProviderFactory.js +13 -0
- package/dist/factory/TTSProviderFactory.js +27 -0
- package/dist/factory/ai/AiProviderFactory.js +30 -0
- package/dist/factory/ai/DeepSeekAiProviderFactory.js +14 -0
- package/dist/factory/ai/GoogleAiProviderFactory.js +14 -0
- package/dist/factory/ai/OllamaAiProviderFactory.js +14 -0
- package/dist/factory/ai/OpenAiProviderFactory.js +14 -0
- package/dist/factory/tts/ElevenLabsTTSProviderFactory.js +13 -0
- package/dist/factory/tts/TTSProviderFactory.js +27 -0
- package/dist/index.js +23 -11
- package/dist/interfaces/ITTSProvider.js +1 -0
- package/dist/permissions/TTSPermissions.js +6 -0
- package/dist/providers/DeepSeekProvider.js +34 -0
- package/dist/providers/ElevenLabsTTSProvider.js +108 -0
- package/dist/providers/ai/DeepSeekAiProvider.js +34 -0
- package/dist/providers/ai/GoogleAiProvider.js +367 -0
- package/dist/providers/ai/OllamaAiProvider.js +342 -0
- package/dist/providers/ai/OpenAiProvider.js +302 -0
- package/dist/providers/tts/ElevenLabsTTSProvider.js +108 -0
- package/dist/routes/TTSRoutes.js +8 -0
- package/dist/schemas/TTSRequestSchema.js +24 -0
- package/dist/services/TTSGenericService.js +21 -0
- package/package.json +2 -2
- package/src/agents/DraxAgent.ts +1 -1
- package/src/config/DeepSeekConfig.ts +14 -0
- package/src/config/ElevenLabsTTSConfig.ts +13 -0
- package/src/controllers/AICrudController.ts +1 -1
- package/src/controllers/AIGenericController.ts +1 -1
- package/src/controllers/TTSGenericController.ts +70 -0
- package/src/factory/{AiProviderFactory.ts → ai/AiProviderFactory.ts} +5 -1
- package/src/factory/ai/DeepSeekAiProviderFactory.ts +27 -0
- package/src/factory/{GoogleAiProviderFactory.ts → ai/GoogleAiProviderFactory.ts} +4 -4
- package/src/factory/{OllamaAiProviderFactory.ts → ai/OllamaAiProviderFactory.ts} +4 -4
- package/src/factory/{OpenAiProviderFactory.ts → ai/OpenAiProviderFactory.ts} +4 -4
- package/src/factory/tts/ElevenLabsTTSProviderFactory.ts +26 -0
- package/src/factory/tts/TTSProviderFactory.ts +42 -0
- package/src/index.ts +54 -7
- package/src/interfaces/ITTSProvider.ts +47 -0
- package/src/permissions/AIPermissions.ts +0 -1
- package/src/permissions/TTSPermissions.ts +8 -0
- package/src/providers/ai/DeepSeekAiProvider.ts +58 -0
- package/src/providers/{GoogleAiProvider.ts → ai/GoogleAiProvider.ts} +2 -2
- package/src/providers/{OllamaAiProvider.ts → ai/OllamaAiProvider.ts} +2 -2
- package/src/providers/{OpenAiProvider.ts → ai/OpenAiProvider.ts} +2 -2
- package/src/providers/tts/ElevenLabsTTSProvider.ts +132 -0
- package/src/routes/TTSRoutes.ts +13 -0
- package/src/schemas/TTSRequestSchema.ts +38 -0
- package/src/services/TTSGenericService.ts +41 -0
- package/test/DeepSeekProvider.test.ts +146 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/types/config/DeepSeekConfig.d.ts +9 -0
- package/types/config/DeepSeekConfig.d.ts.map +1 -0
- package/types/config/ElevenLabsTTSConfig.d.ts +10 -0
- package/types/config/ElevenLabsTTSConfig.d.ts.map +1 -0
- package/types/controllers/TTSGenericController.d.ts +11 -0
- package/types/controllers/TTSGenericController.d.ts.map +1 -0
- package/types/factory/AiProviderFactory.d.ts.map +1 -1
- package/types/factory/DeepSeekProviderFactory.d.ts +8 -0
- package/types/factory/DeepSeekProviderFactory.d.ts.map +1 -0
- package/types/factory/ElevenLabsTTSProviderFactory.d.ts +8 -0
- package/types/factory/ElevenLabsTTSProviderFactory.d.ts.map +1 -0
- package/types/factory/TTSProviderFactory.d.ts +15 -0
- package/types/factory/TTSProviderFactory.d.ts.map +1 -0
- package/types/factory/ai/AiProviderFactory.d.ts +8 -0
- package/types/factory/ai/AiProviderFactory.d.ts.map +1 -0
- package/types/factory/ai/DeepSeekAiProviderFactory.d.ts +8 -0
- package/types/factory/ai/DeepSeekAiProviderFactory.d.ts.map +1 -0
- package/types/factory/ai/GoogleAiProviderFactory.d.ts +8 -0
- package/types/factory/ai/GoogleAiProviderFactory.d.ts.map +1 -0
- package/types/factory/ai/OllamaAiProviderFactory.d.ts +8 -0
- package/types/factory/ai/OllamaAiProviderFactory.d.ts.map +1 -0
- package/types/factory/ai/OpenAiProviderFactory.d.ts +8 -0
- package/types/factory/ai/OpenAiProviderFactory.d.ts.map +1 -0
- package/types/factory/tts/ElevenLabsTTSProviderFactory.d.ts +8 -0
- package/types/factory/tts/ElevenLabsTTSProviderFactory.d.ts.map +1 -0
- package/types/factory/tts/TTSProviderFactory.d.ts +15 -0
- package/types/factory/tts/TTSProviderFactory.d.ts.map +1 -0
- package/types/index.d.ts +28 -6
- package/types/index.d.ts.map +1 -1
- package/types/interfaces/ITTSProvider.d.ts +39 -0
- package/types/interfaces/ITTSProvider.d.ts.map +1 -0
- package/types/permissions/TTSPermissions.d.ts +6 -0
- package/types/permissions/TTSPermissions.d.ts.map +1 -0
- package/types/providers/DeepSeekProvider.d.ts +24 -0
- package/types/providers/DeepSeekProvider.d.ts.map +1 -0
- package/types/providers/ElevenLabsTTSProvider.d.ts +38 -0
- package/types/providers/ElevenLabsTTSProvider.d.ts.map +1 -0
- package/types/providers/ai/DeepSeekAiProvider.d.ts +24 -0
- package/types/providers/ai/DeepSeekAiProvider.d.ts.map +1 -0
- package/types/providers/ai/GoogleAiProvider.d.ts +63 -0
- package/types/providers/ai/GoogleAiProvider.d.ts.map +1 -0
- package/types/providers/ai/OllamaAiProvider.d.ts +78 -0
- package/types/providers/ai/OllamaAiProvider.d.ts.map +1 -0
- package/types/providers/ai/OpenAiProvider.d.ts +97 -0
- package/types/providers/ai/OpenAiProvider.d.ts.map +1 -0
- package/types/providers/tts/ElevenLabsTTSProvider.d.ts +38 -0
- package/types/providers/tts/ElevenLabsTTSProvider.d.ts.map +1 -0
- package/types/routes/TTSRoutes.d.ts +4 -0
- package/types/routes/TTSRoutes.d.ts.map +1 -0
- package/types/schemas/TTSRequestSchema.d.ts +37 -0
- package/types/schemas/TTSRequestSchema.d.ts.map +1 -0
- package/types/services/TTSGenericService.d.ts +17 -0
- package/types/services/TTSGenericService.d.ts.map +1 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {DraxConfig} from "@drax/common-back";
|
|
2
|
-
import OllamaAiConfig from "
|
|
3
|
-
import type {IAIProvider} from "
|
|
4
|
-
import OllamaAiProvider from "
|
|
5
|
-
import AILogServiceFactory from "
|
|
2
|
+
import OllamaAiConfig from "../../config/OllamaAiConfig.js";
|
|
3
|
+
import type {IAIProvider} from "../../interfaces/IAIProvider.js"
|
|
4
|
+
import OllamaAiProvider from "../../providers/ai/OllamaAiProvider.js";
|
|
5
|
+
import AILogServiceFactory from "../services/AILogServiceFactory.js";
|
|
6
6
|
|
|
7
7
|
class OllamaAiProviderFactory {
|
|
8
8
|
private static singleton: IAIProvider;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {DraxConfig} from "@drax/common-back";
|
|
2
|
-
import OpenAiConfig from "
|
|
3
|
-
import type {IAIProvider} from "
|
|
4
|
-
import OpenAiProvider from "
|
|
5
|
-
import AILogServiceFactory from "
|
|
2
|
+
import OpenAiConfig from "../../config/OpenAiConfig.js";
|
|
3
|
+
import type {IAIProvider} from "../../interfaces/IAIProvider.js"
|
|
4
|
+
import OpenAiProvider from "../../providers/ai/OpenAiProvider.js";
|
|
5
|
+
import AILogServiceFactory from "../services/AILogServiceFactory.js";
|
|
6
6
|
|
|
7
7
|
class OpenAiProviderFactory {
|
|
8
8
|
private static singleton: IAIProvider;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {DraxConfig} from "@drax/common-back";
|
|
2
|
+
import ElevenLabsTTSConfig from "../../config/ElevenLabsTTSConfig.js";
|
|
3
|
+
import type {ITTSProvider} from "../../interfaces/ITTSProvider.js";
|
|
4
|
+
import ElevenLabsTTSProvider from "../../providers/tts/ElevenLabsTTSProvider.js";
|
|
5
|
+
|
|
6
|
+
class ElevenLabsTTSProviderFactory {
|
|
7
|
+
private static singleton: ITTSProvider;
|
|
8
|
+
|
|
9
|
+
public static instance(): ITTSProvider {
|
|
10
|
+
if (!ElevenLabsTTSProviderFactory.singleton) {
|
|
11
|
+
ElevenLabsTTSProviderFactory.singleton = new ElevenLabsTTSProvider(
|
|
12
|
+
DraxConfig.getOrLoad(ElevenLabsTTSConfig.ElevenLabsApiKey),
|
|
13
|
+
DraxConfig.getOrLoad(ElevenLabsTTSConfig.ElevenLabsModel, "string", "eleven_multilingual_v2"),
|
|
14
|
+
DraxConfig.getOrLoad(ElevenLabsTTSConfig.ElevenLabsVoiceId),
|
|
15
|
+
DraxConfig.getOrLoad(ElevenLabsTTSConfig.ElevenLabsBaseUrl, "string", "https://api.elevenlabs.io"),
|
|
16
|
+
DraxConfig.getOrLoad(ElevenLabsTTSConfig.ElevenLabsOutputFormat, "string", "mp3_44100_128"),
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return ElevenLabsTTSProviderFactory.singleton;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default ElevenLabsTTSProviderFactory
|
|
24
|
+
export {
|
|
25
|
+
ElevenLabsTTSProviderFactory
|
|
26
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type {ITTSProvider} from "../../interfaces/ITTSProvider.js";
|
|
2
|
+
import ElevenLabsTTSProviderFactory from "./ElevenLabsTTSProviderFactory.js";
|
|
3
|
+
|
|
4
|
+
type TTSProviderInfo = {
|
|
5
|
+
name: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class TTSProviderFactory {
|
|
10
|
+
private static singletons: Record<string, ITTSProvider> = {};
|
|
11
|
+
private static providers: TTSProviderInfo[] = [
|
|
12
|
+
{
|
|
13
|
+
name: "ElevenLabs",
|
|
14
|
+
label: "ElevenLabs",
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
public static availableProviders(): TTSProviderInfo[] {
|
|
19
|
+
return TTSProviderFactory.providers
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static instance(provider: string = "ElevenLabs"): ITTSProvider {
|
|
23
|
+
if (!TTSProviderFactory.singletons[provider]) {
|
|
24
|
+
switch (provider) {
|
|
25
|
+
case "ElevenLabs":
|
|
26
|
+
TTSProviderFactory.singletons[provider] = ElevenLabsTTSProviderFactory.instance()
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(`Unsupported TTS provider: ${provider}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return TTSProviderFactory.singletons[provider];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default TTSProviderFactory
|
|
37
|
+
export {
|
|
38
|
+
TTSProviderFactory
|
|
39
|
+
}
|
|
40
|
+
export type {
|
|
41
|
+
TTSProviderInfo,
|
|
42
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
import {OpenAiConfig} from "./config/OpenAiConfig.js";
|
|
2
2
|
import {GoogleAiConfig} from "./config/GoogleAiConfig.js";
|
|
3
3
|
import {OllamaAiConfig} from "./config/OllamaAiConfig.js";
|
|
4
|
+
import {DeepSeekConfig} from "./config/DeepSeekConfig.js";
|
|
5
|
+
import {ElevenLabsTTSConfig} from "./config/ElevenLabsTTSConfig.js";
|
|
4
6
|
import {AILogSchema, AILogBaseSchema} from "./schemas/AILogSchema.js";
|
|
7
|
+
import {TTSRequestSchema, TTSVoiceSettingsSchema} from "./schemas/TTSRequestSchema.js";
|
|
5
8
|
import AILogModel from "./models/AILogModel.js";
|
|
6
9
|
import AILogMongoRepository from "./repository/mongo/AILogMongoRepository.js";
|
|
7
10
|
import AILogSqliteRepository from "./repository/sqlite/AILogSqliteRepository.js";
|
|
8
|
-
import {OpenAiProviderFactory} from "./factory/OpenAiProviderFactory.js";
|
|
9
|
-
import {GoogleAiProviderFactory} from "./factory/GoogleAiProviderFactory.js";
|
|
10
|
-
import {OllamaAiProviderFactory} from "./factory/OllamaAiProviderFactory.js";
|
|
11
|
-
import {
|
|
11
|
+
import {OpenAiProviderFactory} from "./factory/ai/OpenAiProviderFactory.js";
|
|
12
|
+
import {GoogleAiProviderFactory} from "./factory/ai/GoogleAiProviderFactory.js";
|
|
13
|
+
import {OllamaAiProviderFactory} from "./factory/ai/OllamaAiProviderFactory.js";
|
|
14
|
+
import {DeepSeekAiProviderFactory} from "./factory/ai/DeepSeekAiProviderFactory.js";
|
|
15
|
+
import {AiProviderFactory} from "./factory/ai/AiProviderFactory.js";
|
|
16
|
+
import {ElevenLabsTTSProviderFactory} from "./factory/tts/ElevenLabsTTSProviderFactory.js";
|
|
17
|
+
import {TTSProviderFactory} from "./factory/tts/TTSProviderFactory.js";
|
|
18
|
+
import type {TTSProviderInfo} from "./factory/tts/TTSProviderFactory.js";
|
|
12
19
|
import {DraxAgentFactory} from "./factory/DraxAgentFactory.js";
|
|
13
20
|
import AILogServiceFactory from "./factory/services/AILogServiceFactory.js";
|
|
14
|
-
import {OpenAiProvider} from "./providers/OpenAiProvider.js";
|
|
15
|
-
import {GoogleAiProvider} from "./providers/GoogleAiProvider.js";
|
|
16
|
-
import {OllamaAiProvider} from "./providers/OllamaAiProvider.js";
|
|
21
|
+
import {OpenAiProvider} from "./providers/ai/OpenAiProvider.js";
|
|
22
|
+
import {GoogleAiProvider} from "./providers/ai/GoogleAiProvider.js";
|
|
23
|
+
import {OllamaAiProvider} from "./providers/ai/OllamaAiProvider.js";
|
|
24
|
+
import {DeepSeekAiProvider} from "./providers/ai/DeepSeekAiProvider.js";
|
|
25
|
+
import {ElevenLabsTTSProvider} from "./providers/tts/ElevenLabsTTSProvider.js";
|
|
17
26
|
import {BuilderTool} from "./tools/BuilderTool.js";
|
|
18
27
|
import {KnowledgeService} from "./services/KnowledgeService.js";
|
|
19
28
|
import {AILogService} from "./services/AILogService.js";
|
|
29
|
+
import {TTSGenericService} from "./services/TTSGenericService.js";
|
|
20
30
|
import AILogPermissions from "./permissions/AILogPermissions.js";
|
|
21
31
|
import AgentPermissions from "./permissions/AgentPermissions.js";
|
|
22
32
|
import AgentSessionPermissions from "./permissions/AgentSessionPermissions.js";
|
|
23
33
|
import AIPermissions from "./permissions/AIPermissions.js";
|
|
34
|
+
import TTSPermissions from "./permissions/TTSPermissions.js";
|
|
24
35
|
import AILogController from "./controllers/AILogController.js";
|
|
25
36
|
import AICrudController from "./controllers/AICrudController.js";
|
|
26
37
|
import AIGenericController from "./controllers/AIGenericController.js";
|
|
38
|
+
import TTSGenericController from "./controllers/TTSGenericController.js";
|
|
27
39
|
import DraxAgentController from "./controllers/DraxAgentController.js";
|
|
28
40
|
import AgentSessionController from "./controllers/AgentSessionController.js";
|
|
29
41
|
import AILogRoutes from "./routes/AILogRoutes.js";
|
|
30
42
|
import AIRoutes from "./routes/AIRoutes.js";
|
|
43
|
+
import TTSRoutes from "./routes/TTSRoutes.js";
|
|
31
44
|
import DraxAgentRoutes from "./routes/DraxAgentRoutes.js";
|
|
32
45
|
import AgentSessionRoutes from "./routes/AgentSessionRoutes.js";
|
|
33
46
|
import {DraxAgent} from "./agents/DraxAgent.js";
|
|
@@ -45,6 +58,19 @@ import type {
|
|
|
45
58
|
IPromptResponse,
|
|
46
59
|
IPromptTool
|
|
47
60
|
} from "./interfaces/IAIProvider.js";
|
|
61
|
+
import type {
|
|
62
|
+
ITTSParams,
|
|
63
|
+
ITTSProvider,
|
|
64
|
+
ITTSResponse,
|
|
65
|
+
ITTSVoiceSettings,
|
|
66
|
+
} from "./interfaces/ITTSProvider.js";
|
|
67
|
+
import type {
|
|
68
|
+
TTSRequest,
|
|
69
|
+
TTSVoiceSettings,
|
|
70
|
+
} from "./schemas/TTSRequestSchema.js";
|
|
71
|
+
import type {
|
|
72
|
+
TTSRequestContext,
|
|
73
|
+
} from "./services/TTSGenericService.js";
|
|
48
74
|
import type {
|
|
49
75
|
ToolBuilderMethod,
|
|
50
76
|
ToolBuilderOptions,
|
|
@@ -83,6 +109,14 @@ export type {
|
|
|
83
109
|
IPromptContentPartImage,
|
|
84
110
|
IPromptContentPartText,
|
|
85
111
|
IPromptResponse,
|
|
112
|
+
ITTSProvider,
|
|
113
|
+
ITTSParams,
|
|
114
|
+
ITTSResponse,
|
|
115
|
+
ITTSVoiceSettings,
|
|
116
|
+
TTSRequest,
|
|
117
|
+
TTSVoiceSettings,
|
|
118
|
+
TTSRequestContext,
|
|
119
|
+
TTSProviderInfo,
|
|
86
120
|
ToolBuilderMethod,
|
|
87
121
|
ToolBuilderOptions,
|
|
88
122
|
ToolBuilderService,
|
|
@@ -104,38 +138,51 @@ export {
|
|
|
104
138
|
OpenAiConfig,
|
|
105
139
|
GoogleAiConfig,
|
|
106
140
|
OllamaAiConfig,
|
|
141
|
+
DeepSeekConfig,
|
|
142
|
+
ElevenLabsTTSConfig,
|
|
107
143
|
AILogSchema,
|
|
108
144
|
AILogBaseSchema,
|
|
145
|
+
TTSRequestSchema,
|
|
146
|
+
TTSVoiceSettingsSchema,
|
|
109
147
|
AILogModel,
|
|
110
148
|
AILogMongoRepository,
|
|
111
149
|
AILogSqliteRepository,
|
|
112
150
|
OpenAiProviderFactory,
|
|
113
151
|
GoogleAiProviderFactory,
|
|
114
152
|
OllamaAiProviderFactory,
|
|
153
|
+
DeepSeekAiProviderFactory,
|
|
115
154
|
AiProviderFactory,
|
|
155
|
+
ElevenLabsTTSProviderFactory,
|
|
156
|
+
TTSProviderFactory,
|
|
116
157
|
DraxAgentFactory,
|
|
117
158
|
AILogServiceFactory,
|
|
118
159
|
OpenAiProvider,
|
|
119
160
|
GoogleAiProvider,
|
|
120
161
|
OllamaAiProvider,
|
|
162
|
+
DeepSeekAiProvider,
|
|
163
|
+
ElevenLabsTTSProvider,
|
|
121
164
|
BuilderTool,
|
|
122
165
|
//Service
|
|
123
166
|
KnowledgeService,
|
|
124
167
|
AILogService,
|
|
168
|
+
TTSGenericService,
|
|
125
169
|
//Permissions
|
|
126
170
|
AILogPermissions,
|
|
127
171
|
AgentPermissions,
|
|
128
172
|
AIPermissions,
|
|
173
|
+
TTSPermissions,
|
|
129
174
|
AgentSessionPermissions,
|
|
130
175
|
//Controllers
|
|
131
176
|
AILogController,
|
|
132
177
|
AICrudController,
|
|
133
178
|
AIGenericController,
|
|
179
|
+
TTSGenericController,
|
|
134
180
|
DraxAgentController,
|
|
135
181
|
AgentSessionController,
|
|
136
182
|
DraxAgent,
|
|
137
183
|
AILogRoutes,
|
|
138
184
|
AIRoutes,
|
|
185
|
+
TTSRoutes,
|
|
139
186
|
DraxAgentRoutes,
|
|
140
187
|
AgentSessionRoutes
|
|
141
188
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
interface ITTSVoiceSettings {
|
|
2
|
+
stability?: number;
|
|
3
|
+
similarityBoost?: number;
|
|
4
|
+
style?: number;
|
|
5
|
+
useSpeakerBoost?: boolean;
|
|
6
|
+
speed?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ITTSParams {
|
|
10
|
+
text: string;
|
|
11
|
+
voiceId?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
outputFormat?: string;
|
|
14
|
+
voiceSettings?: ITTSVoiceSettings;
|
|
15
|
+
previousText?: string;
|
|
16
|
+
nextText?: string;
|
|
17
|
+
languageCode?: string;
|
|
18
|
+
seed?: number;
|
|
19
|
+
operationTitle?: string;
|
|
20
|
+
operationGroup?: string;
|
|
21
|
+
ip?: string;
|
|
22
|
+
userAgent?: string;
|
|
23
|
+
tenant?: string | null;
|
|
24
|
+
user?: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ITTSResponse {
|
|
28
|
+
audio: Buffer;
|
|
29
|
+
contentType: string;
|
|
30
|
+
size: number;
|
|
31
|
+
time: number;
|
|
32
|
+
provider: string;
|
|
33
|
+
model: string;
|
|
34
|
+
voiceId: string;
|
|
35
|
+
outputFormat?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface ITTSProvider {
|
|
39
|
+
textToSpeech(input: ITTSParams): Promise<ITTSResponse>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type {
|
|
43
|
+
ITTSProvider,
|
|
44
|
+
ITTSParams,
|
|
45
|
+
ITTSResponse,
|
|
46
|
+
ITTSVoiceSettings,
|
|
47
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import type {IAILogBase} from "@drax/ai-share";
|
|
3
|
+
import type {IPromptParams} from "../../interfaces/IAIProvider.js";
|
|
4
|
+
import type {AILogService} from "../../services/AILogService.js";
|
|
5
|
+
import OpenAiProvider from "./OpenAiProvider.js";
|
|
6
|
+
|
|
7
|
+
class DeepSeekAiProvider extends OpenAiProvider{
|
|
8
|
+
protected _baseUrl: string
|
|
9
|
+
|
|
10
|
+
constructor(apiKey: string, model: string, baseUrl: string = "https://api.deepseek.com", visionModel?: string, aiLogService?: AILogService) {
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
throw new Error("DeepSeek apiKey required")
|
|
13
|
+
}
|
|
14
|
+
if (!model) {
|
|
15
|
+
throw new Error("DeepSeek model required")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
super(apiKey, model, visionModel, aiLogService)
|
|
19
|
+
|
|
20
|
+
if (!baseUrl) {
|
|
21
|
+
throw new Error("DeepSeek baseUrl required")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this._baseUrl = baseUrl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get client(){
|
|
28
|
+
if(!this._client){
|
|
29
|
+
this._client = new OpenAI({
|
|
30
|
+
apiKey: this._apiKey,
|
|
31
|
+
baseURL: this._baseUrl,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return this._client
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected buildLogPayload(input: IPromptParams, params: {
|
|
39
|
+
model: string,
|
|
40
|
+
systemPrompt: string,
|
|
41
|
+
startedAt: Date,
|
|
42
|
+
endedAt?: Date,
|
|
43
|
+
inputTokens?: number,
|
|
44
|
+
outputTokens?: number,
|
|
45
|
+
tokens?: number,
|
|
46
|
+
output?: unknown,
|
|
47
|
+
success: boolean,
|
|
48
|
+
errorMessage?: string,
|
|
49
|
+
}): IAILogBase {
|
|
50
|
+
return {
|
|
51
|
+
...super.buildLogPayload(input, params),
|
|
52
|
+
provider: "deepseek",
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default DeepSeekAiProvider
|
|
58
|
+
export {DeepSeekAiProvider}
|
|
@@ -14,8 +14,8 @@ import type {
|
|
|
14
14
|
IPromptParams,
|
|
15
15
|
IPromptResponse,
|
|
16
16
|
IPromptTool
|
|
17
|
-
} from "
|
|
18
|
-
import type {AILogService} from "
|
|
17
|
+
} from "../../interfaces/IAIProvider.js";
|
|
18
|
+
import type {AILogService} from "../../services/AILogService.js";
|
|
19
19
|
import type {IAILogBase} from "@drax/ai-share";
|
|
20
20
|
|
|
21
21
|
class GoogleAiProvider implements IAIProvider{
|
|
@@ -6,8 +6,8 @@ import type {
|
|
|
6
6
|
IPromptParams,
|
|
7
7
|
IPromptResponse,
|
|
8
8
|
IPromptTool
|
|
9
|
-
} from "
|
|
10
|
-
import type {AILogService} from "
|
|
9
|
+
} from "../../interfaces/IAIProvider.js";
|
|
10
|
+
import type {AILogService} from "../../services/AILogService.js";
|
|
11
11
|
import type {IAILogBase} from "@drax/ai-share";
|
|
12
12
|
|
|
13
13
|
type OllamaMessage = {
|
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
IPromptParams,
|
|
8
8
|
IPromptResponse,
|
|
9
9
|
IPromptTool
|
|
10
|
-
} from "
|
|
11
|
-
import type {AILogService} from "
|
|
10
|
+
} from "../../interfaces/IAIProvider.js";
|
|
11
|
+
import type {AILogService} from "../../services/AILogService.js";
|
|
12
12
|
import type {IAILogBase} from "@drax/ai-share";
|
|
13
13
|
|
|
14
14
|
class OpenAiProvider implements IAIProvider{
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type {ITTSParams, ITTSProvider, ITTSResponse} from "../../interfaces/ITTSProvider.js";
|
|
2
|
+
|
|
3
|
+
class ElevenLabsTTSProvider implements ITTSProvider {
|
|
4
|
+
protected _apiKey: string
|
|
5
|
+
protected _baseUrl: string
|
|
6
|
+
protected _model: string
|
|
7
|
+
protected _voiceId: string
|
|
8
|
+
protected _outputFormat?: string
|
|
9
|
+
|
|
10
|
+
constructor(apiKey: string, model: string, voiceId: string, baseUrl: string = "https://api.elevenlabs.io", outputFormat?: string) {
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
throw new Error("ElevenLabs apiKey required")
|
|
13
|
+
}
|
|
14
|
+
if (!model) {
|
|
15
|
+
throw new Error("ElevenLabs model required")
|
|
16
|
+
}
|
|
17
|
+
if (!voiceId) {
|
|
18
|
+
throw new Error("ElevenLabs voiceId required")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
this._apiKey = apiKey
|
|
22
|
+
this._model = model
|
|
23
|
+
this._voiceId = voiceId
|
|
24
|
+
this._baseUrl = baseUrl.replace(/\/+$/, "")
|
|
25
|
+
this._outputFormat = outputFormat
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get model() {
|
|
29
|
+
if (!this._model) {
|
|
30
|
+
throw new Error("ElevenLabs model not found")
|
|
31
|
+
}
|
|
32
|
+
return this._model
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get voiceId() {
|
|
36
|
+
if (!this._voiceId) {
|
|
37
|
+
throw new Error("ElevenLabs voiceId not found")
|
|
38
|
+
}
|
|
39
|
+
return this._voiceId
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected mapContentType(outputFormat?: string) {
|
|
43
|
+
if (!outputFormat) {
|
|
44
|
+
return "audio/mpeg"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (outputFormat.startsWith("mp3")) {
|
|
48
|
+
return "audio/mpeg"
|
|
49
|
+
}
|
|
50
|
+
if (outputFormat.startsWith("opus")) {
|
|
51
|
+
return "audio/ogg"
|
|
52
|
+
}
|
|
53
|
+
if (outputFormat.startsWith("pcm")) {
|
|
54
|
+
return "audio/wav"
|
|
55
|
+
}
|
|
56
|
+
if (outputFormat.startsWith("ulaw") || outputFormat.startsWith("alaw")) {
|
|
57
|
+
return "audio/basic"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return "application/octet-stream"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected mapVoiceSettings(voiceSettings: ITTSParams["voiceSettings"]) {
|
|
64
|
+
if (!voiceSettings) {
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
stability: voiceSettings.stability,
|
|
70
|
+
similarity_boost: voiceSettings.similarityBoost,
|
|
71
|
+
style: voiceSettings.style,
|
|
72
|
+
use_speaker_boost: voiceSettings.useSpeakerBoost,
|
|
73
|
+
speed: voiceSettings.speed,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
protected buildBody(input: ITTSParams, model: string) {
|
|
78
|
+
return {
|
|
79
|
+
text: input.text,
|
|
80
|
+
model_id: model,
|
|
81
|
+
...(input.voiceSettings ? {voice_settings: this.mapVoiceSettings(input.voiceSettings)} : {}),
|
|
82
|
+
...(input.previousText ? {previous_text: input.previousText} : {}),
|
|
83
|
+
...(input.nextText ? {next_text: input.nextText} : {}),
|
|
84
|
+
...(input.languageCode ? {language_code: input.languageCode} : {}),
|
|
85
|
+
...(input.seed !== undefined ? {seed: input.seed} : {}),
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async textToSpeech(input: ITTSParams): Promise<ITTSResponse> {
|
|
90
|
+
const startedAt = Date.now()
|
|
91
|
+
const model = input.model ?? this.model
|
|
92
|
+
const voiceId = input.voiceId ?? this.voiceId
|
|
93
|
+
const outputFormat = input.outputFormat ?? this._outputFormat
|
|
94
|
+
const url = new URL(`${this._baseUrl}/v1/text-to-speech/${encodeURIComponent(voiceId)}`)
|
|
95
|
+
|
|
96
|
+
if (outputFormat) {
|
|
97
|
+
url.searchParams.set("output_format", outputFormat)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const response = await fetch(url, {
|
|
101
|
+
method: "POST",
|
|
102
|
+
headers: {
|
|
103
|
+
"Accept": this.mapContentType(outputFormat),
|
|
104
|
+
"Content-Type": "application/json",
|
|
105
|
+
"xi-api-key": this._apiKey,
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify(this.buildBody(input, model)),
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
const errorText = await response.text()
|
|
112
|
+
throw new Error(`ElevenLabs TTS request failed (${response.status}): ${errorText}`)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const audio = Buffer.from(await response.arrayBuffer())
|
|
116
|
+
const contentType = response.headers.get("content-type") ?? this.mapContentType(outputFormat)
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
audio,
|
|
120
|
+
contentType,
|
|
121
|
+
size: audio.byteLength,
|
|
122
|
+
time: Date.now() - startedAt,
|
|
123
|
+
provider: "elevenlabs",
|
|
124
|
+
model,
|
|
125
|
+
voiceId,
|
|
126
|
+
outputFormat,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export default ElevenLabsTTSProvider;
|
|
132
|
+
export {ElevenLabsTTSProvider}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import TTSGenericController from "../controllers/TTSGenericController.js";
|
|
2
|
+
|
|
3
|
+
async function TTSFastifyRoutes(fastify, options) {
|
|
4
|
+
|
|
5
|
+
const genericController: TTSGenericController = new TTSGenericController()
|
|
6
|
+
|
|
7
|
+
fastify.get('/api/tts/providers', (req,rep) => genericController.availableProviders(req,rep))
|
|
8
|
+
fastify.post('/api/tts', (req,rep) => genericController.textToSpeech(req,rep))
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default TTSFastifyRoutes;
|
|
13
|
+
export {TTSFastifyRoutes}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {z} from "zod";
|
|
2
|
+
|
|
3
|
+
const TTSVoiceSettingsSchema = z.object({
|
|
4
|
+
stability: z.number().min(0).max(1).optional(),
|
|
5
|
+
similarityBoost: z.number().min(0).max(1).optional(),
|
|
6
|
+
style: z.number().min(0).max(1).optional(),
|
|
7
|
+
useSpeakerBoost: z.boolean().optional(),
|
|
8
|
+
speed: z.number().positive().optional(),
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const TTSRequestSchema = z.object({
|
|
12
|
+
text: z.string().min(1),
|
|
13
|
+
provider: z.string().default("ElevenLabs"),
|
|
14
|
+
voiceId: z.string().optional(),
|
|
15
|
+
model: z.string().optional(),
|
|
16
|
+
outputFormat: z.string().optional(),
|
|
17
|
+
voiceSettings: TTSVoiceSettingsSchema.optional(),
|
|
18
|
+
previousText: z.string().optional(),
|
|
19
|
+
nextText: z.string().optional(),
|
|
20
|
+
languageCode: z.string().optional(),
|
|
21
|
+
seed: z.number().int().optional(),
|
|
22
|
+
responseFormat: z.enum(["audio", "base64"]).default("audio"),
|
|
23
|
+
operationTitle: z.string().optional(),
|
|
24
|
+
operationGroup: z.string().optional(),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
type TTSRequest = z.infer<typeof TTSRequestSchema>
|
|
28
|
+
type TTSVoiceSettings = z.infer<typeof TTSVoiceSettingsSchema>
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
TTSRequestSchema,
|
|
32
|
+
TTSVoiceSettingsSchema,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type {
|
|
36
|
+
TTSRequest,
|
|
37
|
+
TTSVoiceSettings,
|
|
38
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import TTSProviderFactory from "../factory/tts/TTSProviderFactory.js";
|
|
2
|
+
import type {TTSProviderInfo} from "../factory/tts/TTSProviderFactory.js";
|
|
3
|
+
import type {ITTSParams, ITTSResponse} from "../interfaces/ITTSProvider.js";
|
|
4
|
+
import type {TTSRequest} from "../schemas/TTSRequestSchema.js";
|
|
5
|
+
|
|
6
|
+
type TTSRequestContext = {
|
|
7
|
+
ip?: string;
|
|
8
|
+
userAgent?: string;
|
|
9
|
+
tenant?: string | null;
|
|
10
|
+
user?: string | null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class TTSGenericService {
|
|
14
|
+
|
|
15
|
+
availableProviders(): TTSProviderInfo[] {
|
|
16
|
+
return TTSProviderFactory.availableProviders()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async textToSpeech(input: TTSRequest, context: TTSRequestContext = {}): Promise<ITTSResponse> {
|
|
20
|
+
const ttsProvider = TTSProviderFactory.instance(input.provider)
|
|
21
|
+
const ttsInput: ITTSParams = {
|
|
22
|
+
...(input as ITTSParams),
|
|
23
|
+
operationTitle: input.operationTitle ?? "generic-tts",
|
|
24
|
+
operationGroup: input.operationGroup ?? "generic-tts",
|
|
25
|
+
ip: context.ip,
|
|
26
|
+
userAgent: context.userAgent,
|
|
27
|
+
tenant: context.tenant ?? null,
|
|
28
|
+
user: context.user ?? null,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return ttsProvider.textToSpeech(ttsInput)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default TTSGenericService;
|
|
36
|
+
export {
|
|
37
|
+
TTSGenericService,
|
|
38
|
+
}
|
|
39
|
+
export type {
|
|
40
|
+
TTSRequestContext,
|
|
41
|
+
}
|