Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,9 @@ from elo import update_elo_ratings # Custom function for ELO ratings
|
|
8 |
enable_btn = gr.Button.update(interactive=True)
|
9 |
|
10 |
# Load chatbot URLs and model names from a JSON file
|
11 |
-
|
12 |
-
|
|
|
13 |
def clear_chat(state):
|
14 |
# Reset state including the chatbot order
|
15 |
state = {} if state is not None else state
|
@@ -65,40 +66,34 @@ def format_alpaca_prompt(state):
|
|
65 |
j="### Response:\n"
|
66 |
alpaca_prompt2 += j+ message['content']+"\n\n"
|
67 |
return [alpaca_prompt+"### Response:\n",alpaca_prompt2+"### Response:\n"]
|
68 |
-
def get_bot_response(
|
69 |
alpaca_prompt = format_alpaca_prompt(state)
|
70 |
payload = {
|
71 |
-
"
|
72 |
-
|
73 |
-
"
|
74 |
-
|
75 |
-
|
76 |
-
"top_p":0.95
|
77 |
-
}
|
78 |
}
|
79 |
}
|
80 |
headers = {
|
81 |
-
"
|
82 |
-
"
|
83 |
-
"authorization": os.environ.get("RUNPOD_TOKEN")
|
84 |
}
|
85 |
-
response = requests.post(
|
86 |
-
return response.json()['
|
87 |
-
|
88 |
def chat_with_bots(user_input, state):
|
89 |
# Use existing bot order from state if available, otherwise shuffle and initialize
|
90 |
if 'last_bots' not in state or not state['last_bots']:
|
91 |
-
|
92 |
-
|
93 |
-
state['last_bots'] = [bot_names[0], bot_names[1]]
|
94 |
|
95 |
-
|
96 |
|
97 |
-
bot1_response = get_bot_response(
|
98 |
-
bot2_response = get_bot_response(
|
99 |
|
100 |
return bot1_response, bot2_response
|
101 |
-
|
102 |
def update_ratings(state, winner_index):
|
103 |
elo_ratings = get_user_elo_ratings()
|
104 |
bot_names = list(chatbots.keys())
|
|
|
8 |
enable_btn = gr.Button.update(interactive=True)
|
9 |
|
10 |
# Load chatbot URLs and model names from a JSON file
|
11 |
+
# Load chatbot model adapter names from a text file
|
12 |
+
with open('chatbots.txt', 'r') as file:
|
13 |
+
chatbots = file.read().splitlines()
|
14 |
def clear_chat(state):
|
15 |
# Reset state including the chatbot order
|
16 |
state = {} if state is not None else state
|
|
|
66 |
j="### Response:\n"
|
67 |
alpaca_prompt2 += j+ message['content']+"\n\n"
|
68 |
return [alpaca_prompt+"### Response:\n",alpaca_prompt2+"### Response:\n"]
|
69 |
+
def get_bot_response(adapter_id, prompt, state, bot_index):
|
70 |
alpaca_prompt = format_alpaca_prompt(state)
|
71 |
payload = {
|
72 |
+
"inputs": alpaca_prompt[bot_index],
|
73 |
+
"parameters": {
|
74 |
+
"adapter_id": adapter_id,
|
75 |
+
"adapter_source": "hub",
|
76 |
+
"temperature": 0.01
|
|
|
|
|
77 |
}
|
78 |
}
|
79 |
headers = {
|
80 |
+
"Content-Type": "application/json",
|
81 |
+
"Authorization": f"Bearer {os.environ.get('PREDIBASE_TOKEN')}"
|
|
|
82 |
}
|
83 |
+
response = requests.post("https://serving.app.predibase.com/79957f/deployments/v2/llms/mistral-7b/generate", json=payload, headers=headers)
|
84 |
+
return response.json()['generated_text'].split('### Instruction')[0]
|
|
|
85 |
def chat_with_bots(user_input, state):
|
86 |
# Use existing bot order from state if available, otherwise shuffle and initialize
|
87 |
if 'last_bots' not in state or not state['last_bots']:
|
88 |
+
random.shuffle(chatbots)
|
89 |
+
state['last_bots'] = [chatbots[0], chatbots[1]]
|
|
|
90 |
|
91 |
+
bot1_adapter, bot2_adapter = state['last_bots'][0], state['last_bots'][1]
|
92 |
|
93 |
+
bot1_response = get_bot_response(bot1_adapter, user_input, state, 0)
|
94 |
+
bot2_response = get_bot_response(bot2_adapter, user_input, state, 1)
|
95 |
|
96 |
return bot1_response, bot2_response
|
|
|
97 |
def update_ratings(state, winner_index):
|
98 |
elo_ratings = get_user_elo_ratings()
|
99 |
bot_names = list(chatbots.keys())
|