@runnerpro/backend 1.13.23 → 1.13.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.
@@ -227,8 +227,15 @@ const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }
227
227
  // Cambiar el tono del texto a uno neutro y corregir la ortografía
228
228
  if (idCliente === 'sJzhGqaJcddq96x80hZAlPJ6pET2' && process.env.NODE_ENV === 'PROD') {
229
229
  console.time('cambiarTonoEntrenadorNeutro');
230
- text = yield cambiarTonoEntrenadorNeutro(text);
231
- console.timeEnd('cambiarTonoEntrenadorNeutro');
230
+ try {
231
+ text = yield cambiarTonoEntrenadorNeutro(text);
232
+ }
233
+ catch (error) {
234
+ console.error('Error en cambiarTonoEntrenadorNeutro:', error);
235
+ }
236
+ finally {
237
+ console.timeEnd('cambiarTonoEntrenadorNeutro');
238
+ }
232
239
  }
233
240
  }
234
241
  // Devuelve el texto en el otro idioma si el cliente no habla español y el idioma del cliente
@@ -11,21 +11,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.sendPrompt = void 0;
13
13
  const { VertexAI } = require('@google-cloud/vertexai');
14
- function sendPrompt(prompt) {
14
+ function sendPrompt(prompt, options = {}) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
16
  // Inicializa el cliente de Vertex AI
17
17
  const vertex_ai = new VertexAI({
18
18
  project: process.env.PROJECT_ID, // Reemplaza con tu ID de proyecto de Google Cloud
19
19
  location: 'us-central1', // Reemplaza con tu región
20
20
  });
21
- // Selecciona el modelo de Gemini
22
- const model = 'gemini-2.5-flash'; // O cualquier otro modelo de Gemini disponible
23
- // Configura el modelo generativo
21
+ // Selecciona el modelo de Gemini más rápido
22
+ const model = 'gemini-2.5-flash'; // Flash es más rápido que Pro
23
+ // Configura el modelo generativo con parámetros optimizados para velocidad
24
24
  const generativeModel = vertex_ai.preview.getGenerativeModel({
25
25
  model: model,
26
+ generationConfig: {
27
+ maxOutputTokens: options.maxOutputTokens || 512, // Limitar tokens para respuestas más rápidas
28
+ temperature: options.temperature || 0.3, // Menor temperatura = más determinístico y rápido
29
+ topP: options.topP || 0.8,
30
+ topK: options.topK || 20,
31
+ },
26
32
  });
27
33
  try {
28
- const resp = yield generativeModel.generateContent(prompt);
34
+ // Timeout para evitar esperas largas
35
+ const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout en sendPrompt')), options.timeout || 15000));
36
+ const resp = yield Promise.race([generativeModel.generateContent(prompt), timeoutPromise]);
29
37
  const content = resp.response.candidates[0].content;
30
38
  // Asumiendo que la respuesta es de tipo texto
31
39
  if (content.parts && content.parts.length > 0 && content.parts[0].text)
@@ -34,6 +42,7 @@ function sendPrompt(prompt) {
34
42
  }
35
43
  catch (error) {
36
44
  console.error('Error al enviar el prompt:', error);
45
+ throw error; // Re-throw para que el código que llama pueda manejar el error
37
46
  }
38
47
  });
39
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAmBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAuBpD,CAAC;AA0bF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAmBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAuBpD,CAAC;AA+bF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,3 +1,10 @@
1
- declare function sendPrompt(prompt: any): Promise<any>;
1
+ interface SendPromptOptions {
2
+ maxOutputTokens?: number;
3
+ temperature?: number;
4
+ topP?: number;
5
+ topK?: number;
6
+ timeout?: number;
7
+ }
8
+ declare function sendPrompt(prompt: string, options?: SendPromptOptions): Promise<any>;
2
9
  export { sendPrompt };
3
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":"AAEA,iBAAe,UAAU,CAAC,MAAM,KAAA,gBA0B/B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":"AAEA,UAAU,iBAAiB;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,iBAAe,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,gBAqCxE;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.13.23",
3
+ "version": "1.13.25",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"