@peopl-health/nexus 2.4.3 → 2.4.4
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.
|
@@ -111,6 +111,7 @@ const runAssistantWithRetries = async (thread, assistant, runConfig, patientRepl
|
|
|
111
111
|
assistant.setReplies(patientReply);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
const startTime = Date.now();
|
|
114
115
|
let run, output, completed;
|
|
115
116
|
let retries = 0;
|
|
116
117
|
const maxRetries = DEFAULT_MAX_RETRIES;
|
|
@@ -131,11 +132,14 @@ const runAssistantWithRetries = async (thread, assistant, runConfig, patientRepl
|
|
|
131
132
|
if (retries < maxRetries) await new Promise(resolve => setTimeout(resolve, 2000));
|
|
132
133
|
} while (retries < maxRetries && (!completed || !output));
|
|
133
134
|
|
|
135
|
+
const predictionTimeMs = Date.now() - startTime;
|
|
136
|
+
|
|
134
137
|
if (run?.last_error) console.log('[runAssistantWithRetries] RUN LAST ERROR:', run.last_error);
|
|
135
138
|
console.log('[runAssistantWithRetries] RUN STATUS', completed);
|
|
136
139
|
console.log('[runAssistantWithRetries] OUTPUT', output);
|
|
140
|
+
console.log('[runAssistantWithRetries] TIMING', { predictionTimeMs, retries });
|
|
137
141
|
|
|
138
|
-
return { run, output, completed, retries };
|
|
142
|
+
return { run, output, completed, retries, predictionTimeMs };
|
|
139
143
|
};
|
|
140
144
|
|
|
141
145
|
module.exports = {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const predictionMetricsSchema = new mongoose.Schema({
|
|
4
|
+
message_id: { type: String, required: true, index: true },
|
|
5
|
+
numero: { type: String, required: true, index: true },
|
|
6
|
+
assistant_id: { type: String, required: true, index: true },
|
|
7
|
+
thread_id: { type: String, required: true },
|
|
8
|
+
prediction_time_ms: { type: Number, required: true },
|
|
9
|
+
retry_count: { type: Number, required: true, default: 1 },
|
|
10
|
+
completed: { type: Boolean, default: true },
|
|
11
|
+
error: { type: String, default: null }
|
|
12
|
+
}, { timestamps: true });
|
|
13
|
+
|
|
14
|
+
predictionMetricsSchema.index({ createdAt: -1 });
|
|
15
|
+
predictionMetricsSchema.index({ assistant_id: 1, createdAt: -1 });
|
|
16
|
+
predictionMetricsSchema.index({ numero: 1, createdAt: -1 });
|
|
17
|
+
|
|
18
|
+
const PredictionMetrics = mongoose.model('PredictionMetrics', predictionMetricsSchema);
|
|
19
|
+
|
|
20
|
+
module.exports = { PredictionMetrics, predictionMetricsSchema };
|
|
@@ -6,6 +6,7 @@ const { BaseAssistant } = require('../assistants/BaseAssistant');
|
|
|
6
6
|
const { createProvider } = require('../providers/createProvider');
|
|
7
7
|
|
|
8
8
|
const { Thread } = require('../models/threadModel.js');
|
|
9
|
+
const { PredictionMetrics } = require('../models/predictionMetricsModel');
|
|
9
10
|
|
|
10
11
|
const { getCurRow } = require('../helpers/assistantHelper.js');
|
|
11
12
|
const { runAssistantAndWait, runAssistantWithRetries } = require('../helpers/assistantHelper.js');
|
|
@@ -316,7 +317,7 @@ const replyAssistantCore = async (code, message_ = null, thread_ = null, runOpti
|
|
|
316
317
|
if (!patientMsg || thread.stopped) return null;
|
|
317
318
|
|
|
318
319
|
const assistant = getAssistantById(thread.getAssistantId(), thread);
|
|
319
|
-
const { run, output, completed, retries } = await withTracing(
|
|
320
|
+
const { run, output, completed, retries, predictionTimeMs } = await withTracing(
|
|
320
321
|
runAssistantWithRetries,
|
|
321
322
|
'run_assistant_with_retries',
|
|
322
323
|
(thread, assistant, runConfig, patientReply) => ({
|
|
@@ -326,6 +327,19 @@ const replyAssistantCore = async (code, message_ = null, thread_ = null, runOpti
|
|
|
326
327
|
})
|
|
327
328
|
)(thread, assistant, runOptions, patientReply);
|
|
328
329
|
|
|
330
|
+
// Store prediction metrics
|
|
331
|
+
if (output && predictionTimeMs) {
|
|
332
|
+
await PredictionMetrics.create({
|
|
333
|
+
message_id: `${code}-${Date.now()}`,
|
|
334
|
+
numero: code,
|
|
335
|
+
assistant_id: thread.getAssistantId(),
|
|
336
|
+
thread_id: thread.getConversationId(),
|
|
337
|
+
prediction_time_ms: predictionTimeMs,
|
|
338
|
+
retry_count: retries,
|
|
339
|
+
completed: completed
|
|
340
|
+
}).catch(err => console.error('[replyAssistantCore] Failed to store metrics:', err));
|
|
341
|
+
}
|
|
342
|
+
|
|
329
343
|
return output;
|
|
330
344
|
};
|
|
331
345
|
|