Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -72,7 +72,7 @@ import os
|
|
72 |
|
73 |
|
74 |
# Function to get bot response
|
75 |
-
def format_prompt(state, bot_index, character_name, character_description, user_name, num_messages=
|
76 |
if character_name is None or character_name.strip() == "":
|
77 |
character_name = "Ryan"
|
78 |
if character_description is None or character_description.strip() == "":
|
@@ -190,8 +190,9 @@ async def user_ask(state, chatbot1, chatbot2, textbox, character_name, character
|
|
190 |
{"role": "user", "content": user_input}])
|
191 |
state["history"][1].extend([
|
192 |
{"role": "user", "content": user_input}])
|
193 |
-
if len(state["history"])>20:
|
194 |
-
state["history"] = state["history"][-20:]
|
|
|
195 |
# Chat with bots
|
196 |
bot1_response, bot2_response = await chat_with_bots(user_input, state, character_name, character_description, user_name)
|
197 |
|
@@ -242,17 +243,27 @@ def generate_leaderboard(collection):
|
|
242 |
def refresh_leaderboard():
|
243 |
collection = init_database()
|
244 |
return generate_leaderboard(collection)
|
245 |
-
async def direct_chat(model, user_input, chatbot, character_name, character_description, user_name):
|
246 |
adapter = next(entry['adapter'] for entry in chatbots_data if entry['original_model'] == model)
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
temp_state = {
|
248 |
"history": [
|
249 |
-
[
|
250 |
-
[
|
251 |
]
|
252 |
}
|
|
|
253 |
response = await get_bot_response(adapter, user_input, temp_state, 0, character_name, character_description, user_name)
|
254 |
chatbot.append((user_input, response))
|
255 |
-
|
|
|
|
|
|
|
256 |
def reset_direct_chat():
|
257 |
return [], gr.Textbox.update(value='')
|
258 |
refresh_leaderboard()
|
@@ -316,8 +327,8 @@ with gr.Blocks() as demo:
|
|
316 |
# ...
|
317 |
|
318 |
direct_regenerate_btn.click(direct_regenerate, inputs=[model_dropdown, direct_textbox, direct_chatbot, character_name, character_description, user_name], outputs=[direct_textbox, direct_chatbot])
|
319 |
-
direct_textbox.submit(direct_chat, inputs=[model_dropdown, direct_textbox, direct_chatbot, character_name, character_description, user_name], outputs=[direct_textbox, direct_chatbot])
|
320 |
-
direct_submit_btn.click(direct_chat, inputs=[model_dropdown, direct_textbox, direct_chatbot, character_name, character_description, user_name], outputs=[direct_textbox, direct_chatbot])
|
321 |
direct_reset_btn.click(reset_direct_chat, None, [direct_chatbot, direct_textbox])
|
322 |
with gr.Tab("π Leaderboard"):
|
323 |
gr.Markdown("## π Check out the top-performing models!")
|
|
|
72 |
|
73 |
|
74 |
# Function to get bot response
|
75 |
+
def format_prompt(state, bot_index, character_name, character_description, user_name, num_messages=20):
|
76 |
if character_name is None or character_name.strip() == "":
|
77 |
character_name = "Ryan"
|
78 |
if character_description is None or character_description.strip() == "":
|
|
|
190 |
{"role": "user", "content": user_input}])
|
191 |
state["history"][1].extend([
|
192 |
{"role": "user", "content": user_input}])
|
193 |
+
if len(state["history"][0])>20:
|
194 |
+
state["history"][0] = state["history"][0][-20:]
|
195 |
+
state["history"][1] = state["history"][1][-20:]
|
196 |
# Chat with bots
|
197 |
bot1_response, bot2_response = await chat_with_bots(user_input, state, character_name, character_description, user_name)
|
198 |
|
|
|
243 |
def refresh_leaderboard():
|
244 |
collection = init_database()
|
245 |
return generate_leaderboard(collection)
|
246 |
+
async def direct_chat(model, user_input, state, chatbot, character_name, character_description, user_name):
|
247 |
adapter = next(entry['adapter'] for entry in chatbots_data if entry['original_model'] == model)
|
248 |
+
|
249 |
+
if "direct_history" not in state:
|
250 |
+
state["direct_history"] = []
|
251 |
+
|
252 |
+
state["direct_history"].append({"role": "user", "content": user_input})
|
253 |
+
|
254 |
temp_state = {
|
255 |
"history": [
|
256 |
+
state["direct_history"],
|
257 |
+
state["direct_history"]
|
258 |
]
|
259 |
}
|
260 |
+
|
261 |
response = await get_bot_response(adapter, user_input, temp_state, 0, character_name, character_description, user_name)
|
262 |
chatbot.append((user_input, response))
|
263 |
+
|
264 |
+
state["direct_history"].append({"role": "bot", "content": response})
|
265 |
+
|
266 |
+
return "", chatbot, state
|
267 |
def reset_direct_chat():
|
268 |
return [], gr.Textbox.update(value='')
|
269 |
refresh_leaderboard()
|
|
|
327 |
# ...
|
328 |
|
329 |
direct_regenerate_btn.click(direct_regenerate, inputs=[model_dropdown, direct_textbox, direct_chatbot, character_name, character_description, user_name], outputs=[direct_textbox, direct_chatbot])
|
330 |
+
direct_textbox.submit(direct_chat, inputs=[model_dropdown, direct_textbox, state, direct_chatbot, character_name, character_description, user_name], outputs=[direct_textbox, direct_chatbot, state])
|
331 |
+
direct_submit_btn.click(direct_chat, inputs=[model_dropdown, direct_textbox, state, direct_chatbot, character_name, character_description, user_name], outputs=[direct_textbox, direct_chatbot, state])
|
332 |
direct_reset_btn.click(reset_direct_chat, None, [direct_chatbot, direct_textbox])
|
333 |
with gr.Tab("π Leaderboard"):
|
334 |
gr.Markdown("## π Check out the top-performing models!")
|