rwitz commited on
Commit
033caa5
·
1 Parent(s): 50a8cb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -12,7 +12,7 @@ with open('chatbot_urls.json', 'r') as file:
12
 
13
  # Initialize or get user-specific ELO ratings
14
  def get_user_elo_ratings(state):
15
- return state['elo_ratings']
16
 
17
  # Read and write ELO ratings to file (thread-safe)
18
  def read_elo_ratings():
@@ -29,7 +29,7 @@ def write_elo_ratings(elo_ratings):
29
  # Function to get bot response
30
  def format_chatml_prompt(state):
31
  chatml_prompt = ""
32
- for message in state["history"]:
33
  chatml_prompt += f"<|im_start|> "+message['role']+"- "+ message['content']+"<|im_end|>\n"
34
  return chatml_prompt
35
  def get_bot_response(url, prompt):
@@ -67,8 +67,8 @@ def chat_with_bots(user_input, state):
67
  def update_ratings(state, winner_index):
68
  elo_ratings = get_user_elo_ratings()
69
  bot_names = list(chatbots.keys())
70
- winner = state['last_bots'][winner_index]
71
- loser = state['last_bots'][1 - winner_index]
72
 
73
  elo_ratings = update_elo_ratings(elo_ratings, winner, loser)
74
  write_elo_ratings(elo_ratings)
@@ -92,7 +92,7 @@ def user_ask(state, chatbot1, chatbot2, textbox):
92
  # Updating state with the current ELO ratings
93
  state["elo_ratings"] = read_elo_ratings()
94
  if "history" not in state:
95
- state['history']=[]
96
  state["history"].extend([
97
  {"role": "user", "content": user_input}])
98
  # Chat with bots
@@ -100,8 +100,8 @@ def user_ask(state, chatbot1, chatbot2, textbox):
100
 
101
  # Update chat history in state
102
  if "history" not in state:
103
- state["history"] = []
104
- state["history"].extend([
105
  {"role": "bot1", "content": bot1_response},
106
  {"role": "bot2", "content": bot2_response}
107
  ])
 
12
 
13
  # Initialize or get user-specific ELO ratings
14
  def get_user_elo_ratings(state):
15
+ return state.value['elo_ratings']
16
 
17
  # Read and write ELO ratings to file (thread-safe)
18
  def read_elo_ratings():
 
29
  # Function to get bot response
30
  def format_chatml_prompt(state):
31
  chatml_prompt = ""
32
+ for message in state.value["history"]:
33
  chatml_prompt += f"<|im_start|> "+message['role']+"- "+ message['content']+"<|im_end|>\n"
34
  return chatml_prompt
35
  def get_bot_response(url, prompt):
 
67
  def update_ratings(state, winner_index):
68
  elo_ratings = get_user_elo_ratings()
69
  bot_names = list(chatbots.keys())
70
+ winner = state.value['last_bots'][winner_index]
71
+ loser = state.value['last_bots'][1 - winner_index]
72
 
73
  elo_ratings = update_elo_ratings(elo_ratings, winner, loser)
74
  write_elo_ratings(elo_ratings)
 
92
  # Updating state with the current ELO ratings
93
  state["elo_ratings"] = read_elo_ratings()
94
  if "history" not in state:
95
+ state.update({'history': [])
96
  state["history"].extend([
97
  {"role": "user", "content": user_input}])
98
  # Chat with bots
 
100
 
101
  # Update chat history in state
102
  if "history" not in state:
103
+ state.update({'history': [])
104
+ state["history"].append([
105
  {"role": "bot1", "content": bot1_response},
106
  {"role": "bot2", "content": bot2_response}
107
  ])