@peopl-health/nexus 2.0.14 → 2.0.15
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/lib/services/assistantService.js +37 -17
- package/package.json +1 -1
|
@@ -265,11 +265,10 @@ const addMsgAssistant = async (code, inMessages, reply = false) => {
|
|
|
265
265
|
|
|
266
266
|
if (!reply) return null;
|
|
267
267
|
|
|
268
|
-
const assistant = getAssistantById(thread?.prompt_id || thread?.assistant_id, thread);
|
|
269
268
|
let output, completed;
|
|
270
269
|
let retries = 0;
|
|
271
270
|
const maxRetries = 10;
|
|
272
|
-
|
|
271
|
+
const assistant = getAssistantById(thread?.prompt_id || thread?.assistant_id, thread);
|
|
273
272
|
do {
|
|
274
273
|
({ output, completed } = await runAssistantAndWait({ thread, assistant }));
|
|
275
274
|
console.log(`Attempt ${retries + 1}: completed=${completed}, output=${output || '(empty)'}`);
|
|
@@ -293,17 +292,27 @@ const addInsAssistant = async (code, instruction) => {
|
|
|
293
292
|
console.log(thread);
|
|
294
293
|
if (thread === null) return null;
|
|
295
294
|
|
|
295
|
+
let output, completed;
|
|
296
|
+
let retries = 0;
|
|
297
|
+
const maxRetries = 10;
|
|
296
298
|
const assistant = getAssistantById(thread?.prompt_id || thread?.assistant_id, thread);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
299
|
+
do {
|
|
300
|
+
({ output, completed } = await runAssistantAndWait({
|
|
301
|
+
thread,
|
|
302
|
+
assistant,
|
|
303
|
+
runConfig: {
|
|
304
|
+
additionalInstructions: instruction,
|
|
305
|
+
additionalMessages: [
|
|
306
|
+
{ role: 'user', content: instruction }
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
}));
|
|
310
|
+
console.log(`Attempt ${retries + 1}: completed=${completed}, output=${output || '(empty)'}`);
|
|
311
|
+
|
|
312
|
+
if (completed && output) break;
|
|
313
|
+
if (retries < maxRetries) await new Promise(resolve => setTimeout(resolve, 2000));
|
|
314
|
+
retries++;
|
|
315
|
+
} while (retries <= maxRetries && (!completed || !output));
|
|
307
316
|
console.log('RUN RESPONSE', output);
|
|
308
317
|
|
|
309
318
|
return output;
|
|
@@ -410,11 +419,22 @@ const replyAssistant = async function (code, message_ = null, thread_ = null, ru
|
|
|
410
419
|
const assistant = getAssistantById(process.env.VARIANT === 'responses' ? thread?.prompt_id : thread?.assistant_id, thread);
|
|
411
420
|
assistant.setReplies(patientReply);
|
|
412
421
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
422
|
+
let run, output, completed;
|
|
423
|
+
let retries = 0;
|
|
424
|
+
const maxRetries = 10;
|
|
425
|
+
do {
|
|
426
|
+
({ run, output, completed } = await runAssistantAndWait({
|
|
427
|
+
thread,
|
|
428
|
+
assistant,
|
|
429
|
+
runConfig: runOptions
|
|
430
|
+
}));
|
|
431
|
+
console.log(`Attempt ${retries + 1}: completed=${completed}, output=${output || '(empty)'}`);
|
|
432
|
+
|
|
433
|
+
if (completed && output) break;
|
|
434
|
+
if (retries < maxRetries) await new Promise(resolve => setTimeout(resolve, 2000));
|
|
435
|
+
retries++;
|
|
436
|
+
} while (retries <= maxRetries && (!completed || !output));
|
|
437
|
+
|
|
418
438
|
console.log('RUN LAST ERROR:', run?.last_error);
|
|
419
439
|
console.log('RUN STATUS', completed);
|
|
420
440
|
console.log(output);
|