SarahXia0405 commited on
Commit
14f19ba
·
verified ·
1 Parent(s): 62b95b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -14
app.py CHANGED
@@ -532,28 +532,43 @@ with gr.Blocks(
532
  """
533
  )
534
 
 
535
  chatbot = gr.Chatbot(
536
  label="",
537
  height=450,
538
  avatar_images=(None, CLARE_LOGO_PATH),
539
  show_label=False,
540
- bubble_full_width=False,
541
- type="tuples",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
542
  )
543
 
544
- # === Feedback on last answer ===
545
- gr.Markdown("#### Rate Clare’s last answer")
546
- with gr.Row():
547
- thumb_up_btn = gr.Button(
548
- "👍 Helpful", size="sm", interactive=False
549
- )
550
- thumb_down_btn = gr.Button(
551
- "👎 Not helpful", size="sm", interactive=False
552
- )
553
 
554
- feedback_toggle_btn = gr.Button(
555
- "Give detailed feedback", size="sm", variant="secondary", interactive=False
556
- )
557
  feedback_text = gr.Textbox(
558
  label="What worked well or what was wrong?",
559
  placeholder="Optional: describe what you liked / what was confusing or incorrect.",
 
532
  """
533
  )
534
 
535
+
536
  chatbot = gr.Chatbot(
537
  label="",
538
  height=450,
539
  avatar_images=(None, CLARE_LOGO_PATH),
540
  show_label=False,
541
+ type="tuples", # 你现在的 history 是 list[ [user, assistant], ... ],保留 tuples 就行
542
+ likeable=True, # 新版本才支持
543
+ )
544
+
545
+ def handle_like(data, history, user_id, mode_val, model_name_val, lang_pref):
546
+ """
547
+ data 里一般会带:
548
+ - data["index"] 被点的是第几条对话
549
+ - data["value"] 是 "like" / "dislike"
550
+ 你可以用这个信息去调用 LangSmith 的 feedback API
551
+ """
552
+ idx = data.get("index", -1)
553
+ value = data.get("value", "")
554
+ if idx < 0 or idx >= len(history):
555
+ return
556
+
557
+ question, answer = history[idx]
558
+
559
+ # 在这里把 question/answer + value 发到 LangSmith
560
+ # (用你之前已经写好的 record_feedback / client.create_feedback 那一套)
561
+ # record_langsmith_feedback(question, answer, value, user_id, mode_val, model_name_val, lang_pref)
562
+
563
+ print(f"[LIKE EVENT] idx={idx}, value={value}")
564
+
565
+ chatbot.like(
566
+ fn=handle_like,
567
+ inputs=[chatbot, user_id_state, learning_mode, model_name, language_preference],
568
+ outputs=[],
569
  )
570
 
 
 
 
 
 
 
 
 
 
571
 
 
 
 
572
  feedback_text = gr.Textbox(
573
  label="What worked well or what was wrong?",
574
  placeholder="Optional: describe what you liked / what was confusing or incorrect.",