Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -128,17 +128,17 @@ async def get_bot_response(adapter_id, prompt, state, bot_index, character_name,
|
|
128 |
except (aiohttp.ClientError, asyncio.TimeoutError):
|
129 |
response_text = "Sorry, I couldn't generate a response."
|
130 |
return response_text.strip()
|
131 |
-
async def chat_with_bots(user_input, state, character_name, character_description):
|
132 |
# Use existing bot order from state if available, otherwise shuffle and initialize
|
133 |
if 'last_bots' not in state or not state['last_bots']:
|
134 |
random.shuffle(chatbots)
|
135 |
state['last_bots'] = [chatbots[0], chatbots[1]]
|
136 |
|
137 |
bot1_adapter, bot2_adapter = state['last_bots'][0], state['last_bots'][1]
|
138 |
-
|
139 |
bot1_response, bot2_response = await asyncio.gather(
|
140 |
-
get_bot_response(bot1_adapter, user_input, state, 0, character_name, character_description),
|
141 |
-
get_bot_response(bot2_adapter, user_input, state, 1, character_name, character_description)
|
142 |
)
|
143 |
return bot1_response.replace("<|im_end|>",""), bot2_response.replace("<|im_end|>","")
|
144 |
def update_ratings(state, winner_index, collection):
|
@@ -167,7 +167,7 @@ def vote_down_model(state, chatbot, chatbot2):
|
|
167 |
chatbot.append(update_message[1])
|
168 |
return chatbot, chatbot2, gr.Button.update(interactive=False), gr.Button.update(interactive=False), gr.Textbox.update(interactive=False), gr.Button.update(interactive=False)
|
169 |
|
170 |
-
async def user_ask(state, chatbot1, chatbot2, textbox, character_name, character_description):
|
171 |
global enable_btn
|
172 |
user_input = textbox
|
173 |
if len(user_input) > 200:
|
@@ -184,7 +184,7 @@ async def user_ask(state, chatbot1, chatbot2, textbox, character_name, character
|
|
184 |
state["history"][1].extend([
|
185 |
{"role": "user", "content": user_input}])
|
186 |
# Chat with bots
|
187 |
-
bot1_response, bot2_response = await chat_with_bots(user_input, state, character_name, character_description)
|
188 |
|
189 |
state["history"][0].extend([
|
190 |
{"role": "bot1", "content": bot1_response},
|
|
|
128 |
except (aiohttp.ClientError, asyncio.TimeoutError):
|
129 |
response_text = "Sorry, I couldn't generate a response."
|
130 |
return response_text.strip()
|
131 |
+
async def chat_with_bots(user_input, state, character_name, character_description, user_name):
|
132 |
# Use existing bot order from state if available, otherwise shuffle and initialize
|
133 |
if 'last_bots' not in state or not state['last_bots']:
|
134 |
random.shuffle(chatbots)
|
135 |
state['last_bots'] = [chatbots[0], chatbots[1]]
|
136 |
|
137 |
bot1_adapter, bot2_adapter = state['last_bots'][0], state['last_bots'][1]
|
138 |
+
|
139 |
bot1_response, bot2_response = await asyncio.gather(
|
140 |
+
get_bot_response(bot1_adapter, user_input, state, 0, character_name, character_description, user_name),
|
141 |
+
get_bot_response(bot2_adapter, user_input, state, 1, character_name, character_description, user_name)
|
142 |
)
|
143 |
return bot1_response.replace("<|im_end|>",""), bot2_response.replace("<|im_end|>","")
|
144 |
def update_ratings(state, winner_index, collection):
|
|
|
167 |
chatbot.append(update_message[1])
|
168 |
return chatbot, chatbot2, gr.Button.update(interactive=False), gr.Button.update(interactive=False), gr.Textbox.update(interactive=False), gr.Button.update(interactive=False)
|
169 |
|
170 |
+
async def user_ask(state, chatbot1, chatbot2, textbox, character_name, character_description, user_name):
|
171 |
global enable_btn
|
172 |
user_input = textbox
|
173 |
if len(user_input) > 200:
|
|
|
184 |
state["history"][1].extend([
|
185 |
{"role": "user", "content": user_input}])
|
186 |
# Chat with bots
|
187 |
+
bot1_response, bot2_response = await chat_with_bots(user_input, state, character_name, character_description, user_name)
|
188 |
|
189 |
state["history"][0].extend([
|
190 |
{"role": "bot1", "content": bot1_response},
|