mrcuddle commited on
Commit
e57b01b
·
verified ·
1 Parent(s): 61d7cec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -0
app.py CHANGED
@@ -17,8 +17,14 @@ system_prompt = (
17
  "If you don't know an answer, say 'I'm not sure about that, but I can try to help further!'"
18
  )
19
 
 
 
 
20
  @spaces.GPU # For ZeroGPU compatibility
21
  def chatbot(message, history):
 
 
 
22
  # Combine the system prompt with chat history and user message
23
  conversation = system_prompt + "\n"
24
  conversation += "".join([f"User: {msg}\nBot: {resp}\n" for msg, resp in history])
 
17
  "If you don't know an answer, say 'I'm not sure about that, but I can try to help further!'"
18
  )
19
 
20
+ # Limit chat history length
21
+ MAX_HISTORY_LENGTH = 5 # Keep only the last 5 turns to prevent excessive context size
22
+
23
  @spaces.GPU # For ZeroGPU compatibility
24
  def chatbot(message, history):
25
+ # Keep only the most recent entries in history
26
+ history = history[-MAX_HISTORY_LENGTH:]
27
+
28
  # Combine the system prompt with chat history and user message
29
  conversation = system_prompt + "\n"
30
  conversation += "".join([f"User: {msg}\nBot: {resp}\n" for msg, resp in history])