Skip to content

Commit

Permalink
Fix timeout exception #44
Browse files Browse the repository at this point in the history
  • Loading branch information
pramitchoudhary committed Feb 16, 2024
1 parent 8146eb9 commit 74a4b70
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async def update_ui(q: Q, value: int):
await q.page.save()


def _execute(q: Q, func_type: str, loop: asyncio.AbstractEventLoop, time_out=50, **kwargs):
def _execute(q: Q, func_type: str, loop: asyncio.AbstractEventLoop, time_out=100, **kwargs):
count = 0
future = executor = None
result = task = None
Expand Down Expand Up @@ -304,8 +304,10 @@ def _execute(q: Q, func_type: str, loop: asyncio.AbstractEventLoop, time_out=50,
if not future or future.done():
future = asyncio.ensure_future(update_ui(q, count / time_out), loop=loop)
if task.done():
result = task.result(timeout=1)
result = (task.result())
break
if not result:
result = ("Something went wrong, couldn't compile the response. Try again!", None)
return result


Expand Down Expand Up @@ -378,7 +380,7 @@ async def chatbot(q: Q):
# For regeneration, currently there are 2 modes
# 1. Quick fast approach by throttling the temperature
# 2. "Try harder mode (THM)" Slow approach by using the diverse beam search
llm_response = None
llm_response = []
try:
loop = asyncio.get_event_loop()
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():
Expand Down Expand Up @@ -414,11 +416,14 @@ async def chatbot(q: Q):
if q.client.query is not None and q.client.query.strip() != "":
await _update_before_job_start(q)
with concurrent.futures.ThreadPoolExecutor() as pool:
llm_response, alt_response, _ = await q.exec(pool, _execute, q, "ask",
result = await q.exec(pool, _execute, q, "ask",
loop=loop,
is_regenerate=True,
is_regen_with_options=False
)
if result and len(result)>2:
llm_response = result[0]
alt_response = result[1]
llm_response = "\n".join(llm_response)
await _update_after_job_end(q)
else:
Expand All @@ -432,11 +437,14 @@ async def chatbot(q: Q):
if q.client.query is not None and q.client.query.strip() != "":
await _update_before_job_start(q)
with concurrent.futures.ThreadPoolExecutor() as pool:
llm_response, alt_response, _ = await q.exec(pool, _execute, q, "ask",
result = await q.exec(pool, _execute, q, "ask",
loop=loop,
is_regenerate=False,
is_regen_with_options=True
)
if result and len(result)>2:
llm_response = result[0]
alt_response = result[1]
response = "\n".join(llm_response)
await _update_after_job_end(q)
if alt_response:
Expand All @@ -453,10 +461,13 @@ async def chatbot(q: Q):
q.client.query = question
await _update_before_job_start(q)
with concurrent.futures.ThreadPoolExecutor() as pool:
llm_response, alt_response, err = await q.exec(pool, _execute, q, "ask",
result = await q.exec(pool, _execute, q, "ask",
loop=loop,
debug_mode=q.args.debug_mode
)
if result and len(result)>2:
llm_response = result[0]
alt_response = result[1]
llm_response = "\n".join(llm_response)
await _update_after_job_end(q)
except (MemoryError, RuntimeError) as e:
Expand Down

0 comments on commit 74a4b70

Please sign in to comment.