@@ -276,7 +276,7 @@ async def update_ui(q: Q, value: int):
276
276
await q .page .save ()
277
277
278
278
279
- def _execute (q : Q , func_type : str , loop : asyncio .AbstractEventLoop , time_out = 50 , ** kwargs ):
279
+ def _execute (q : Q , func_type : str , loop : asyncio .AbstractEventLoop , time_out = 100 , ** kwargs ):
280
280
count = 0
281
281
future = executor = None
282
282
result = task = None
@@ -304,8 +304,10 @@ def _execute(q: Q, func_type: str, loop: asyncio.AbstractEventLoop, time_out=50,
304
304
if not future or future .done ():
305
305
future = asyncio .ensure_future (update_ui (q , count / time_out ), loop = loop )
306
306
if task .done ():
307
- result = task .result (timeout = 1 )
307
+ result = ( task .result () )
308
308
break
309
+ if not result :
310
+ result = ("Something went wrong, couldn't compile the response. Try again!" , None )
309
311
return result
310
312
311
313
@@ -378,7 +380,7 @@ async def chatbot(q: Q):
378
380
# For regeneration, currently there are 2 modes
379
381
# 1. Quick fast approach by throttling the temperature
380
382
# 2. "Try harder mode (THM)" Slow approach by using the diverse beam search
381
- llm_response = None
383
+ llm_response = []
382
384
try :
383
385
loop = asyncio .get_event_loop ()
384
386
if q .args .chatbot and ("preview data" in q .args .chatbot .lower () or "data preview" in q .args .chatbot .lower () or "preview" in q .args .chatbot .lower ()) or f"preview { q .client .table_name } " in q .args .chatbot .lower ():
@@ -414,11 +416,14 @@ async def chatbot(q: Q):
414
416
if q .client .query is not None and q .client .query .strip () != "" :
415
417
await _update_before_job_start (q )
416
418
with concurrent .futures .ThreadPoolExecutor () as pool :
417
- llm_response , alt_response , _ = await q .exec (pool , _execute , q , "ask" ,
419
+ result = await q .exec (pool , _execute , q , "ask" ,
418
420
loop = loop ,
419
421
is_regenerate = True ,
420
422
is_regen_with_options = False
421
423
)
424
+ if result and len (result )> 2 :
425
+ llm_response = result [0 ]
426
+ alt_response = result [1 ]
422
427
llm_response = "\n " .join (llm_response )
423
428
await _update_after_job_end (q )
424
429
else :
@@ -432,11 +437,14 @@ async def chatbot(q: Q):
432
437
if q .client .query is not None and q .client .query .strip () != "" :
433
438
await _update_before_job_start (q )
434
439
with concurrent .futures .ThreadPoolExecutor () as pool :
435
- llm_response , alt_response , _ = await q .exec (pool , _execute , q , "ask" ,
440
+ result = await q .exec (pool , _execute , q , "ask" ,
436
441
loop = loop ,
437
442
is_regenerate = False ,
438
443
is_regen_with_options = True
439
444
)
445
+ if result and len (result )> 2 :
446
+ llm_response = result [0 ]
447
+ alt_response = result [1 ]
440
448
response = "\n " .join (llm_response )
441
449
await _update_after_job_end (q )
442
450
if alt_response :
@@ -453,10 +461,13 @@ async def chatbot(q: Q):
453
461
q .client .query = question
454
462
await _update_before_job_start (q )
455
463
with concurrent .futures .ThreadPoolExecutor () as pool :
456
- llm_response , alt_response , err = await q .exec (pool , _execute , q , "ask" ,
464
+ result = await q .exec (pool , _execute , q , "ask" ,
457
465
loop = loop ,
458
466
debug_mode = q .args .debug_mode
459
467
)
468
+ if result and len (result )> 2 :
469
+ llm_response = result [0 ]
470
+ alt_response = result [1 ]
460
471
llm_response = "\n " .join (llm_response )
461
472
await _update_after_job_end (q )
462
473
except (MemoryError , RuntimeError ) as e :
0 commit comments