@drax/ai-back 3.41.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/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/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 +22 -13
- package/dist/interfaces/ITTSProvider.js +1 -0
- package/dist/permissions/TTSPermissions.js +6 -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/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} +3 -3
- 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 +52 -11
- package/src/interfaces/ITTSProvider.ts +47 -0
- package/src/permissions/AIPermissions.ts +0 -1
- package/src/permissions/TTSPermissions.ts +8 -0
- package/src/providers/{DeepSeekProvider.ts → ai/DeepSeekAiProvider.ts} +5 -5
- 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 +4 -4
- package/tsconfig.tsbuildinfo +1 -1
- 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/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 +24 -11
- 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/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
- package/src/factory/DeepSeekProviderFactory.ts +0 -27
|
@@ -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
|
@@ -2,35 +2,45 @@ import {OpenAiConfig} from "./config/OpenAiConfig.js";
|
|
|
2
2
|
import {GoogleAiConfig} from "./config/GoogleAiConfig.js";
|
|
3
3
|
import {OllamaAiConfig} from "./config/OllamaAiConfig.js";
|
|
4
4
|
import {DeepSeekConfig} from "./config/DeepSeekConfig.js";
|
|
5
|
+
import {ElevenLabsTTSConfig} from "./config/ElevenLabsTTSConfig.js";
|
|
5
6
|
import {AILogSchema, AILogBaseSchema} from "./schemas/AILogSchema.js";
|
|
7
|
+
import {TTSRequestSchema, TTSVoiceSettingsSchema} from "./schemas/TTSRequestSchema.js";
|
|
6
8
|
import AILogModel from "./models/AILogModel.js";
|
|
7
9
|
import AILogMongoRepository from "./repository/mongo/AILogMongoRepository.js";
|
|
8
10
|
import AILogSqliteRepository from "./repository/sqlite/AILogSqliteRepository.js";
|
|
9
|
-
import {OpenAiProviderFactory} from "./factory/OpenAiProviderFactory.js";
|
|
10
|
-
import {GoogleAiProviderFactory} from "./factory/GoogleAiProviderFactory.js";
|
|
11
|
-
import {OllamaAiProviderFactory} from "./factory/OllamaAiProviderFactory.js";
|
|
12
|
-
import {
|
|
13
|
-
import {AiProviderFactory} from "./factory/AiProviderFactory.js";
|
|
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";
|
|
14
19
|
import {DraxAgentFactory} from "./factory/DraxAgentFactory.js";
|
|
15
20
|
import AILogServiceFactory from "./factory/services/AILogServiceFactory.js";
|
|
16
|
-
import {OpenAiProvider} from "./providers/OpenAiProvider.js";
|
|
17
|
-
import {GoogleAiProvider} from "./providers/GoogleAiProvider.js";
|
|
18
|
-
import {OllamaAiProvider} from "./providers/OllamaAiProvider.js";
|
|
19
|
-
import {
|
|
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";
|
|
20
26
|
import {BuilderTool} from "./tools/BuilderTool.js";
|
|
21
27
|
import {KnowledgeService} from "./services/KnowledgeService.js";
|
|
22
28
|
import {AILogService} from "./services/AILogService.js";
|
|
29
|
+
import {TTSGenericService} from "./services/TTSGenericService.js";
|
|
23
30
|
import AILogPermissions from "./permissions/AILogPermissions.js";
|
|
24
31
|
import AgentPermissions from "./permissions/AgentPermissions.js";
|
|
25
32
|
import AgentSessionPermissions from "./permissions/AgentSessionPermissions.js";
|
|
26
33
|
import AIPermissions from "./permissions/AIPermissions.js";
|
|
34
|
+
import TTSPermissions from "./permissions/TTSPermissions.js";
|
|
27
35
|
import AILogController from "./controllers/AILogController.js";
|
|
28
36
|
import AICrudController from "./controllers/AICrudController.js";
|
|
29
37
|
import AIGenericController from "./controllers/AIGenericController.js";
|
|
38
|
+
import TTSGenericController from "./controllers/TTSGenericController.js";
|
|
30
39
|
import DraxAgentController from "./controllers/DraxAgentController.js";
|
|
31
40
|
import AgentSessionController from "./controllers/AgentSessionController.js";
|
|
32
41
|
import AILogRoutes from "./routes/AILogRoutes.js";
|
|
33
42
|
import AIRoutes from "./routes/AIRoutes.js";
|
|
43
|
+
import TTSRoutes from "./routes/TTSRoutes.js";
|
|
34
44
|
import DraxAgentRoutes from "./routes/DraxAgentRoutes.js";
|
|
35
45
|
import AgentSessionRoutes from "./routes/AgentSessionRoutes.js";
|
|
36
46
|
import {DraxAgent} from "./agents/DraxAgent.js";
|
|
@@ -48,6 +58,19 @@ import type {
|
|
|
48
58
|
IPromptResponse,
|
|
49
59
|
IPromptTool
|
|
50
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";
|
|
51
74
|
import type {
|
|
52
75
|
ToolBuilderMethod,
|
|
53
76
|
ToolBuilderOptions,
|
|
@@ -86,6 +109,14 @@ export type {
|
|
|
86
109
|
IPromptContentPartImage,
|
|
87
110
|
IPromptContentPartText,
|
|
88
111
|
IPromptResponse,
|
|
112
|
+
ITTSProvider,
|
|
113
|
+
ITTSParams,
|
|
114
|
+
ITTSResponse,
|
|
115
|
+
ITTSVoiceSettings,
|
|
116
|
+
TTSRequest,
|
|
117
|
+
TTSVoiceSettings,
|
|
118
|
+
TTSRequestContext,
|
|
119
|
+
TTSProviderInfo,
|
|
89
120
|
ToolBuilderMethod,
|
|
90
121
|
ToolBuilderOptions,
|
|
91
122
|
ToolBuilderService,
|
|
@@ -108,40 +139,50 @@ export {
|
|
|
108
139
|
GoogleAiConfig,
|
|
109
140
|
OllamaAiConfig,
|
|
110
141
|
DeepSeekConfig,
|
|
142
|
+
ElevenLabsTTSConfig,
|
|
111
143
|
AILogSchema,
|
|
112
144
|
AILogBaseSchema,
|
|
145
|
+
TTSRequestSchema,
|
|
146
|
+
TTSVoiceSettingsSchema,
|
|
113
147
|
AILogModel,
|
|
114
148
|
AILogMongoRepository,
|
|
115
149
|
AILogSqliteRepository,
|
|
116
150
|
OpenAiProviderFactory,
|
|
117
151
|
GoogleAiProviderFactory,
|
|
118
152
|
OllamaAiProviderFactory,
|
|
119
|
-
|
|
153
|
+
DeepSeekAiProviderFactory,
|
|
120
154
|
AiProviderFactory,
|
|
155
|
+
ElevenLabsTTSProviderFactory,
|
|
156
|
+
TTSProviderFactory,
|
|
121
157
|
DraxAgentFactory,
|
|
122
158
|
AILogServiceFactory,
|
|
123
159
|
OpenAiProvider,
|
|
124
160
|
GoogleAiProvider,
|
|
125
161
|
OllamaAiProvider,
|
|
126
|
-
|
|
162
|
+
DeepSeekAiProvider,
|
|
163
|
+
ElevenLabsTTSProvider,
|
|
127
164
|
BuilderTool,
|
|
128
165
|
//Service
|
|
129
166
|
KnowledgeService,
|
|
130
167
|
AILogService,
|
|
168
|
+
TTSGenericService,
|
|
131
169
|
//Permissions
|
|
132
170
|
AILogPermissions,
|
|
133
171
|
AgentPermissions,
|
|
134
172
|
AIPermissions,
|
|
173
|
+
TTSPermissions,
|
|
135
174
|
AgentSessionPermissions,
|
|
136
175
|
//Controllers
|
|
137
176
|
AILogController,
|
|
138
177
|
AICrudController,
|
|
139
178
|
AIGenericController,
|
|
179
|
+
TTSGenericController,
|
|
140
180
|
DraxAgentController,
|
|
141
181
|
AgentSessionController,
|
|
142
182
|
DraxAgent,
|
|
143
183
|
AILogRoutes,
|
|
144
184
|
AIRoutes,
|
|
185
|
+
TTSRoutes,
|
|
145
186
|
DraxAgentRoutes,
|
|
146
187
|
AgentSessionRoutes
|
|
147
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
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
2
|
import type {IAILogBase} from "@drax/ai-share";
|
|
3
|
-
import type {IPromptParams} from "
|
|
4
|
-
import type {AILogService} from "
|
|
3
|
+
import type {IPromptParams} from "../../interfaces/IAIProvider.js";
|
|
4
|
+
import type {AILogService} from "../../services/AILogService.js";
|
|
5
5
|
import OpenAiProvider from "./OpenAiProvider.js";
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class DeepSeekAiProvider extends OpenAiProvider{
|
|
8
8
|
protected _baseUrl: string
|
|
9
9
|
|
|
10
10
|
constructor(apiKey: string, model: string, baseUrl: string = "https://api.deepseek.com", visionModel?: string, aiLogService?: AILogService) {
|
|
@@ -54,5 +54,5 @@ class DeepSeekProvider extends OpenAiProvider{
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export default
|
|
58
|
-
export {
|
|
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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {describe, expect, test} from "vitest";
|
|
2
|
-
import {AiProviderFactory,
|
|
2
|
+
import {AiProviderFactory, DeepSeekAiProvider} from "../src";
|
|
3
3
|
import {IPromptTool} from "../src/interfaces/IAIProvider";
|
|
4
4
|
|
|
5
5
|
describe("DeepSeekProvider Test", () => {
|
|
@@ -7,7 +7,7 @@ describe("DeepSeekProvider Test", () => {
|
|
|
7
7
|
test("DeepSeek prompt uses OpenAI-compatible chat completions", async () => {
|
|
8
8
|
let request: any
|
|
9
9
|
|
|
10
|
-
class MockedDeepSeekProvider extends
|
|
10
|
+
class MockedDeepSeekProvider extends DeepSeekAiProvider {
|
|
11
11
|
constructor() {
|
|
12
12
|
super("test-key", "deepseek-chat")
|
|
13
13
|
this._client = {
|
|
@@ -61,7 +61,7 @@ describe("DeepSeekProvider Test", () => {
|
|
|
61
61
|
execute: async ({city}) => ({city, temperature: 21})
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
class MockedDeepSeekProvider extends
|
|
64
|
+
class MockedDeepSeekProvider extends DeepSeekAiProvider {
|
|
65
65
|
constructor() {
|
|
66
66
|
super("test-key", "deepseek-chat")
|
|
67
67
|
this._client = {
|
|
@@ -141,6 +141,6 @@ describe("DeepSeekProvider Test", () => {
|
|
|
141
141
|
process.env.DRAX_DB_ENGINE = "mongo"
|
|
142
142
|
|
|
143
143
|
const deepSeek = AiProviderFactory.instance("DeepSeek")
|
|
144
|
-
expect(deepSeek).toBeInstanceOf(
|
|
144
|
+
expect(deepSeek).toBeInstanceOf(DeepSeekAiProvider)
|
|
145
145
|
})
|
|
146
146
|
})
|