artificialguybr commited on
Commit
2123ed3
·
1 Parent(s): 37ff396

Refactor chatbot message handling and formatting

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -75,14 +75,15 @@ with gr.Blocks() as demo:
75
 
76
  def update_chatbot(message, chat_history):
77
  print("Updating chatbot...")
78
- # Certifique-se de que a mensagem do usuário não seja adicionada duas vezes
79
- if not chat_history or (chat_history and chat_history[-1][0] != "user"):
80
  chat_history = user(message, chat_history)
81
- chat_history, _, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
82
- # Formate as mensagens para exibição, removendo roles do conteúdo
83
  formatted_chat_history = [(msg["role"], msg["content"]) for msg in chat_history]
84
  return formatted_chat_history, chat_history, ""
85
 
 
86
  submit.click(
87
  fn=update_chatbot,
88
  inputs=[message, chat_history_state],
 
75
 
76
  def update_chatbot(message, chat_history):
77
  print("Updating chatbot...")
78
+ # Ensure the user's message is not added twice
79
+ if not chat_history or (chat_history and chat_history[-1]["role"] != "user"):
80
  chat_history = user(message, chat_history)
81
+ chat_history, _ = chat(chat_history, system_msg.value, max_tokens.value, temperature.value, top_p.value, 40, 1.1)
82
+ # Format messages for display, removing roles from content
83
  formatted_chat_history = [(msg["role"], msg["content"]) for msg in chat_history]
84
  return formatted_chat_history, chat_history, ""
85
 
86
+
87
  submit.click(
88
  fn=update_chatbot,
89
  inputs=[message, chat_history_state],