@@ -157,6 +157,10 @@ async def chat(q: Q):
157
157
box = ui .box ("vertical" , height = "500px" ),
158
158
name = "chatbot" ,
159
159
data = data (fields = "content from_user" , t = "list" , size = - 50 ),
160
+ commands = [
161
+ ui .command (name = "download_accept" , label = "Download QnA history" , icon = "Download" ),
162
+ ui .command (name = "download_reject" , label = "Download in-correct QnA history" , icon = "Download" ),
163
+ ],
160
164
),
161
165
),
162
166
add_card (
@@ -170,8 +174,8 @@ async def chat(q: Q):
170
174
ui .button (
171
175
name = "regenerate" ,
172
176
icon = "RepeatOne" ,
173
- caption = "Attempts regeneration" ,
174
- label = "Regenerate " ,
177
+ caption = "Attempts regeneration of the last response " ,
178
+ label = "Try Again " ,
175
179
primary = True ,
176
180
),
177
181
ui .button (
@@ -182,9 +186,15 @@ async def chat(q: Q):
182
186
),
183
187
ui .button (
184
188
name = "save_conversation" ,
185
- caption = "Saves the conversation for future reference/to improve response" ,
186
- label = "Save" ,
187
- icon = "Save" ,
189
+ caption = "Saves the conversation in the history for future reference to improve response" ,
190
+ label = "Accept" ,
191
+ icon = "Emoji2" ,
192
+ ),
193
+ ui .button (
194
+ name = "save_rejected_conversation" ,
195
+ caption = "Saves the disappointed conversation to improve response." ,
196
+ label = "Reject" ,
197
+ icon = "EmojiDisappointed" ,
188
198
),
189
199
],
190
200
justify = "center" ,
@@ -629,11 +639,21 @@ async def on_event(q: Q):
629
639
# Refresh response is triggered when user selects a table via dropdown
630
640
event_handled = True
631
641
632
- if q .args .save_conversation or (q .args .chatbot and "save the qna pair:" in q .args .chatbot .lower ()):
642
+ if (
643
+ q .args .save_conversation
644
+ or q .args .save_rejected_conversation
645
+ or (q .args .chatbot and "save the qna pair:" in q .args .chatbot .lower ())
646
+ ):
633
647
question = q .client .query
634
648
_val = q .client .llm_response
635
649
# Currently, any manual input by the user is a Question by default
636
650
table_name = q .user .table_name if q .user .table_name else "default"
651
+ _is_invalid = True if q .args .save_rejected_conversation else False
652
+ _msg = (
653
+ "Conversation saved successfully!"
654
+ if not _is_invalid
655
+ else "Sorry, we couldn't get it right, we will try to improve!"
656
+ )
637
657
if (
638
658
question is not None
639
659
and "SELECT" in question
@@ -642,12 +662,10 @@ async def on_event(q: Q):
642
662
_q = question .lower ().split ("q:" )[1 ].split ("r:" )[0 ].strip ()
643
663
_r = question .lower ().split ("r:" )[1 ].strip ()
644
664
logging .info (f"Saving conversation for question: { _q } and response: { _r } " )
645
- save_query (base_path , table_name , query = _q , response = _r )
646
- _msg = "Conversation saved successfully!"
665
+ save_query (base_path , table_name , query = _q , response = _r , is_invalid = _is_invalid )
647
666
elif question is not None and _val is not None and _val .strip () != "" :
648
667
logging .info (f"Saving conversation for question: { question } and response: { _val } " )
649
- save_query (base_path , table_name , query = question , response = _val )
650
- _msg = "Conversation saved successfully!"
668
+ save_query (base_path , table_name , query = question , response = _val , is_invalid = _is_invalid )
651
669
else :
652
670
_msg = "Sorry, try generating a conversation to save."
653
671
q .page ["chat_card" ].data += [_msg , False ]
0 commit comments