artificialguybr commited on
Commit
bce3dcd
1 Parent(s): 9ab3033

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -26,10 +26,12 @@ def regenerate(_chatbot, _task_history, system_msg, max_tokens, temperature, top
26
  if not _task_history:
27
  yield _chatbot
28
  return
29
- # Remove the last bot message
30
- last_message = _task_history[-1]
31
- if last_message[1]: # Check if the bot actually sent a message last
32
- last_message[1] = ""
 
 
33
 
34
  # Regenerate the message using the chat function
35
  new_history, _, _ = chat(_task_history, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty)
@@ -39,6 +41,7 @@ def regenerate(_chatbot, _task_history, system_msg, max_tokens, temperature, top
39
 
40
 
41
 
 
42
  def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
43
  history = history or []
44
 
@@ -139,5 +142,6 @@ with gr.Blocks() as demo:
139
  fn=regenerate, inputs=[chatbot, chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty], outputs=[chatbot], queue=True
140
  )
141
 
 
142
  demo.queue(max_size=128, concurrency_count=2)
143
  demo.launch()
 
26
  if not _task_history:
27
  yield _chatbot
28
  return
29
+ # Remove the last bot message from history
30
+ last_message = _task_history.pop(-1)
31
+ _chatbot.pop(-1)
32
+
33
+ # Re-add the user's part of the last message to history
34
+ _task_history.append([last_message[0], ""])
35
 
36
  # Regenerate the message using the chat function
37
  new_history, _, _ = chat(_task_history, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty)
 
41
 
42
 
43
 
44
+
45
  def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetition_penalty):
46
  history = history or []
47
 
 
142
  fn=regenerate, inputs=[chatbot, chat_history_state, system_msg, max_tokens, temperature, top_p, top_k, repetition_penalty], outputs=[chatbot], queue=True
143
  )
144
 
145
+
146
  demo.queue(max_size=128, concurrency_count=2)
147
  demo.launch()