Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion fastchat/serve/gradio_block_arena_named.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
acknowledgment_md,
get_ip,
get_model_description_md,
CLEAR_HISTORY_CONFIRM_JS,
)
from fastchat.serve.remote_logger import get_remote_logger
from fastchat.utils import (
Expand Down Expand Up @@ -457,7 +458,12 @@ def build_side_by_side_ui_named(models):
).then(
flash_buttons, [], btn_list
)
clear_btn.click(clear_history, None, states + chatbots + [textbox] + btn_list)
clear_btn.click(
clear_history,
None,
states + chatbots + [textbox] + btn_list,
js=CLEAR_HISTORY_CONFIRM_JS,
)

share_js = """
function (a, b, c, d) {
Expand Down
2 changes: 2 additions & 0 deletions fastchat/serve/gradio_block_arena_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
State,
get_conv_log_filename,
get_remote_logger,
CLEAR_HISTORY_CONFIRM_JS,
)
from fastchat.serve.vision.image import ImageFormat, Image
from fastchat.utils import (
Expand Down Expand Up @@ -451,6 +452,7 @@ def build_single_vision_language_model_ui(
clear_history,
None,
[state, chatbot, multimodal_textbox, textbox, send_btn] + btn_list,
js=CLEAR_HISTORY_CONFIRM_JS,
)

model_selector.change(
Expand Down
2 changes: 2 additions & 0 deletions fastchat/serve/gradio_block_arena_vision_named.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
get_ip,
get_model_description_md,
enable_text,
CLEAR_HISTORY_CONFIRM_JS,
)
from fastchat.serve.remote_logger import get_remote_logger
from fastchat.utils import (
Expand Down Expand Up @@ -492,6 +493,7 @@ def build_side_by_side_vision_ui_named(context: Context, random_questions=None):
clear_history,
None,
states + chatbots + [multimodal_textbox, textbox, send_btn] + btn_list,
js=CLEAR_HISTORY_CONFIRM_JS,
)

share_js = """
Expand Down
15 changes: 14 additions & 1 deletion fastchat/serve/gradio_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@

logger = build_logger("gradio_web_server", "gradio_web_server.log")

CLEAR_HISTORY_CONFIRM_JS = """
() => {
if (!confirm("Are you sure you want to clear your chat history?")) {
throw new Error("Clear history cancelled");
}
}
"""

headers = {"User-Agent": "FastChat Client"}

no_change_btn = gr.Button()
Expand Down Expand Up @@ -1000,7 +1008,12 @@ def build_single_model_ui(models, add_promotion_links=False):
[state, temperature, top_p, max_output_tokens],
[state, chatbot] + btn_list,
)
clear_btn.click(clear_history, None, [state, chatbot, textbox] + btn_list)
clear_btn.click(
clear_history,
None,
[state, chatbot, textbox] + btn_list,
js=CLEAR_HISTORY_CONFIRM_JS,
)

model_selector.change(clear_history, None, [state, chatbot, textbox] + btn_list)

Expand Down
Loading