artificialguybr commited on
Commit
99f63a1
·
1 Parent(s): 759d118

Refactor chat history formatting in app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -82,9 +82,11 @@ with gr.Blocks() as demo:
82
  if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
83
  chat_history = user(message, chat_history)
84
  chat_history, _ = chat(chat_history, BASE_SYSTEM_MESSAGE, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
85
- # Remove roles from the chat history
86
- formatted_chat_history = [[msg["content"] for msg in chat_history if msg["role"] == "user"],
87
- [msg["content"] for msg in chat_history if msg["role"] == "assistant"]]
 
 
88
  return formatted_chat_history, chat_history, ""
89
 
90
 
 
82
  if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
83
  chat_history = user(message, chat_history)
84
  chat_history, _ = chat(chat_history, BASE_SYSTEM_MESSAGE, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
85
+ # Format the chat history for the gr.Chatbot component
86
+ formatted_chat_history = []
87
+ for user_msg, assistant_msg in zip([msg["content"] for msg in chat_history if msg["role"] == "user"],
88
+ [msg["content"] for msg in chat_history if msg["role"] == "assistant"]):
89
+ formatted_chat_history.append([user_msg, assistant_msg])
90
  return formatted_chat_history, chat_history, ""
91
 
92