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

Refactor chat history formatting in app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -82,13 +82,9 @@ 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
- # Adjust the formatting of the chat history for the Gradio Chatbot component
86
- formatted_chat_history = []
87
- for msg in chat_history:
88
- if msg["role"] == "user":
89
- formatted_chat_history.append(["user", msg["content"]])
90
- else:
91
- formatted_chat_history.append(["bot", msg["content"]]) # Change 'assistant' to 'bot' for clarity in the UI
92
  return formatted_chat_history, chat_history, ""
93
 
94
 
 
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