@drax/ai-back 3.41.0 → 3.43.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 +3 -1
- package/dist/config/ElevenLabsTTSConfig.js +10 -0
- package/dist/controllers/AICrudController.js +1 -1
- package/dist/controllers/AIGenericController.js +23 -1
- package/dist/controllers/DraxAgentController.js +22 -0
- 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 +23 -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 +370 -0
- package/dist/providers/ai/OllamaAiProvider.js +345 -0
- package/dist/providers/ai/OpenAiProvider.js +305 -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/PromptAudioService.js +68 -0
- package/dist/services/TTSGenericService.js +21 -0
- package/package.json +3 -3
- package/src/agents/DraxAgent.ts +3 -1
- package/src/config/ElevenLabsTTSConfig.ts +13 -0
- package/src/controllers/AICrudController.ts +1 -1
- package/src/controllers/AIGenericController.ts +25 -1
- package/src/controllers/DraxAgentController.ts +24 -0
- 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 +60 -11
- package/src/interfaces/IAIProvider.ts +38 -1
- package/src/interfaces/IDraxAgent.ts +4 -0
- 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} +6 -3
- package/src/providers/{OllamaAiProvider.ts → ai/OllamaAiProvider.ts} +6 -3
- package/src/providers/{OpenAiProvider.ts → ai/OpenAiProvider.ts} +6 -3
- 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/PromptAudioService.ts +87 -0
- package/src/services/TTSGenericService.ts +41 -0
- package/test/DeepSeekProvider.test.ts +4 -4
- 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/config/ElevenLabsTTSConfig.d.ts +10 -0
- package/types/config/ElevenLabsTTSConfig.d.ts.map +1 -0
- package/types/controllers/AIGenericController.d.ts.map +1 -1
- package/types/controllers/DraxAgentController.d.ts.map +1 -1
- 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 +26 -12
- 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/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/PromptAudioService.d.ts +9 -0
- package/types/services/PromptAudioService.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
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { GoogleGenAI } from "@google/genai";
|
|
2
|
+
import { toJSONSchema } from "zod";
|
|
3
|
+
import PromptAudioService from "../../services/PromptAudioService.js";
|
|
4
|
+
class GoogleAiProvider {
|
|
5
|
+
constructor(apiKey, model, visionModel, aiLogService) {
|
|
6
|
+
if (!apiKey) {
|
|
7
|
+
throw new Error("Google AI apiKey required");
|
|
8
|
+
}
|
|
9
|
+
if (!model) {
|
|
10
|
+
throw new Error("Google AI model required");
|
|
11
|
+
}
|
|
12
|
+
this._apiKey = apiKey;
|
|
13
|
+
this._model = model;
|
|
14
|
+
this._visionModel = visionModel;
|
|
15
|
+
this._aiLogService = aiLogService;
|
|
16
|
+
}
|
|
17
|
+
get model() {
|
|
18
|
+
if (!this._model) {
|
|
19
|
+
throw new Error("Google AI model not found");
|
|
20
|
+
}
|
|
21
|
+
return this._model;
|
|
22
|
+
}
|
|
23
|
+
get client() {
|
|
24
|
+
if (!this._client) {
|
|
25
|
+
this._client = new GoogleGenAI({
|
|
26
|
+
apiKey: this._apiKey,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return this._client;
|
|
30
|
+
}
|
|
31
|
+
get visionModel() {
|
|
32
|
+
return this._visionModel;
|
|
33
|
+
}
|
|
34
|
+
buildUserContent(input) {
|
|
35
|
+
if (input.userContent && input.userContent.length > 0) {
|
|
36
|
+
return this.mapContentParts(input.userContent);
|
|
37
|
+
}
|
|
38
|
+
if (input.userImages && input.userImages.length > 0) {
|
|
39
|
+
const content = [];
|
|
40
|
+
if (input.userInput) {
|
|
41
|
+
content.push({ text: input.userInput });
|
|
42
|
+
}
|
|
43
|
+
content.push(...input.userImages.map(image => this.mapImageUrl(image.url)));
|
|
44
|
+
return content;
|
|
45
|
+
}
|
|
46
|
+
return input.userInput ? [{ text: input.userInput }] : [{ text: "" }];
|
|
47
|
+
}
|
|
48
|
+
mapContentParts(content) {
|
|
49
|
+
return content.map(part => {
|
|
50
|
+
if (part.type === 'text') {
|
|
51
|
+
return {
|
|
52
|
+
text: part.text
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return this.mapImageUrl(part.imageUrl);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
mapImageUrl(url) {
|
|
59
|
+
const dataUrlMatch = url.match(/^data:([^;,]+);base64,(.+)$/);
|
|
60
|
+
if (dataUrlMatch) {
|
|
61
|
+
return {
|
|
62
|
+
inlineData: {
|
|
63
|
+
mimeType: dataUrlMatch[1],
|
|
64
|
+
data: dataUrlMatch[2],
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
fileData: {
|
|
70
|
+
fileUri: url,
|
|
71
|
+
mimeType: this.inferImageMimeType(url),
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
inferImageMimeType(url) {
|
|
76
|
+
const normalizedUrl = url.split("?")[0].toLowerCase();
|
|
77
|
+
if (normalizedUrl.endsWith(".png")) {
|
|
78
|
+
return "image/png";
|
|
79
|
+
}
|
|
80
|
+
if (normalizedUrl.endsWith(".webp")) {
|
|
81
|
+
return "image/webp";
|
|
82
|
+
}
|
|
83
|
+
if (normalizedUrl.endsWith(".gif")) {
|
|
84
|
+
return "image/gif";
|
|
85
|
+
}
|
|
86
|
+
if (normalizedUrl.endsWith(".bmp")) {
|
|
87
|
+
return "image/bmp";
|
|
88
|
+
}
|
|
89
|
+
if (normalizedUrl.endsWith(".heic")) {
|
|
90
|
+
return "image/heic";
|
|
91
|
+
}
|
|
92
|
+
if (normalizedUrl.endsWith(".heif")) {
|
|
93
|
+
return "image/heif";
|
|
94
|
+
}
|
|
95
|
+
return "image/jpeg";
|
|
96
|
+
}
|
|
97
|
+
mapHistory(history = []) {
|
|
98
|
+
return history.map(message => {
|
|
99
|
+
const parts = typeof message.content === 'string'
|
|
100
|
+
? [{ text: message.content }]
|
|
101
|
+
: this.mapContentParts(message.content);
|
|
102
|
+
if (message.role === "assistant") {
|
|
103
|
+
return {
|
|
104
|
+
role: "model",
|
|
105
|
+
parts,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (message.role === "system") {
|
|
109
|
+
return {
|
|
110
|
+
role: "user",
|
|
111
|
+
parts: [
|
|
112
|
+
{ text: "[SYSTEM]" },
|
|
113
|
+
...parts,
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
role: "user",
|
|
119
|
+
parts,
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
hasImageInput(input) {
|
|
124
|
+
if (input.userImages && input.userImages.length > 0) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
if (input.userContent?.some(part => part.type === 'image')) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return input.history?.some(message => Array.isArray(message.content) && message.content.some(part => part.type === 'image')) ?? false;
|
|
131
|
+
}
|
|
132
|
+
serializePromptInput(input, systemPrompt) {
|
|
133
|
+
return JSON.stringify({
|
|
134
|
+
systemPrompt,
|
|
135
|
+
history: input.history,
|
|
136
|
+
userInput: input.userInput,
|
|
137
|
+
userContent: input.userContent,
|
|
138
|
+
memory: input.memory,
|
|
139
|
+
knowledgeBase: input.knowledgeBase,
|
|
140
|
+
tools: input.tools?.map(tool => ({
|
|
141
|
+
name: tool.name,
|
|
142
|
+
description: tool.description,
|
|
143
|
+
parameters: tool.parameters,
|
|
144
|
+
})),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
serializePromptOutput(output) {
|
|
148
|
+
if (typeof output === "string") {
|
|
149
|
+
return output;
|
|
150
|
+
}
|
|
151
|
+
if (output === null || output === undefined) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
return JSON.stringify(output);
|
|
155
|
+
}
|
|
156
|
+
buildLogPayload(input, params) {
|
|
157
|
+
return {
|
|
158
|
+
provider: "googleai",
|
|
159
|
+
model: params.model,
|
|
160
|
+
operationTitle: input.operationTitle,
|
|
161
|
+
operationGroup: input.operationGroup,
|
|
162
|
+
ip: input.ip,
|
|
163
|
+
userAgent: input.userAgent,
|
|
164
|
+
input: this.serializePromptInput(input, params.systemPrompt),
|
|
165
|
+
inputImages: input.userImages?.map(image => ({
|
|
166
|
+
url: image.url,
|
|
167
|
+
})) ?? input.userContent
|
|
168
|
+
?.filter(part => part.type === "image")
|
|
169
|
+
.map(part => ({
|
|
170
|
+
url: part.imageUrl,
|
|
171
|
+
})),
|
|
172
|
+
inputFiles: input.inputFiles,
|
|
173
|
+
inputTokens: params.inputTokens,
|
|
174
|
+
outputTokens: params.outputTokens,
|
|
175
|
+
tokens: params.tokens,
|
|
176
|
+
startedAt: params.startedAt,
|
|
177
|
+
endedAt: params.endedAt,
|
|
178
|
+
responseTime: params.endedAt ? `${params.endedAt.getTime() - params.startedAt.getTime()}ms` : undefined,
|
|
179
|
+
output: this.serializePromptOutput(params.output),
|
|
180
|
+
success: params.success,
|
|
181
|
+
errorMessage: params.errorMessage,
|
|
182
|
+
tenant: input.tenant,
|
|
183
|
+
user: input.user,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
async registerPromptLog(input, params) {
|
|
187
|
+
if (!this._aiLogService) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
await this._aiLogService.create(this.buildLogPayload(input, params));
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
console.error("Error registerPromptLog", {
|
|
195
|
+
name: e?.name,
|
|
196
|
+
message: e?.message,
|
|
197
|
+
stack: e?.stack,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async generateEmbedding({ text, model = "text-embedding-004" }) {
|
|
202
|
+
const response = await this.client.models.embedContent({
|
|
203
|
+
model,
|
|
204
|
+
contents: text,
|
|
205
|
+
});
|
|
206
|
+
return response.embeddings?.[0]?.values ?? [];
|
|
207
|
+
}
|
|
208
|
+
mapTools(tools = []) {
|
|
209
|
+
if (tools.length === 0) {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
return [{
|
|
213
|
+
functionDeclarations: tools.map(tool => ({
|
|
214
|
+
name: tool.name,
|
|
215
|
+
description: tool.description,
|
|
216
|
+
parametersJsonSchema: tool.parameters ?? {
|
|
217
|
+
type: "object",
|
|
218
|
+
properties: {},
|
|
219
|
+
additionalProperties: false,
|
|
220
|
+
},
|
|
221
|
+
}))
|
|
222
|
+
}];
|
|
223
|
+
}
|
|
224
|
+
buildResponseConfig(input, systemPrompt) {
|
|
225
|
+
const config = {
|
|
226
|
+
systemInstruction: systemPrompt,
|
|
227
|
+
};
|
|
228
|
+
const responseJsonSchema = this.normalizeResponseJsonSchema(input);
|
|
229
|
+
if (responseJsonSchema) {
|
|
230
|
+
config.responseMimeType = "application/json";
|
|
231
|
+
config.responseJsonSchema = responseJsonSchema;
|
|
232
|
+
}
|
|
233
|
+
if (input.tools && input.tools.length > 0) {
|
|
234
|
+
config.tools = this.mapTools(input.tools);
|
|
235
|
+
}
|
|
236
|
+
return config;
|
|
237
|
+
}
|
|
238
|
+
normalizeResponseJsonSchema(input) {
|
|
239
|
+
if (input.zodSchema) {
|
|
240
|
+
return toJSONSchema(input.zodSchema, {
|
|
241
|
+
target: "draft-7",
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
if (!input.jsonSchema) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
const jsonSchema = input.jsonSchema;
|
|
248
|
+
if (jsonSchema.type === "json_schema" && jsonSchema.json_schema?.schema) {
|
|
249
|
+
return jsonSchema.json_schema.schema;
|
|
250
|
+
}
|
|
251
|
+
return jsonSchema;
|
|
252
|
+
}
|
|
253
|
+
async buildToolResponseParts(functionCalls = [], tools = []) {
|
|
254
|
+
const parts = [];
|
|
255
|
+
for (const functionCall of functionCalls) {
|
|
256
|
+
const toolName = functionCall.name;
|
|
257
|
+
const tool = tools.find(t => t.name === toolName);
|
|
258
|
+
if (!tool) {
|
|
259
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
260
|
+
}
|
|
261
|
+
const output = await tool.execute(functionCall.args ?? {});
|
|
262
|
+
parts.push({
|
|
263
|
+
functionResponse: {
|
|
264
|
+
id: functionCall.id,
|
|
265
|
+
name: toolName,
|
|
266
|
+
response: {
|
|
267
|
+
output,
|
|
268
|
+
},
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return parts;
|
|
273
|
+
}
|
|
274
|
+
buildModelFunctionCallContent(functionCalls = []) {
|
|
275
|
+
return {
|
|
276
|
+
role: "model",
|
|
277
|
+
parts: functionCalls.map(functionCall => ({
|
|
278
|
+
functionCall,
|
|
279
|
+
}))
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
async prompt(input) {
|
|
283
|
+
if (!input.systemPrompt) {
|
|
284
|
+
throw new Error("systemPrompt required");
|
|
285
|
+
}
|
|
286
|
+
let systemPrompt = input.systemPrompt;
|
|
287
|
+
if (input.memory && input.memory.length > 0) {
|
|
288
|
+
systemPrompt += `\n\n ${input.memoryHeader ?? '[MEMORIA]'}\n ${input.memory.map(m => `${m.key}: ${m.value}`).join('\n')}`;
|
|
289
|
+
}
|
|
290
|
+
if (input.knowledgeBase && input.knowledgeBase.length > 0) {
|
|
291
|
+
systemPrompt += `\n\n${input.knowledgeBaseHeader ?? '[BASE DE CONOCIMIENTO]'}\n ${input.knowledgeBase.join('\n')}`;
|
|
292
|
+
}
|
|
293
|
+
const userInput = this.buildUserContent(input);
|
|
294
|
+
const model = input.model ?? (this.hasImageInput(input) ? this.visionModel ?? this.model : this.model);
|
|
295
|
+
const startedAt = new Date();
|
|
296
|
+
const startTime = performance.now();
|
|
297
|
+
let tokens = 0;
|
|
298
|
+
let inputTokens = 0;
|
|
299
|
+
let outputTokens = 0;
|
|
300
|
+
try {
|
|
301
|
+
const contents = [
|
|
302
|
+
...this.mapHistory(input.history),
|
|
303
|
+
{ role: 'user', parts: userInput },
|
|
304
|
+
];
|
|
305
|
+
const tools = input.tools ?? [];
|
|
306
|
+
const maxIterations = input.toolMaxIterations ?? 5;
|
|
307
|
+
let output;
|
|
308
|
+
for (let iteration = 0; iteration < maxIterations; iteration++) {
|
|
309
|
+
const response = await this.client.models.generateContent({
|
|
310
|
+
model,
|
|
311
|
+
contents,
|
|
312
|
+
config: this.buildResponseConfig(input, systemPrompt),
|
|
313
|
+
});
|
|
314
|
+
tokens += response.usageMetadata?.totalTokenCount ?? 0;
|
|
315
|
+
inputTokens += response.usageMetadata?.promptTokenCount ?? 0;
|
|
316
|
+
outputTokens += response.usageMetadata?.candidatesTokenCount ?? 0;
|
|
317
|
+
const functionCalls = response.functionCalls ?? [];
|
|
318
|
+
if (functionCalls.length === 0) {
|
|
319
|
+
output = response.text;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
contents.push(response.candidates?.[0]?.content ?? this.buildModelFunctionCallContent(functionCalls));
|
|
323
|
+
contents.push({
|
|
324
|
+
role: "user",
|
|
325
|
+
parts: await this.buildToolResponseParts(functionCalls, tools),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (output === undefined) {
|
|
329
|
+
throw new Error(`Tool max iterations reached: ${maxIterations}`);
|
|
330
|
+
}
|
|
331
|
+
const endTime = performance.now();
|
|
332
|
+
const time = endTime - startTime;
|
|
333
|
+
const endedAt = new Date();
|
|
334
|
+
const audio = await PromptAudioService.build(input, output);
|
|
335
|
+
await this.registerPromptLog(input, {
|
|
336
|
+
model,
|
|
337
|
+
systemPrompt,
|
|
338
|
+
startedAt,
|
|
339
|
+
endedAt,
|
|
340
|
+
inputTokens,
|
|
341
|
+
outputTokens,
|
|
342
|
+
tokens,
|
|
343
|
+
output,
|
|
344
|
+
success: true,
|
|
345
|
+
});
|
|
346
|
+
return {
|
|
347
|
+
output,
|
|
348
|
+
tokens,
|
|
349
|
+
inputTokens,
|
|
350
|
+
outputTokens,
|
|
351
|
+
time,
|
|
352
|
+
...(audio ? { audio } : {}),
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
catch (e) {
|
|
356
|
+
const endedAt = new Date();
|
|
357
|
+
await this.registerPromptLog(input, {
|
|
358
|
+
model,
|
|
359
|
+
systemPrompt,
|
|
360
|
+
startedAt,
|
|
361
|
+
endedAt,
|
|
362
|
+
success: false,
|
|
363
|
+
errorMessage: e?.message,
|
|
364
|
+
});
|
|
365
|
+
throw e;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
export default GoogleAiProvider;
|
|
370
|
+
export { GoogleAiProvider };
|