Skip to content

Commit 74a4b70

Browse files
Fix timeout exception #44
1 parent 8146eb9 commit 74a4b70

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

ui/app.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ async def update_ui(q: Q, value: int):
276276
await q.page.save()
277277

278278

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):
280280
count = 0
281281
future = executor = None
282282
result = task = None
@@ -304,8 +304,10 @@ def _execute(q: Q, func_type: str, loop: asyncio.AbstractEventLoop, time_out=50,
304304
if not future or future.done():
305305
future = asyncio.ensure_future(update_ui(q, count / time_out), loop=loop)
306306
if task.done():
307-
result = task.result(timeout=1)
307+
result = (task.result())
308308
break
309+
if not result:
310+
result = ("Something went wrong, couldn't compile the response. Try again!", None)
309311
return result
310312

311313

@@ -378,7 +380,7 @@ async def chatbot(q: Q):
378380
# For regeneration, currently there are 2 modes
379381
# 1. Quick fast approach by throttling the temperature
380382
# 2. "Try harder mode (THM)" Slow approach by using the diverse beam search
381-
llm_response = None
383+
llm_response = []
382384
try:
383385
loop = asyncio.get_event_loop()
384386
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):
414416
if q.client.query is not None and q.client.query.strip() != "":
415417
await _update_before_job_start(q)
416418
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",
418420
loop=loop,
419421
is_regenerate=True,
420422
is_regen_with_options=False
421423
)
424+
if result and len(result)>2:
425+
llm_response = result[0]
426+
alt_response = result[1]
422427
llm_response = "\n".join(llm_response)
423428
await _update_after_job_end(q)
424429
else:
@@ -432,11 +437,14 @@ async def chatbot(q: Q):
432437
if q.client.query is not None and q.client.query.strip() != "":
433438
await _update_before_job_start(q)
434439
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",
436441
loop=loop,
437442
is_regenerate=False,
438443
is_regen_with_options=True
439444
)
445+
if result and len(result)>2:
446+
llm_response = result[0]
447+
alt_response = result[1]
440448
response = "\n".join(llm_response)
441449
await _update_after_job_end(q)
442450
if alt_response:
@@ -453,10 +461,13 @@ async def chatbot(q: Q):
453461
q.client.query = question
454462
await _update_before_job_start(q)
455463
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",
457465
loop=loop,
458466
debug_mode=q.args.debug_mode
459467
)
468+
if result and len(result)>2:
469+
llm_response = result[0]
470+
alt_response = result[1]
460471
llm_response = "\n".join(llm_response)
461472
await _update_after_job_end(q)
462473
except (MemoryError, RuntimeError) as e:

0 commit comments

Comments
 (0)