@runnerpro/backend 1.13.37 → 1.13.39
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.
|
@@ -220,31 +220,25 @@ const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }
|
|
|
220
220
|
const idCliente = isClient ? req.session.userid : req.body.idCliente;
|
|
221
221
|
let idWorkout, type = 1;
|
|
222
222
|
if (!isClient) {
|
|
223
|
-
console.time('promise all 1');
|
|
224
223
|
[text] = yield Promise.all([
|
|
225
224
|
// Cambiar el tono del texto a uno neutro y corregir la ortografía
|
|
226
225
|
cambiarTonoEntrenadorNeutro(text, idCliente),
|
|
227
226
|
// Si es entrenador, se marca leído cuando se envía un mensaje
|
|
228
227
|
getPreferredLanguageForChat({ text, idCliente, isClient }),
|
|
229
228
|
]);
|
|
230
|
-
console.timeEnd('promise all 1');
|
|
231
229
|
}
|
|
232
230
|
// Devuelve el texto en el otro idioma si el cliente no habla español y el idioma del cliente
|
|
233
|
-
console.time('getPreferredLanguageForChat');
|
|
234
231
|
const { textSpanish, textPreferredLanguage, preferredLanguage } = yield getPreferredLanguageForChat({
|
|
235
232
|
text,
|
|
236
233
|
idCliente,
|
|
237
234
|
isClient,
|
|
238
235
|
});
|
|
239
|
-
console.timeEnd('getPreferredLanguageForChat');
|
|
240
236
|
// Enviado cuando es un mensaje de comentario sobre intelligence
|
|
241
237
|
if (newMessage) {
|
|
242
238
|
type = 6;
|
|
243
239
|
idWorkout = newMessage.idWorkout;
|
|
244
240
|
}
|
|
245
|
-
console.time('query');
|
|
246
241
|
const [message] = yield (0, index_1.query)('INSERT INTO [CHAT MESSAGE] ([ID CLIENTE], [ID SENDER], [TEXT], [TEXT PREFERRED LANGUAGE], [PREFERRED LANGUAGE], [REPLY MESSAGE ID], [ID WORKOUT], [TYPE]) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING [ID]', [isClient ? userid : idCliente, userid, textSpanish, textPreferredLanguage, preferredLanguage, replyMessageId, idWorkout, type]);
|
|
247
|
-
console.timeEnd('query');
|
|
248
242
|
res.send({ idMessage: message.id, text: textSpanish });
|
|
249
243
|
if (!isClient) {
|
|
250
244
|
sendNotification({
|
|
@@ -414,7 +408,6 @@ const cambiarTonoEntrenadorNeutro = (text, idCliente) => __awaiter(void 0, void
|
|
|
414
408
|
if (idCliente !== 'sJzhGqaJcddq96x80hZAlPJ6pET2')
|
|
415
409
|
return text;
|
|
416
410
|
try {
|
|
417
|
-
console.time('sendPrompt');
|
|
418
411
|
const textCorregido = yield (0, prompt_1.sendPrompt)(`
|
|
419
412
|
Actúa como un sistema automático de corrección y estandarización de texto para una aplicación de fitness. Tu única función es procesar un mensaje y devolver una única versión mejorada.
|
|
420
413
|
|
|
@@ -441,8 +434,6 @@ Sigue estas reglas estrictamente:
|
|
|
441
434
|
**Texto Original:** ${text}
|
|
442
435
|
**Texto Corregido:**
|
|
443
436
|
`);
|
|
444
|
-
console.log('textCorregido', textCorregido);
|
|
445
|
-
console.timeEnd('sendPrompt');
|
|
446
437
|
return textCorregido;
|
|
447
438
|
}
|
|
448
439
|
catch (error) {
|
package/lib/cjs/prompt/index.js
CHANGED
|
@@ -10,12 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sendPrompt = void 0;
|
|
13
|
-
const
|
|
13
|
+
const vertexai_1 = require("@google-cloud/vertexai");
|
|
14
14
|
function sendPrompt(prompt) {
|
|
15
15
|
var _a, _b, _c;
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
17
|
// Inicializa el cliente de Vertex AI
|
|
18
|
-
const vertex_ai = new VertexAI({
|
|
18
|
+
const vertex_ai = new vertexai_1.VertexAI({
|
|
19
19
|
project: process.env.PROJECT_ID, // Reemplaza con tu ID de proyecto de Google Cloud
|
|
20
20
|
location: 'europe-west8', // Reemplaza con tu región
|
|
21
21
|
});
|
|
@@ -30,22 +30,17 @@ function sendPrompt(prompt) {
|
|
|
30
30
|
topK: 20,
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return ((_c = parts[0]) === null || _c === void 0 ? void 0 : _c.text) || '';
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
33
|
+
const resp = yield generativeModel.generateContent(prompt);
|
|
34
|
+
// Early return si no hay candidates
|
|
35
|
+
const candidate = (_a = resp.response.candidates) === null || _a === void 0 ? void 0 : _a[0];
|
|
36
|
+
if (!candidate)
|
|
37
|
+
return '';
|
|
38
|
+
// Early return si no hay parts
|
|
39
|
+
const parts = (_b = candidate.content) === null || _b === void 0 ? void 0 : _b.parts;
|
|
40
|
+
if (!parts || parts.length === 0)
|
|
41
|
+
return '';
|
|
42
|
+
// Return del texto si existe
|
|
43
|
+
return ((_c = parts[0]) === null || _c === void 0 ? void 0 : _c.text) || '';
|
|
49
44
|
});
|
|
50
45
|
}
|
|
51
46
|
exports.sendPrompt = sendPrompt;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAuBpD,CAAC;AAkcF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":"AAEA,iBAAe,UAAU,CAAC,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/prompt/index.ts"],"names":[],"mappings":"AAEA,iBAAe,UAAU,CAAC,MAAM,EAAE,MAAM,mBAgCvC;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|