Dongfu Jiang commited on
Commit
a0937f6
1 Parent(s): 469c801
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -45,18 +45,22 @@ import random
45
  random.seed(42)
46
  np.random.seed(42)
47
  def sample_an_feedback(selected_models):
48
- shuffled_dataset = dataset.shuffle()
49
  feedback = None
50
- for example in tqdm(shuffled_dataset, total=len(shuffled_dataset), desc="Searching for valid examples"):
 
 
51
  example_model_responses = example['responses']
52
  valid_model_responses = [model_response for model_response in example_model_responses if model_response['model'] in selected_models]
53
  if len(valid_model_responses) >= 2:
54
- feedback = example
55
- model_response_1, model_response_2 = random.sample(valid_model_responses, 2)
56
- break
57
- if not feedback:
58
  return gr.Exit("No valid examples found. Please select other models.")
59
 
 
 
 
 
60
  plan_history = {
61
  "user": [
62
  feedback['query'],
 
45
  random.seed(42)
46
  np.random.seed(42)
47
  def sample_an_feedback(selected_models):
 
48
  feedback = None
49
+ all_valid_feedbacks = []
50
+ all_valid_model_responses = []
51
+ for example in tqdm(dataset, total=len(dataset), desc="Searching for valid examples"):
52
  example_model_responses = example['responses']
53
  valid_model_responses = [model_response for model_response in example_model_responses if model_response['model'] in selected_models]
54
  if len(valid_model_responses) >= 2:
55
+ all_valid_feedbacks.append(example)
56
+ all_valid_model_responses.append(random.sample(valid_model_responses, 2))
57
+ if len(all_valid_feedbacks) == 0:
 
58
  return gr.Exit("No valid examples found. Please select other models.")
59
 
60
+ random_idx = random.randint(0, len(all_valid_feedbacks) - 1)
61
+ feedback = all_valid_feedbacks[random_idx]
62
+ model_response_1, model_response_2 = all_valid_model_responses[random_idx]
63
+
64
  plan_history = {
65
  "user": [
66
  feedback['query'],