R3troR0b commited on
Commit
7017325
·
verified ·
1 Parent(s): f0fd2d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -27,6 +27,15 @@ def respond(
27
 
28
  response = ""
29
 
 
 
 
 
 
 
 
 
 
30
  # Use text-generation instead of chat-completion
31
  for message in client.text_generation(
32
  prompt=prompt,
@@ -62,4 +71,4 @@ demo = gr.ChatInterface(
62
 
63
 
64
  if __name__ == "__main__":
65
- demo.launch()
 
27
 
28
  response = ""
29
 
30
+ # Prevent infinite loops by limiting history and avoiding repeated responses
31
+ if len(history) > 5: # Limit history to the last 5 exchanges
32
+ history = history[-5:]
33
+
34
+ # Detect if responses are getting repetitive and stop the loop
35
+ if len(set([h[1] for h in history])) == 1: # All assistant's responses are the same
36
+ yield "It seems we're repeating ourselves. Let's move to a new topic."
37
+ return
38
+
39
  # Use text-generation instead of chat-completion
40
  for message in client.text_generation(
41
  prompt=prompt,
 
71
 
72
 
73
  if __name__ == "__main__":
74
+ demo.launch()