Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,19 +29,27 @@ def write_elo_ratings(elo_ratings):
|
|
| 29 |
# Function to get bot response
|
| 30 |
def format_alpaca_prompt(state):
|
| 31 |
alpaca_prompt = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
|
| 32 |
-
|
|
|
|
| 33 |
j=""
|
| 34 |
if message['role']=='user':
|
| 35 |
j="### Instruction:\n"
|
| 36 |
else:
|
| 37 |
j="### Response:\n"
|
| 38 |
alpaca_prompt += j+ message['content']+"\n\n"
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
alpaca_prompt = format_alpaca_prompt(state)
|
| 42 |
payload = {
|
| 43 |
"input": {
|
| 44 |
-
"prompt": alpaca_prompt,
|
| 45 |
"sampling_params": {
|
| 46 |
"max_new_tokens": 50,
|
| 47 |
"temperature": 0.7,
|
|
@@ -65,8 +73,8 @@ def chat_with_bots(user_input, state):
|
|
| 65 |
# Update the state with the names of the last bots
|
| 66 |
state.update({'last_bots': [bot_names[0], bot_names[1]]})
|
| 67 |
|
| 68 |
-
bot1_response = get_bot_response(bot1_url, user_input,state)
|
| 69 |
-
bot2_response = get_bot_response(bot2_url, user_input,state)
|
| 70 |
|
| 71 |
return bot1_response, bot2_response
|
| 72 |
|
|
|
|
| 29 |
# Function to get bot response
|
| 30 |
def format_alpaca_prompt(state):
|
| 31 |
alpaca_prompt = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
|
| 32 |
+
alpaca_prompt2 = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
|
| 33 |
+
for message in state["history"][0]:
|
| 34 |
j=""
|
| 35 |
if message['role']=='user':
|
| 36 |
j="### Instruction:\n"
|
| 37 |
else:
|
| 38 |
j="### Response:\n"
|
| 39 |
alpaca_prompt += j+ message['content']+"\n\n"
|
| 40 |
+
for message in state["history"][1]:
|
| 41 |
+
j=""
|
| 42 |
+
if message['role']=='user':
|
| 43 |
+
j="### Instruction:\n"
|
| 44 |
+
else:
|
| 45 |
+
j="### Response:\n"
|
| 46 |
+
alpaca_prompt2 += j+ message['content']+"\n\n"
|
| 47 |
+
return [alpaca_prompt+"### Response:\n",alpaca_prompt2+"### Response:\n"]
|
| 48 |
+
def get_bot_response(url, prompt,state,bot_index):
|
| 49 |
alpaca_prompt = format_alpaca_prompt(state)
|
| 50 |
payload = {
|
| 51 |
"input": {
|
| 52 |
+
"prompt": alpaca_prompt[bot_index],
|
| 53 |
"sampling_params": {
|
| 54 |
"max_new_tokens": 50,
|
| 55 |
"temperature": 0.7,
|
|
|
|
| 73 |
# Update the state with the names of the last bots
|
| 74 |
state.update({'last_bots': [bot_names[0], bot_names[1]]})
|
| 75 |
|
| 76 |
+
bot1_response = get_bot_response(bot1_url, user_input,state,0)
|
| 77 |
+
bot2_response = get_bot_response(bot2_url, user_input,state,1)
|
| 78 |
|
| 79 |
return bot1_response, bot2_response
|
| 80 |
|