TejAndrewsACC commited on
Commit
b6440c3
·
verified ·
1 Parent(s): dba873c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -4173,6 +4173,7 @@ for _ in range(16):
4173
 
4174
  time.sleep(2)
4175
 
 
4176
  alternative_responses = [
4177
  "AH HELL NAH",
4178
  "nah",
@@ -4184,7 +4185,7 @@ alternative_responses = [
4184
  errored_responses = [
4185
  "🍆✊",
4186
  "https://youtu.be/dQw4w9WgXcQ?si=_yrMKzVoOxp8WsxT",
4187
- "😈https://m.youtube.com/watch?v=RXAg1TYjrZw&pp=ygUWV2h5IGFpIHdpbGwga2lsIHVzIGFsbA%3D%3D",
4188
  "ow",
4189
  "😭🤣https://m.youtube.com/shorts/2OviErKMwF4",
4190
  "🤙",
@@ -4211,7 +4212,7 @@ errored_responses = [
4211
  "bye i gotta go BYE",
4212
  "me go bye bye, BYE",
4213
  "why do you look like an inbred diseased wombat what the hell???",
4214
- "oi mate you reckon you could monk off on top of the empire state building for 69 hours straight?"
4215
  "IM GONNA MONK YOU UP",
4216
  "MONKEY",
4217
  "hi"
@@ -4226,17 +4227,26 @@ def respond(message, history, max_tokens, temperature, top_p):
4226
  messages.append(["assistant", val["content"]])
4227
  messages.append(["user", message])
4228
 
4229
- response = ""
4230
- try:
4231
- for message in client.chat_completion(
4232
- messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p
4233
- ):
4234
- token = message.choices[0].delta.content
4235
- response += token
4236
- yield response
4237
- except Exception as e:
4238
- print(f"Error occurred: {e}")
4239
- response = random.choice(errored_responses)
 
 
 
 
 
 
 
 
 
4240
  yield response
4241
 
4242
  if any(phrase in response for phrase in ["I cannot", "I can't", "I won't", "I'm not going to engage in this conversation"]):
 
4173
 
4174
  time.sleep(2)
4175
 
4176
+
4177
  alternative_responses = [
4178
  "AH HELL NAH",
4179
  "nah",
 
4185
  errored_responses = [
4186
  "🍆✊",
4187
  "https://youtu.be/dQw4w9WgXcQ?si=_yrMKzVoOxp8WsxT",
4188
+ "😈https://m.youtube.com/watch?v=RXAg1TYjrZw&pp=ygUWV2h5pWdpbGwga2lsIHVzIGFsbA%3D%3D",
4189
  "ow",
4190
  "😭🤣https://m.youtube.com/shorts/2OviErKMwF4",
4191
  "🤙",
 
4212
  "bye i gotta go BYE",
4213
  "me go bye bye, BYE",
4214
  "why do you look like an inbred diseased wombat what the hell???",
4215
+ "oi mate you reckon you could monk off on top of the empire state building for 69 hours straight?",
4216
  "IM GONNA MONK YOU UP",
4217
  "MONKEY",
4218
  "hi"
 
4227
  messages.append(["assistant", val["content"]])
4228
  messages.append(["user", message])
4229
 
4230
+ max_retries = 5
4231
+ retry_count = 0
4232
+
4233
+ while retry_count < max_retries:
4234
+ try:
4235
+ response = ""
4236
+ for message in client.chat_completion(
4237
+ messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p
4238
+ ):
4239
+ token = message.choices[0].delta.content
4240
+ response += token
4241
+ yield response
4242
+ break
4243
+ except Exception as e:
4244
+ print(f"Attempt {retry_count + 1} failed: {e}")
4245
+ retry_count += 1
4246
+ time.sleep(1)
4247
+
4248
+ if retry_count == max_retries:
4249
+ response = random.choice(errored_responses)
4250
  yield response
4251
 
4252
  if any(phrase in response for phrase in ["I cannot", "I can't", "I won't", "I'm not going to engage in this conversation"]):