diff --git a/docs/commands/webserver.md b/docs/commands/webserver.md index 920f15aa0..b6342c682 100644 --- a/docs/commands/webserver.md +++ b/docs/commands/webserver.md @@ -27,7 +27,7 @@ cd fastchat_logs/server0 export OPENAI_API_KEY= export ANTHROPIC_API_KEY= -python3 -m fastchat.serve.gradio_web_server_multi --controller http://localhost:21001 --concurrency 10 --add-chatgpt --add-claude --add-palm --anony-only --elo ~/elo_results/elo_results_20230802.pkl --leaderboard-table-file ~/elo_results/leaderboard_table_20230802.csv --register ~/elo_results/register_oai_models.json +python3 -m fastchat.serve.gradio_web_server_multi --controller http://localhost:21001 --concurrency 10 --add-chatgpt --add-claude --add-palm --anony-only --elo ~/elo_results/elo_results.pkl --leaderboard-table-file ~/elo_results/leaderboard_table.csv --register ~/elo_results/register_oai_models.json --show-terms python3 backup_logs.py ``` diff --git a/fastchat/llm_judge/common.py b/fastchat/llm_judge/common.py index ad1180034..abe1ec6cc 100644 --- a/fastchat/llm_judge/common.py +++ b/fastchat/llm_judge/common.py @@ -418,6 +418,35 @@ def chat_compeletion_openai(model, conv, temperature, max_tokens): return output +def chat_compeletion_openai_azure(model, conv, temperature, max_tokens): + openai.api_type = "azure" + openai.api_base = os.environ["AZURE_OPENAI_ENDPOINT"] + openai.api_key = os.environ["AZURE_OPENAI_KEY"] + openai.api_version = "2023-05-15" + + if "azure-" in model: + model = model[6:] + + output = API_ERROR_OUTPUT + for _ in range(API_MAX_RETRY): + try: + messages = conv.to_openai_api_messages() + response = openai.ChatCompletion.create( + engine=model, + messages=messages, + n=1, + temperature=temperature, + max_tokens=max_tokens, + ) + output = response["choices"][0]["message"]["content"] + break + except openai.error.OpenAIError as e: + print(type(e), e) + time.sleep(API_RETRY_SLEEP) + + return output + + def chat_compeletion_anthropic(model, conv, temperature, max_tokens): output = API_ERROR_OUTPUT for _ in range(API_MAX_RETRY): diff --git a/fastchat/model/model_registry.py b/fastchat/model/model_registry.py index 0612ca832..19a513eaa 100644 --- a/fastchat/model/model_registry.py +++ b/fastchat/model/model_registry.py @@ -19,7 +19,13 @@ def register_model_info( def get_model_info(name: str) -> ModelInfo: - return model_info[name] + if name in model_info: + return model_info[name] + else: + # To fix this, please use `register_model_info` to register your model + return ModelInfo( + name, "", "Register the description at fastchat/model/model_registry.py" + ) register_model_info( diff --git a/fastchat/serve/gradio_block_arena_anony.py b/fastchat/serve/gradio_block_arena_anony.py index 2bdb9abbb..edd89d072 100644 --- a/fastchat/serve/gradio_block_arena_anony.py +++ b/fastchat/serve/gradio_block_arena_anony.py @@ -57,17 +57,7 @@ def load_demo_side_by_side_anony(models_, url_params): gr.Markdown.update(visible=True), ) - return ( - states - + selector_updates - + (gr.Chatbot.update(visible=True),) * num_sides - + ( - gr.Textbox.update(visible=True), - gr.Box.update(visible=True), - gr.Row.update(visible=True), - gr.Accordion.update(visible=True), - ) - ) + return states + selector_updates def vote_last_response(states, vote_type, model_selectors, request: gr.Request): @@ -388,9 +378,6 @@ def build_side_by_side_ui_anony(models): ### Leaderboard See [lmsys/chatbot-arena-leaderboard](https://huggingface.co/spaces/lmsys/chatbot-arena-leaderboard) or the 4th tab above on this page. -### Terms of use -By using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. **The service collects user dialogue data and reserves the right to distribute it under a Creative Commons Attribution (CC-BY) license.** The demo works better on desktop devices with a wide screen. - ### Battle Please scroll down and start chatting. The models include both closed-source models (e.g., ChatGPT) and open-source models (e.g., Llama). """ @@ -407,7 +394,7 @@ def build_side_by_side_ui_anony(models): label = "Model A" if i == 0 else "Model B" with gr.Column(): chatbots[i] = gr.Chatbot( - label=label, elem_id=f"chatbot", visible=False, height=550 + label=label, elem_id=f"chatbot", height=550 ) with gr.Row(): @@ -432,19 +419,18 @@ def build_side_by_side_ui_anony(models): textbox = gr.Textbox( show_label=False, placeholder="Enter your prompt here and press ENTER", - visible=False, container=False, elem_id="input_box", ) with gr.Column(scale=1, min_width=50): - send_btn = gr.Button(value="Send", visible=False, variant="primary") + send_btn = gr.Button(value="Send", variant="primary") with gr.Row() as button_row: clear_btn = gr.Button(value="🗑️ Clear history", interactive=False) regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=False) share_btn = gr.Button(value="📷 Share") - with gr.Accordion("Parameters", open=False, visible=True) as parameter_row: + with gr.Accordion("Parameters", open=False) as parameter_row: temperature = gr.Slider( minimum=0.0, maximum=1.0, @@ -560,12 +546,4 @@ def build_side_by_side_ui_anony(models): flash_buttons, [], btn_list ) - return ( - states, - model_selectors, - chatbots, - textbox, - send_btn, - button_row, - parameter_row, - ) + return states + model_selectors diff --git a/fastchat/serve/gradio_block_arena_named.py b/fastchat/serve/gradio_block_arena_named.py index 3da3b223a..6c2d0b534 100644 --- a/fastchat/serve/gradio_block_arena_named.py +++ b/fastchat/serve/gradio_block_arena_named.py @@ -62,17 +62,7 @@ def load_demo_side_by_side_named(models, url_params): gr.Dropdown.update(choices=models, value=model_right, visible=True), ) - return ( - states - + selector_updates - + (gr.Chatbot.update(visible=True),) * num_sides - + ( - gr.Textbox.update(visible=True), - gr.Box.update(visible=True), - gr.Row.update(visible=True), - gr.Accordion.update(visible=True), - ) - ) + return states + selector_updates def vote_last_response(states, vote_type, model_selectors, request: gr.Request): @@ -313,10 +303,10 @@ def build_side_by_side_ui_named(models): - You can do multiple turns of conversations before voting. - Click "Clear history" to start a new round. -### Terms of use -By using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. **The service collects user dialogue data and reserves the right to distribute it under a Creative Commons Attribution (CC-BY) license.** The demo works better on desktop devices with a wide screen. +### Leaderboard +See [lmsys/chatbot-arena-leaderboard](https://huggingface.co/spaces/lmsys/chatbot-arena-leaderboard) or the 4th tab above on this page. -### Choose two models to chat with (view [leaderboard](https://huggingface.co/spaces/lmsys/chatbot-arena-leaderboard)) +### Choose two models to chat with """ states = [gr.State() for _ in range(num_sides)] @@ -345,7 +335,7 @@ def build_side_by_side_ui_named(models): label = "Model A" if i == 0 else "Model B" with gr.Column(): chatbots[i] = gr.Chatbot( - label=label, elem_id=f"chatbot", visible=False, height=550 + label=label, elem_id=f"chatbot", height=550 ) with gr.Row(): @@ -365,19 +355,18 @@ def build_side_by_side_ui_named(models): textbox = gr.Textbox( show_label=False, placeholder="Enter your prompt here and press ENTER", - visible=False, container=False, elem_id="input_box", ) with gr.Column(scale=1, min_width=50): - send_btn = gr.Button(value="Send", visible=False, variant="primary") + send_btn = gr.Button(value="Send", variant="primary") with gr.Row() as button_row: regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=False) clear_btn = gr.Button(value="🗑️ Clear history", interactive=False) share_btn = gr.Button(value="📷 Share") - with gr.Accordion("Parameters", open=False, visible=True) as parameter_row: + with gr.Accordion("Parameters", open=False) as parameter_row: temperature = gr.Slider( minimum=0.0, maximum=1.0, @@ -495,12 +484,4 @@ def build_side_by_side_ui_named(models): flash_buttons, [], btn_list ) - return ( - states, - model_selectors, - chatbots, - textbox, - send_btn, - button_row, - parameter_row, - ) + return states + model_selectors diff --git a/fastchat/serve/gradio_web_server.py b/fastchat/serve/gradio_web_server.py index 3c5e34675..24db98b34 100644 --- a/fastchat/serve/gradio_web_server.py +++ b/fastchat/serve/gradio_web_server.py @@ -28,7 +28,7 @@ SESSION_EXPIRATION_TIME, ) from fastchat.model.model_adapter import get_conversation_template -from fastchat.model.model_registry import model_info +from fastchat.model.model_registry import get_model_info, model_info from fastchat.serve.api_provider import ( anthropic_api_stream_iter, openai_api_stream_iter, @@ -39,6 +39,7 @@ build_logger, violates_moderation, get_window_url_params_js, + get_window_url_params_with_tos_js, parse_gradio_auth_creds, ) @@ -163,15 +164,7 @@ def load_demo_single(models, url_params): ) state = None - return ( - state, - dropdown_update, - gr.Chatbot.update(visible=True), - gr.Textbox.update(visible=True), - gr.Button.update(visible=True), - gr.Row.update(visible=True), - gr.Accordion.update(visible=True), - ) + return state, dropdown_update def load_demo(url_params, request: gr.Request): @@ -530,17 +523,11 @@ def get_model_description_md(models): ct = 0 visited = set() for i, name in enumerate(models): - if name in model_info: - minfo = model_info[name] - if minfo.simple_name in visited: - continue - visited.add(minfo.simple_name) - one_model_md = f"[{minfo.simple_name}]({minfo.link}): {minfo.description}" - else: - visited.add(name) - one_model_md = ( - f"[{name}](): Add the description at fastchat/model/model_registry.py" - ) + minfo = get_model_info(name) + if minfo.simple_name in visited: + continue + visited.add(minfo.simple_name) + one_model_md = f"[{minfo.simple_name}]({minfo.link}): {minfo.description}" if ct % 3 == 0: model_description_md += "|" @@ -566,9 +553,6 @@ def build_single_model_ui(models, add_promotion_links=False): # 🏔️ Chat with Open Large Language Models {promotion} -### Terms of use -By using this service, users are required to agree to the following terms: The service is a research preview intended for non-commercial use only. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes. **The service collects user dialogue data and reserves the right to distribute it under a Creative Commons Attribution (CC-BY) license.** - ### Choose a model to chat with """ @@ -588,7 +572,6 @@ def build_single_model_ui(models, add_promotion_links=False): chatbot = gr.Chatbot( elem_id="chatbot", label="Scroll down and start chatting", - visible=False, height=550, ) with gr.Row(): @@ -596,21 +579,20 @@ def build_single_model_ui(models, add_promotion_links=False): textbox = gr.Textbox( show_label=False, placeholder="Enter your prompt here and press ENTER", - visible=False, container=False, elem_id="input_box", ) with gr.Column(scale=1, min_width=50): - send_btn = gr.Button(value="Send", visible=False, variant="primary") + send_btn = gr.Button(value="Send", variant="primary") - with gr.Row(visible=False) as button_row: + with gr.Row() as button_row: upvote_btn = gr.Button(value="👍 Upvote", interactive=False) downvote_btn = gr.Button(value="👎 Downvote", interactive=False) flag_btn = gr.Button(value="⚠️ Flag", interactive=False) regenerate_btn = gr.Button(value="🔄 Regenerate", interactive=False) clear_btn = gr.Button(value="🗑️ Clear history", interactive=False) - with gr.Accordion("Parameters", open=False, visible=False) as parameter_row: + with gr.Accordion("Parameters", open=False) as parameter_row: temperature = gr.Slider( minimum=0.0, maximum=1.0, @@ -673,49 +655,44 @@ def build_single_model_ui(models, add_promotion_links=False): [state, chatbot] + btn_list, ) send_btn.click( - add_text, [state, model_selector, textbox], [state, chatbot, textbox] + btn_list + add_text, + [state, model_selector, textbox], + [state, chatbot, textbox] + btn_list, ).then( bot_response, [state, temperature, top_p, max_output_tokens], [state, chatbot] + btn_list, ) - return state, model_selector, chatbot, textbox, send_btn, button_row, parameter_row + return [state, model_selector] def build_demo(models): with gr.Blocks( title="Chat with Open Large Language Models", - theme=gr.themes.Base(), + theme=gr.themes.Default(), css=block_css, ) as demo: url_params = gr.JSON(visible=False) - ( - state, - model_selector, - chatbot, - textbox, - send_btn, - button_row, - parameter_row, - ) = build_single_model_ui(models) + state, model_selector = build_single_model_ui(models) if args.model_list_mode not in ["once", "reload"]: raise ValueError(f"Unknown model list mode: {args.model_list_mode}") + + if args.show_terms_of_use: + load_js = get_window_url_params_with_tos_js + else: + load_js = get_window_url_params_js + demo.load( load_demo, [url_params], [ state, model_selector, - chatbot, - textbox, - send_btn, - button_row, - parameter_row, ], - _js=get_window_url_params_js, + _js=load_js, ) return demo @@ -728,29 +705,36 @@ def build_demo(models): parser.add_argument( "--share", action="store_true", - help="Whether to generate a public, shareable link.", + help="Whether to generate a public, shareable link", ) parser.add_argument( "--controller-url", type=str, default="http://localhost:21001", - help="The address of the controller.", + help="The address of the controller", ) parser.add_argument( "--concurrency-count", type=int, default=10, - help="The concurrency count of the gradio queue.", + help="The concurrency count of the gradio queue", ) parser.add_argument( "--model-list-mode", type=str, default="once", choices=["once", "reload"], - help="Whether to load the model list once or reload the model list every time.", + help="Whether to load the model list once or reload the model list every time", + ) + parser.add_argument( + "--moderate", + action="store_true", + help="Enable content moderation to block unsafe inputs", ) parser.add_argument( - "--moderate", action="store_true", help="Enable content moderation" + "--show-terms-of-use", + action="store_true", + help="Shows term of use before loading the demo", ) parser.add_argument( "--add-chatgpt", diff --git a/fastchat/serve/gradio_web_server_multi.py b/fastchat/serve/gradio_web_server_multi.py index 97aecc66c..92618d911 100644 --- a/fastchat/serve/gradio_web_server_multi.py +++ b/fastchat/serve/gradio_web_server_multi.py @@ -34,6 +34,7 @@ from fastchat.utils import ( build_logger, get_window_url_params_js, + get_window_url_params_with_tos_js, parse_gradio_auth_creds, ) @@ -105,68 +106,15 @@ def build_demo(models, elo_results_file, leaderboard_table_file): ) as demo: with gr.Tabs() as tabs: with gr.Tab("Chatbot Arena (battle)", id=0): - ( - b_states, - b_model_selectors, - b_chatbots, - b_textbox, - b_send_btn, - b_button_row, - b_parameter_row, - ) = build_side_by_side_ui_anony(models) - b_list = ( - b_states - + b_model_selectors - + b_chatbots - + [ - b_textbox, - b_send_btn, - b_button_row, - b_parameter_row, - ] - ) + side_by_side_anony_list = build_side_by_side_ui_anony(models) with gr.Tab("Chatbot Arena (side-by-side)", id=1): - ( - c_states, - c_model_selectors, - c_chatbots, - c_textbox, - c_send_btn, - c_button_row, - c_parameter_row, - ) = build_side_by_side_ui_named(models) - c_list = ( - c_states - + c_model_selectors - + c_chatbots - + [ - c_textbox, - c_send_btn, - c_button_row, - c_parameter_row, - ] - ) + side_by_side_named_list = build_side_by_side_ui_named(models) with gr.Tab("Single Model", id=2): - ( - a_state, - a_model_selector, - a_chatbot, - a_textbox, - a_send_btn, - a_button_row, - a_parameter_row, - ) = build_single_model_ui(models, add_promotion_links=True) - a_list = [ - a_state, - a_model_selector, - a_chatbot, - a_textbox, - a_send_btn, - a_button_row, - a_parameter_row, - ] + single_model_list = build_single_model_ui( + models, add_promotion_links=True + ) if elo_results_file: with gr.Tab("Leaderboard", id=3): @@ -176,11 +124,20 @@ def build_demo(models, elo_results_file, leaderboard_table_file): if args.model_list_mode not in ["once", "reload"]: raise ValueError(f"Unknown model list mode: {args.model_list_mode}") + + if args.show_terms_of_use: + load_js = get_window_url_params_with_tos_js + else: + load_js = get_window_url_params_js + demo.load( load_demo, [url_params], - [tabs] + a_list + b_list + c_list, - _js=get_window_url_params_js, + [tabs] + + single_model_list + + side_by_side_anony_list + + side_by_side_named_list, + _js=load_js, ) return demo @@ -193,19 +150,19 @@ def build_demo(models, elo_results_file, leaderboard_table_file): parser.add_argument( "--share", action="store_true", - help="Whether to generate a public, shareable link.", + help="Whether to generate a public, shareable link", ) parser.add_argument( "--controller-url", type=str, default="http://localhost:21001", - help="The address of the controller.", + help="The address of the controller", ) parser.add_argument( "--concurrency-count", type=int, default=10, - help="The concurrency count of the gradio queue.", + help="The concurrency count of the gradio queue", ) parser.add_argument( "--model-list-mode", @@ -215,7 +172,14 @@ def build_demo(models, elo_results_file, leaderboard_table_file): help="Whether to load the model list once or reload the model list every time.", ) parser.add_argument( - "--moderate", action="store_true", help="Enable content moderation" + "--moderate", + action="store_true", + help="Enable content moderation to block unsafe inputs", + ) + parser.add_argument( + "--show-terms-of-use", + action="store_true", + help="Shows term of use before loading the demo", ) parser.add_argument( "--add-chatgpt", @@ -248,8 +212,12 @@ def build_demo(models, elo_results_file, leaderboard_table_file): help='Set the gradio authentication file path. The file should contain one or more user:password pairs in this format: "u1:p1,u2:p2,u3:p3"', default=None, ) - parser.add_argument("--elo-results-file", type=str) - parser.add_argument("--leaderboard-table-file", type=str) + parser.add_argument( + "--elo-results-file", type=str, help="Load leaderboard results and plots" + ) + parser.add_argument( + "--leaderboard-table-file", type=str, help="Load leaderboard results and plots" + ) args = parser.parse_args() logger.info(f"args: {args}") diff --git a/fastchat/serve/monitor/dataset_release_scripts/lmsys_chat_1m/sample.py b/fastchat/serve/monitor/dataset_release_scripts/lmsys_chat_1m/sample.py new file mode 100644 index 000000000..3b6da455f --- /dev/null +++ b/fastchat/serve/monitor/dataset_release_scripts/lmsys_chat_1m/sample.py @@ -0,0 +1,32 @@ +""" +Count the unique users in a battle log file. + +Usage: +python3 -input in.json --number 1000 +""" + +import argparse +import json +import random + +K = 1000 + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--input", type=str) + parser.add_argument("--number", type=int, nargs="+") + args = parser.parse_args() + + convs = json.load(open(args.input)) + random.seed(42) + random.shuffle(convs) + + for number in args.number: + new_convs = convs[:number] + + output = args.input.replace(".json", f"_{number//K}k.json") + with open(output, "w") as fout: + json.dump(new_convs, fout, indent=2, ensure_ascii=False) + + print(f"#in: {len(convs)}, #out: {len(new_convs)}") + print(f"Write to file: {output}") diff --git a/fastchat/serve/monitor/summarize_cluster.py b/fastchat/serve/monitor/summarize_cluster.py index aa53c265d..1d5fbcddc 100644 --- a/fastchat/serve/monitor/summarize_cluster.py +++ b/fastchat/serve/monitor/summarize_cluster.py @@ -1,12 +1,14 @@ """ Usage: -python3 summarize_cluster.py --in results_c20_kmeans_cluster.pkl --model gpt-4 +python3 summarize_cluster.py --in results_c20_kmeans_cluster.pkl --model gpt-4 --num-prompts 100 +python3 summarize_cluster.py --in results_c20_kmeans_cluster.pkl --model azure-gpt-4-32k --num-prompts 200 """ import argparse import pickle from fastchat.llm_judge.common import ( chat_compeletion_openai, + chat_compeletion_openai_azure, chat_compeletion_anthropic, ) from fastchat.conversation import get_conv_template @@ -32,18 +34,26 @@ def truncate_string(s, l): topics = [] percentages = [] for i, info in enumerate(cluster_infos): - num_samples, prompts = info + num_samples, topk_prompts, random_prompts = info percentage = num_samples / num_total_prompts print( f"cluster {i}, #prompts {num_samples}, percentage: {percentage * 100:.2f}%" ) instruct = "Given a list of user messages, use less than 8 words to summarize a central topic for all messages in English. Your output should only include a single line. Try to be specific." + split = int(args.num_prompts * 0.8) prompt = "\n".join( - [truncate_string(x, l=200) for x in prompts[: args.num_prompts]] + [truncate_string(x, l=200) for x in topk_prompts[:split]] + + [ + truncate_string(x, l=200) + for x in random_prompts[: args.num_prompts - split] + ] ) prompt = "BEGIN OF THE MESSAGE LIST\n" + prompt + "\nEND OF THE MESSAGE LIST." - if "gpt" in model: + if "azure-" in model: + template_name = "chatgpt" + completion_func = chat_compeletion_openai_azure + elif "gpt" in model: template_name = "chatgpt" completion_func = chat_compeletion_openai elif "claude" in model: diff --git a/fastchat/serve/monitor/topic_clustering.py b/fastchat/serve/monitor/topic_clustering.py index 7710ce42a..dd15c6edc 100644 --- a/fastchat/serve/monitor/topic_clustering.py +++ b/fastchat/serve/monitor/topic_clustering.py @@ -2,7 +2,7 @@ Usage: python3 topic_clustering.py --in arena.json --english-only --min-length 32 -python3 topic_clustering.py --in clean_conv_20230809_100k.json --english-only --min-length 32 --max-length 1024 +python3 topic_clustering.py --in clean_conv_20230809_100k.json --english-only --min-length 32 --max-length 1536 """ import argparse import json @@ -90,7 +90,7 @@ def get_embeddings(texts, model_name, batch_size): def run_k_means(embeddings, num_clusters): - np.random.seed(0) + np.random.seed(42) clustering_model = KMeans(n_clusters=num_clusters, n_init="auto") clustering_model.fit(embeddings.numpy()) centers = torch.from_numpy(clustering_model.cluster_centers_) @@ -109,7 +109,7 @@ def run_k_means(embeddings, num_clusters): def run_agg_cluster(embeddings, num_clusters): - np.random.seed(0) + np.random.seed(42) clustering_model = AgglomerativeClustering(n_clusters=num_clusters) clustering_model.fit(embeddings) labels = torch.from_numpy(clustering_model.labels_) @@ -133,7 +133,7 @@ def run_agg_cluster(embeddings, num_clusters): def run_hdbscan_cluster(embeddings): import hdbscan - np.random.seed(0) + np.random.seed(42) clusterer = hdbscan.HDBSCAN(min_cluster_size=10) labels = torch.from_numpy(clusterer.fit_predict(embeddings)) @@ -183,13 +183,18 @@ def print_topk(texts, labels, topk_indices, show_cut_off): def get_cluster_info(texts, labels, topk_indices): + np.random.seed(42) + cluster_info = [] for k in range(len(topk_indices)): num_samples = torch.sum(labels == k).item() - prompts = [] + topk_prompts = [] for idx in topk_indices[k]: - prompts.append(texts[idx]) - cluster_info.append((num_samples, prompts)) + topk_prompts.append(texts[idx]) + random_prompts = [] + for idx in range(len(topk_indices)): + random_prompts.append(np.random.choice(texts)) + cluster_info.append((num_samples, topk_prompts, random_prompts)) return cluster_info @@ -238,8 +243,6 @@ def get_cluster_info(texts, labels, topk_indices): topk_str = print_topk(texts, labels, topk_indices, args.show_cut_off) num_clusters = len(centers) - cluster_info = get_cluster_info(texts, labels, topk_indices) - # Dump results filename_prefix = f"results_c{num_clusters}_{args.cluster_alg}" print(topk_str) @@ -259,5 +262,6 @@ def get_cluster_info(texts, labels, topk_indices): obj = {"cluster": i, "text": text, "sim": score.item()} fout.write(json.dumps(obj, ensure_ascii=False) + "\n") + cluster_info = get_cluster_info(texts, labels, topk_indices) with open(filename_prefix + "_cluster.pkl", "wb") as fout: pickle.dump(cluster_info, fout) diff --git a/fastchat/utils.py b/fastchat/utils.py index e2d3a6ac6..947d8b687 100644 --- a/fastchat/utils.py +++ b/fastchat/utils.py @@ -201,6 +201,20 @@ def pretty_print_semaphore(semaphore): """ +get_window_url_params_with_tos_js = """ +function() { + const params = new URLSearchParams(window.location.search); + url_params = Object.fromEntries(params); + console.log("url_params", url_params); + + msg = "Users of this website are required to agree to the following terms:\\nThe service is a research preview. It only provides limited safety measures and may generate offensive content. It must not be used for any illegal, harmful, violent, racist, or sexual purposes.\\nThe service collects user dialogue data and reserves the right to distribute it under a Creative Commons Attribution (CC-BY) license." + alert(msg); + + return url_params; + } +""" + + def iter_over_async( async_gen: AsyncGenerator, event_loop: AbstractEventLoop ) -> Generator: