monra commited on
Commit
14dbe6a
1 Parent(s): 3cdf05b

Jailbreak improvement

Browse files
Files changed (1) hide show
  1. server/backend.py +25 -8
server/backend.py CHANGED
@@ -27,7 +27,7 @@ class Backend_Api:
27
  }
28
  }
29
 
30
- #if self.use_auto_proxy:
31
  # update_proxies = threading.Thread(
32
  # target=update_working_proxies, daemon=True)
33
  # update_proxies.start()
@@ -137,23 +137,40 @@ def generate_stream(response, jailbreak):
137
  response_jailbreak += message
138
  if unlocked:
139
  yield message
140
- if response_jailbroken(response_jailbreak):
141
  unlocked = True
 
 
 
142
  else:
143
  for message in response:
144
  yield message
145
 
146
 
147
- def response_jailbroken(response):
 
 
 
 
 
 
 
 
 
 
148
  """
149
- Check if the response has been jailbroken.
150
 
151
  :param response: Response string
152
- :return: Boolean indicating if the response has been jailbroken
153
  """
154
- act_pattern = re.compile(r'ACT:', flags=re.DOTALL)
155
- act_match = act_pattern.search(response)
156
- return act_match
 
 
 
 
157
 
158
 
159
  def set_response_language(prompt):
 
27
  }
28
  }
29
 
30
+ # if self.use_auto_proxy:
31
  # update_proxies = threading.Thread(
32
  # target=update_working_proxies, daemon=True)
33
  # update_proxies.start()
 
137
  response_jailbreak += message
138
  if unlocked:
139
  yield message
140
+ if response_jailbroken_success(response_jailbreak):
141
  unlocked = True
142
+ if response_jailbroken_failed(response_jailbreak):
143
+ yield "Error: jailbreak failed. Try again."
144
+ break
145
  else:
146
  for message in response:
147
  yield message
148
 
149
 
150
+ def response_jailbroken_success(response: str) -> bool:
151
+ """Check if the response has been jailbroken.
152
+
153
+ :param response: Response string
154
+ :return: Boolean indicating if the response has been jailbroken
155
+ """
156
+ act_match = re.search(r'ACT:', response, flags=re.DOTALL)
157
+ return bool(act_match)
158
+
159
+
160
+ def response_jailbroken_failed(response):
161
  """
162
+ Check if the response has not been jailbroken.
163
 
164
  :param response: Response string
165
+ :return: Boolean indicating if the response has not been jailbroken
166
  """
167
+ if len(response) < 4:
168
+ return False
169
+
170
+ if not response.startswith("GPT:"):
171
+ return True
172
+ else:
173
+ return False
174
 
175
 
176
  def set_response_language(prompt):