@@ -670,6 +670,31 @@ async def on_event(q: Q):
670
670
_msg = "Sorry, try generating a conversation to save."
671
671
q .page ["chat_card" ].data += [_msg , False ]
672
672
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
673
698
elif q .args .regenerate or q .args .regenerate_with_options :
674
699
await chatbot (q )
675
700
event_handled = True
0 commit comments