@@ -254,19 +254,18 @@ async def chat(q: Q):
254
254
],
255
255
),
256
256
),
257
- if not q .args .chatbot :
258
- add_card (
259
- q ,
260
- "chat_card" ,
261
- ui .chatbot_card (
262
- box = ui .box ("vertical" , height = "500px" ),
263
- name = "chatbot" ,
264
- placeholder = "Type your question here, happy to help!" ,
265
- data = data (fields = "content from_user" , t = "list" , size = - 50 , rows = q .client .chat_buffer ),
266
- commands = chat_card_command_items ,
267
- events = ["scroll_up" ],
268
- ),
257
+ add_card (
258
+ q ,
259
+ "chat_card" ,
260
+ ui .chatbot_card (
261
+ box = ui .box ("vertical" , height = "500px" ),
262
+ name = "chatbot" ,
263
+ placeholder = "Type your question here, happy to help!" ,
264
+ data = data (fields = "content from_user" , t = "list" , size = - 50 , rows = q .client .chat_buffer ),
265
+ commands = chat_card_command_items ,
266
+ events = ["scroll_up" ],
269
267
),
268
+ ),
270
269
271
270
# additional actions
272
271
await draw_additional_actions (q )
@@ -298,6 +297,7 @@ def _execute_suggestions(q: Q, loop: asyncio.AbstractEventLoop, time_out=50):
298
297
@on ("chatbot" )
299
298
async def chatbot (q : Q ):
300
299
q .page ["sidebar" ].value = "#chat"
300
+ q .args .re_drawn = False
301
301
302
302
# Append user message.
303
303
q .client .chat_buffer .append ([q .args .chatbot , True ])
@@ -337,8 +337,6 @@ async def chatbot(q: Q):
337
337
llm_response = f"The selected dataset has total number of { n_cols } columns.\n Below is quick preview:\n { df_markdown } "
338
338
elif q .args .chatbot and (q .args .chatbot .lower () == "recommend questions" or q .args .chatbot .lower () == "recommend qs" ):
339
339
await q .page .save ()
340
- #_rows = q.page["chat_card"].data.rows
341
- #import pdb; pdb.set_trace()
342
340
del q .page ["chat_card" ]
343
341
del q .page ["additional_actions" ]
344
342
add_card (
@@ -373,7 +371,7 @@ async def chatbot(q: Q):
373
371
events = ["scroll_up" ],
374
372
)),
375
373
await draw_additional_actions (q )
376
- q .args .chatbot = None
374
+ q .args .re_drawn = True
377
375
elif q .args .chatbot and q .args .chatbot .lower () == "db setup" :
378
376
llm_response , err = db_setup (
379
377
db_name = q .client .db_name ,
@@ -447,6 +445,8 @@ async def chatbot(q: Q):
447
445
llm_response = "Something went wrong, try executing the query again!"
448
446
q .client .llm_response = llm_response
449
447
q .client .chat_buffer .append ([llm_response , False ])
448
+ if not q .args .re_drawn :
449
+ q .page ["chat_card" ].data += [llm_response , False ]
450
450
451
451
452
452
@on ("submit_url_keys" )
@@ -851,12 +851,15 @@ async def on_event(q: Q):
851
851
852
852
if q .args .regenerate_with_options :
853
853
q .args .chatbot = "try harder"
854
+ q .client .chat_buffer .append ([q .args .chatbot , True ])
854
855
elif q .args .regenerate :
855
856
q .args .chatbot = "regenerate"
857
+ q .client .chat_buffer .append ([q .args .chatbot , True ])
856
858
q .client .eval_mode = False
857
859
858
860
if q .args .suggest :
859
861
q .args .chatbot = "Recommend questions"
862
+ q .client .chat_buffer .append ([q .args .chatbot , True ])
860
863
await chatbot (q )
861
864
event_handled = True
862
865
if q .args .eval_mode :
@@ -868,6 +871,7 @@ async def on_event(q: Q):
868
871
logging .info (f"User selected table: { q .args .table_dropdown } " )
869
872
await submit_table (q )
870
873
q .args .chatbot = f"Table { q .args .table_dropdown } selected"
874
+ q .client .chat_buffer .append ([q .args .chatbot , True ])
871
875
# Refresh response is triggered when user selects a table via dropdown
872
876
event_handled = True
873
877
if (
@@ -878,6 +882,7 @@ async def on_event(q: Q):
878
882
q .client .model_choice_dropdown = q .args .model_choice_dropdown
879
883
q .page ["select_tables" ].model_choice_dropdown .value = q .client .model_choice_dropdown
880
884
q .args .chatbot = f"Model { q .client .model_choice_dropdown } selected"
885
+ q .client .chat_buffer .append ([q .args .chatbot , True ])
881
886
# Refresh response is triggered when user selects a table via dropdown
882
887
q .args .model_choice_dropdown = None
883
888
event_handled = True
@@ -886,6 +891,7 @@ async def on_event(q: Q):
886
891
q .client .task_dropdown = q .args .task_dropdown
887
892
q .page ["task_choice" ].task_dropdown .value = q .client .task_dropdown
888
893
q .args .chatbot = f"'{ TASK_CHOICE [q .client .task_dropdown ]} ' mode selected"
894
+ q .client .chat_buffer .append ([q .args .chatbot , True ])
889
895
q .args .task_dropdown = None
890
896
# Refresh response is triggered when user selects a table via dropdown
891
897
event_handled = True
@@ -975,6 +981,7 @@ async def on_event(q: Q):
975
981
q .args .chatbot = (
976
982
f"Demo mode is enabled.\n Try below example questions for the selected data to get started,\n { sample_qs } "
977
983
)
984
+ q .client .chat_buffer .append ([q .args .chatbot , True ])
978
985
q .page ["chat_card" ].data += [q .args .chatbot , False ]
979
986
q .args .table_dropdown = None
980
987
q .args .model_choice_dropdown = None
0 commit comments