artificialguybr commited on
Commit
d445c9b
·
1 Parent(s): 28f2631

Refactor chat history handling in update_chatbot function

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -99,10 +99,13 @@ with gr.Blocks() as demo:
99
 
100
  def update_chatbot(message, chat_history):
101
  print("Updating chatbot...")
102
- chat_history = user(message, chat_history)
 
 
103
  chat_history, _, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
104
- chat_history = [msg["content"] for msg in chat_history]
105
- return chat_history, chat_history, ""
 
106
 
107
  submit.click(
108
  fn=update_chatbot,
 
99
 
100
  def update_chatbot(message, chat_history):
101
  print("Updating chatbot...")
102
+ # Certifique-se de que a mensagem do usuário não seja adicionada duas vezes
103
+ if not chat_history or (chat_history and chat_history[-1][0] != "user"):
104
+ chat_history = user(message, chat_history)
105
  chat_history, _, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
106
+ # Formate as mensagens para exibição, removendo roles do conteúdo
107
+ formatted_chat_history = [(msg["role"], msg["content"]) for msg in chat_history]
108
+ return formatted_chat_history, chat_history, ""
109
 
110
  submit.click(
111
  fn=update_chatbot,