@drax/ai-back 3.42.0 → 3.44.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 +2 -0
- package/dist/controllers/AIGenericController.js +22 -0
- package/dist/controllers/DraxAgentController.js +22 -0
- package/dist/index.js +4 -2
- package/dist/providers/ai/GoogleAiProvider.js +4 -1
- package/dist/providers/ai/OllamaAiProvider.js +4 -1
- package/dist/providers/ai/OpenAiProvider.js +4 -1
- package/dist/services/PromptAudioService.js +68 -0
- package/dist/tools/BuildContextTool.js +267 -0
- package/package.json +3 -3
- package/src/agents/DraxAgent.ts +2 -0
- package/src/controllers/AIGenericController.ts +24 -0
- package/src/controllers/DraxAgentController.ts +24 -0
- package/src/index.ts +16 -0
- package/src/interfaces/IAIProvider.ts +38 -1
- package/src/interfaces/IDraxAgent.ts +4 -0
- package/src/providers/ai/GoogleAiProvider.ts +4 -1
- package/src/providers/ai/OllamaAiProvider.ts +4 -1
- package/src/providers/ai/OpenAiProvider.ts +4 -1
- package/src/services/PromptAudioService.ts +87 -0
- package/src/tools/BuildContextTool.ts +388 -0
- package/test/BuildContextTool.test.ts +183 -0
- package/test/DraxAgent.test.ts +64 -0
- package/test/PromptAudioService.test.ts +115 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/types/agents/DraxAgent.d.ts.map +1 -1
- package/types/controllers/AIGenericController.d.ts.map +1 -1
- package/types/controllers/DraxAgentController.d.ts.map +1 -1
- package/types/index.d.ts +6 -3
- package/types/index.d.ts.map +1 -1
- package/types/interfaces/IAIProvider.d.ts +32 -1
- package/types/interfaces/IAIProvider.d.ts.map +1 -1
- package/types/interfaces/IDraxAgent.d.ts +3 -1
- package/types/interfaces/IDraxAgent.d.ts.map +1 -1
- package/types/providers/ai/GoogleAiProvider.d.ts.map +1 -1
- package/types/providers/ai/OllamaAiProvider.d.ts.map +1 -1
- package/types/providers/ai/OpenAiProvider.d.ts.map +1 -1
- package/types/services/PromptAudioService.d.ts +9 -0
- package/types/services/PromptAudioService.d.ts.map +1 -0
- package/types/tools/BuildContextTool.d.ts +33 -0
- package/types/tools/BuildContextTool.d.ts.map +1 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {afterEach, describe, expect, test, vi} from "vitest";
|
|
2
|
+
import {PromptAudioService, TTSProviderFactory} from "../src";
|
|
3
|
+
|
|
4
|
+
describe("PromptAudioService Test", () => {
|
|
5
|
+
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
vi.restoreAllMocks()
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test("does not generate audio when audioResponse is not requested", async () => {
|
|
11
|
+
const instanceSpy = vi.spyOn(TTSProviderFactory, "instance")
|
|
12
|
+
|
|
13
|
+
const audio = await PromptAudioService.build({
|
|
14
|
+
systemPrompt: "You are an assistant.",
|
|
15
|
+
}, "Hola")
|
|
16
|
+
|
|
17
|
+
expect(audio).toBeUndefined()
|
|
18
|
+
expect(instanceSpy).not.toHaveBeenCalled()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test("generates base64 prompt audio with default ElevenLabs provider", async () => {
|
|
22
|
+
const textToSpeech = vi.fn(async () => ({
|
|
23
|
+
audio: Buffer.from("audio-bytes"),
|
|
24
|
+
contentType: "audio/mpeg",
|
|
25
|
+
size: 11,
|
|
26
|
+
time: 25,
|
|
27
|
+
provider: "elevenlabs",
|
|
28
|
+
model: "eleven_multilingual_v2",
|
|
29
|
+
voiceId: "voice-1",
|
|
30
|
+
outputFormat: "mp3_44100_128",
|
|
31
|
+
}))
|
|
32
|
+
const instanceSpy = vi.spyOn(TTSProviderFactory, "instance").mockReturnValue({
|
|
33
|
+
textToSpeech,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const audio = await PromptAudioService.build({
|
|
37
|
+
systemPrompt: "You are an assistant.",
|
|
38
|
+
audioResponse: true,
|
|
39
|
+
operationTitle: "prompt-title",
|
|
40
|
+
operationGroup: "prompt-group",
|
|
41
|
+
ip: "127.0.0.1",
|
|
42
|
+
userAgent: "vitest",
|
|
43
|
+
tenant: "tenant-1",
|
|
44
|
+
user: "user-1",
|
|
45
|
+
}, "Hola mundo")
|
|
46
|
+
|
|
47
|
+
expect(instanceSpy).toHaveBeenCalledWith("ElevenLabs")
|
|
48
|
+
expect(textToSpeech).toHaveBeenCalledWith({
|
|
49
|
+
text: "Hola mundo",
|
|
50
|
+
voiceId: undefined,
|
|
51
|
+
model: undefined,
|
|
52
|
+
outputFormat: undefined,
|
|
53
|
+
voiceSettings: undefined,
|
|
54
|
+
previousText: undefined,
|
|
55
|
+
nextText: undefined,
|
|
56
|
+
languageCode: undefined,
|
|
57
|
+
seed: undefined,
|
|
58
|
+
operationTitle: "prompt-title",
|
|
59
|
+
operationGroup: "prompt-group",
|
|
60
|
+
ip: "127.0.0.1",
|
|
61
|
+
userAgent: "vitest",
|
|
62
|
+
tenant: "tenant-1",
|
|
63
|
+
user: "user-1",
|
|
64
|
+
})
|
|
65
|
+
expect(audio).toEqual({
|
|
66
|
+
audio: Buffer.from("audio-bytes").toString("base64"),
|
|
67
|
+
contentType: "audio/mpeg",
|
|
68
|
+
encoding: "base64",
|
|
69
|
+
meta: {
|
|
70
|
+
provider: "elevenlabs",
|
|
71
|
+
model: "eleven_multilingual_v2",
|
|
72
|
+
voiceId: "voice-1",
|
|
73
|
+
outputFormat: "mp3_44100_128",
|
|
74
|
+
size: 11,
|
|
75
|
+
time: 25,
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test("supports custom TTS provider params", async () => {
|
|
81
|
+
const textToSpeech = vi.fn(async () => ({
|
|
82
|
+
audio: Buffer.from("custom-audio"),
|
|
83
|
+
contentType: "audio/ogg",
|
|
84
|
+
size: 12,
|
|
85
|
+
time: 31,
|
|
86
|
+
provider: "custom",
|
|
87
|
+
model: "custom-model",
|
|
88
|
+
voiceId: "voice-2",
|
|
89
|
+
}))
|
|
90
|
+
const instanceSpy = vi.spyOn(TTSProviderFactory, "instance").mockReturnValue({
|
|
91
|
+
textToSpeech,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
await PromptAudioService.build({
|
|
95
|
+
systemPrompt: "You are an assistant.",
|
|
96
|
+
audioResponse: {
|
|
97
|
+
provider: "CustomTTS",
|
|
98
|
+
voiceId: "voice-2",
|
|
99
|
+
model: "custom-model",
|
|
100
|
+
languageCode: "es",
|
|
101
|
+
operationTitle: "tts-title",
|
|
102
|
+
},
|
|
103
|
+
}, {message: "Hola"})
|
|
104
|
+
|
|
105
|
+
expect(instanceSpy).toHaveBeenCalledWith("CustomTTS")
|
|
106
|
+
expect(textToSpeech).toHaveBeenCalledWith(expect.objectContaining({
|
|
107
|
+
text: "{\"message\":\"Hola\"}",
|
|
108
|
+
voiceId: "voice-2",
|
|
109
|
+
model: "custom-model",
|
|
110
|
+
languageCode: "es",
|
|
111
|
+
operationTitle: "tts-title",
|
|
112
|
+
}))
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
})
|