k-mktr commited on
Commit
268d9a1
·
verified ·
1 Parent(s): 0ee4c85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -33,6 +33,16 @@ start_backup_thread()
33
  def get_available_models():
34
  return [model[0] for model in arena_config.APPROVED_MODELS]
35
 
 
 
 
 
 
 
 
 
 
 
36
  # Function to call Ollama API with caching
37
  @lru_cache(maxsize=100)
38
  def call_ollama_api(model, prompt):
@@ -84,9 +94,20 @@ def generate_responses(prompt):
84
  # Select the first model (least battles)
85
  model_a = sorted_models[0]
86
 
 
 
 
 
 
 
 
 
87
  # For the second model, use weighted random selection
88
- weights = [1 / (battle_counts.get(m, 1) + 1) for m in sorted_models[1:]]
89
- model_b = random.choices(sorted_models[1:], weights=weights, k=1)[0]
 
 
 
90
 
91
  model_a_response = call_ollama_api(model_a, prompt)
92
  model_b_response = call_ollama_api(model_b, prompt)
@@ -555,4 +576,4 @@ with gr.Blocks(css="""
555
  if __name__ == "__main__":
556
  # Initialize ELO ratings before launching the app
557
  ensure_elo_ratings_initialized()
558
- demo.launch(show_api=False)
 
33
  def get_available_models():
34
  return [model[0] for model in arena_config.APPROVED_MODELS]
35
 
36
+ # Function to get recent opponents for a model
37
+ recent_opponents = {}
38
+
39
+ def update_recent_opponents(model_a, model_b):
40
+ recent_opponents.setdefault(model_a, []).append(model_b)
41
+ recent_opponents.setdefault(model_b, []).append(model_a)
42
+ # Limit history to last 5 opponents
43
+ recent_opponents[model_a] = recent_opponents[model_a][-5:]
44
+ recent_opponents[model_b] = recent_opponents[model_b][-5:]
45
+
46
  # Function to call Ollama API with caching
47
  @lru_cache(maxsize=100)
48
  def call_ollama_api(model, prompt):
 
94
  # Select the first model (least battles)
95
  model_a = sorted_models[0]
96
 
97
+ # Filter out recent opponents for model_a
98
+ potential_opponents = [m for m in sorted_models[1:] if m not in recent_opponents.get(model_a, [])]
99
+
100
+ # If no potential opponents left, reset recent opponents for model_a
101
+ if not potential_opponents:
102
+ recent_opponents[model_a] = []
103
+ potential_opponents = sorted_models[1:]
104
+
105
  # For the second model, use weighted random selection
106
+ weights = [1 / (battle_counts.get(m, 1) + 1) for m in potential_opponents]
107
+ model_b = random.choices(potential_opponents, weights=weights, k=1)[0]
108
+
109
+ # Update recent opponents
110
+ update_recent_opponents(model_a, model_b)
111
 
112
  model_a_response = call_ollama_api(model_a, prompt)
113
  model_b_response = call_ollama_api(model_b, prompt)
 
576
  if __name__ == "__main__":
577
  # Initialize ELO ratings before launching the app
578
  ensure_elo_ratings_initialized()
579
+ demo.launch(show_api=False)