Skip to content

Commit 1b4e61c

Browse files
Allow user to download history(accept/reject) #44
1 parent b582ff7 commit 1b4e61c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

app.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title = "SQL-Sidekick"
44
description = "QnA with tabular data using NLQ"
55
LongDescription = "about.md"
66
Tags = ["DATA_SCIENCE", "MACHINE_LEARNING", "NLP"]
7-
Version = "0.0.16"
7+
Version = "0.0.17"
88

99
[Runtime]
1010
MemoryLimit = "64Gi"

ui/app.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,31 @@ async def on_event(q: Q):
670670
_msg = "Sorry, try generating a conversation to save."
671671
q.page["chat_card"].data += [_msg, False]
672672
event_handled = True
673+
elif q.args.download_accept:
674+
result_path = f"{base_path}/var/lib/tmp/.cache/{q.user.table_name}/history.jsonl"
675+
# Check if path exists
676+
if Path(result_path).exists():
677+
logging.info(f"Downloading accepted QnA history for table: {q.user.table_name}")
678+
(server_path,) = await q.site.upload([result_path])
679+
q.page["meta"].script = ui.inline_script(f'window.open("{server_path}", "_blank");')
680+
os.remove(result_path)
681+
_msg = "Download complete!"
682+
else:
683+
_msg = "No history found!"
684+
q.page["chat_card"].data += [_msg, False]
685+
event_handled = True
686+
elif q.args.download_reject:
687+
logging.info(f"Downloading rejected QnA history for table: {q.user.table_name}")
688+
result_path = f"{base_path}/var/lib/tmp/.cache/{q.user.table_name}/invalid/history.jsonl"
689+
if Path(result_path).exists():
690+
(server_path,) = await q.site.upload([result_path])
691+
q.page["meta"].script = ui.inline_script(f'window.open("{server_path}", "_blank");')
692+
os.remove(result_path)
693+
_msg = "Download complete!"
694+
else:
695+
_msg = "No history found!"
696+
q.page["chat_card"].data += [_msg, False]
697+
event_handled = True
673698
elif q.args.regenerate or q.args.regenerate_with_options:
674699
await chatbot(q)
675700
event_handled = True

0 commit comments

Comments
 (0)