Keeps latest 5 messages in chatbot history

#10
by samayg - opened
Files changed (1) hide show
  1. app.py +2 -0
app.py CHANGED
@@ -117,6 +117,8 @@ with gr.Blocks(theme='samayg/StriimTheme', css=CSS) as demo:
117
 
118
  # Append user message and response to chat history
119
  chat_history.append((query, answer))
 
 
120
  return gr.update(value=""), chat_history
121
 
122
  # The msg.submit() now also depends on the status of the internet_access checkbox
 
117
 
118
  # Append user message and response to chat history
119
  chat_history.append((query, answer))
120
+ # Only keeps last 5 messages to not exceed tokens
121
+ chat_history = chat_history[-5:]
122
  return gr.update(value=""), chat_history
123
 
124
  # The msg.submit() now also depends on the status of the internet_access checkbox