str-platformAI samayg commited on
Commit
e80f35b
·
1 Parent(s): 69cc8c8

Keeps latest 5 messages in chatbot history (#10)

Browse files

- Keeps latest 5 messages in chatbot history (0eebe9178e5e0e11891c181d29d09ef02997d0e0)


Co-authored-by: Samay gandhi <samayg@users.noreply.huggingface.co>

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