Jae-Won Chung commited on
Commit
3c356de
1 Parent(s): 946a6c9

Reset to random

Browse files
Files changed (2) hide show
  1. app.py +7 -5
  2. spitfight/colosseum/client.py +1 -1
app.py CHANGED
@@ -366,9 +366,11 @@ controller_addr = os.environ["COLOSSEUM_CONTROLLER_ADDR"]
366
  global_controller_client = ControllerClient(controller_addr=controller_addr, timeout=15)
367
 
368
  # Load the list of models. To reload, the app should be restarted.
 
 
369
  global_available_models = global_controller_client.get_available_models()
370
  model_name_to_user_pref = {model: f"One is {model}" for model in global_available_models}
371
- model_name_to_user_pref["Random"] = "Two random models"
372
  user_pref_to_model_name = {v: k for k, v in model_name_to_user_pref.items()}
373
 
374
  # Colosseum helper functions.
@@ -406,7 +408,7 @@ def on_load():
406
  dataframe = global_tbm.set_filter_get_df()
407
  available_models = copy.deepcopy(global_available_models)
408
  random.shuffle(available_models)
409
- available_models.insert(0, "Random")
410
  return dataframe, gr.Dropdown.update(choices=[model_name_to_user_pref[model] for model in available_models])
411
 
412
  def add_prompt_disable_submit(prompt, history_a, history_b):
@@ -492,7 +494,7 @@ def make_energy_vote_func(is_worth: bool):
492
  def play_again():
493
  available_models = copy.deepcopy(global_available_models)
494
  random.shuffle(available_models)
495
- available_models.insert(0, "Random")
496
  return [
497
  # Clear chatbot history
498
  None, None,
@@ -503,7 +505,7 @@ def play_again():
503
  # Hide energy vote buttons and message
504
  gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Markdown.update(visible=False),
505
  # Enable model preference dropdown and shuffle choices
506
- gr.Dropdown.update(choices=[model_name_to_user_pref[model] for model in available_models], interactive=True),
507
  # Disable reset button
508
  gr.Button.update(interactive=False, visible=False),
509
  ]
@@ -531,7 +533,7 @@ with gr.Blocks(css=custom_css) as block:
531
 
532
  with gr.Row():
533
  model_preference_dropdown = gr.Dropdown(
534
- value="Two random models",
535
  label="Prefer a specific model?",
536
  interactive=True,
537
  )
 
366
  global_controller_client = ControllerClient(controller_addr=controller_addr, timeout=15)
367
 
368
  # Load the list of models. To reload, the app should be restarted.
369
+ RANDOM_MODEL_NAME = "Random"
370
+ RANDOM_USER_PREFERENCE = "Two random models"
371
  global_available_models = global_controller_client.get_available_models()
372
  model_name_to_user_pref = {model: f"One is {model}" for model in global_available_models}
373
+ model_name_to_user_pref[RANDOM_MODEL_NAME] = RANDOM_USER_PREFERENCE
374
  user_pref_to_model_name = {v: k for k, v in model_name_to_user_pref.items()}
375
 
376
  # Colosseum helper functions.
 
408
  dataframe = global_tbm.set_filter_get_df()
409
  available_models = copy.deepcopy(global_available_models)
410
  random.shuffle(available_models)
411
+ available_models.insert(0, RANDOM_MODEL_NAME)
412
  return dataframe, gr.Dropdown.update(choices=[model_name_to_user_pref[model] for model in available_models])
413
 
414
  def add_prompt_disable_submit(prompt, history_a, history_b):
 
494
  def play_again():
495
  available_models = copy.deepcopy(global_available_models)
496
  random.shuffle(available_models)
497
+ available_models.insert(0, RANDOM_MODEL_NAME)
498
  return [
499
  # Clear chatbot history
500
  None, None,
 
505
  # Hide energy vote buttons and message
506
  gr.Button.update(visible=False), gr.Button.update(visible=False), gr.Markdown.update(visible=False),
507
  # Enable model preference dropdown and shuffle choices
508
+ gr.Dropdown.update(value=RANDOM_USER_PREFERENCE, choices=[model_name_to_user_pref[model] for model in available_models], interactive=True),
509
  # Disable reset button
510
  gr.Button.update(interactive=False, visible=False),
511
  ]
 
533
 
534
  with gr.Row():
535
  model_preference_dropdown = gr.Dropdown(
536
+ value=RANDOM_USER_PREFERENCE,
537
  label="Prefer a specific model?",
538
  interactive=True,
539
  )
spitfight/colosseum/client.py CHANGED
@@ -58,7 +58,7 @@ class ControllerClient:
58
  """Generate the response of the `index`th model with the prompt.
59
 
60
  `user_pref` is the user's preference for the model to use. It can be
61
- `"random"` or one of the models in the list returned by `get_available_models`.
62
  """
63
  prompt_request = PromptRequest(
64
  request_id=self.request_id,
 
58
  """Generate the response of the `index`th model with the prompt.
59
 
60
  `user_pref` is the user's preference for the model to use. It can be
61
+ `"Random"` or one of the models in the list returned by `get_available_models`.
62
  """
63
  prompt_request = PromptRequest(
64
  request_id=self.request_id,