Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4181,6 +4181,14 @@ alternative_responses = [
|
|
4181 |
"how about no"
|
4182 |
]
|
4183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4184 |
def respond(message, history, max_tokens, temperature, top_p):
|
4185 |
messages = [["system", system_prompt]]
|
4186 |
for val in history:
|
@@ -4191,18 +4199,24 @@ def respond(message, history, max_tokens, temperature, top_p):
|
|
4191 |
messages.append(["user", message])
|
4192 |
|
4193 |
response = ""
|
4194 |
-
|
4195 |
-
|
4196 |
-
|
4197 |
-
|
4198 |
-
|
4199 |
-
|
|
|
|
|
|
|
|
|
|
|
4200 |
|
4201 |
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"]):
|
4202 |
response = random.choice(alternative_responses)
|
4203 |
|
4204 |
yield response
|
4205 |
|
|
|
4206 |
css = """
|
4207 |
/* Import Caveat font from Google Fonts */
|
4208 |
@import url('https://fonts.googleapis.com/css2?family=Caveat&display=swap');
|
|
|
4181 |
"how about no"
|
4182 |
]
|
4183 |
|
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 |
+
]
|
4191 |
+
|
4192 |
def respond(message, history, max_tokens, temperature, top_p):
|
4193 |
messages = [["system", system_prompt]]
|
4194 |
for val in history:
|
|
|
4199 |
messages.append(["user", message])
|
4200 |
|
4201 |
response = ""
|
4202 |
+
try:
|
4203 |
+
for message in client.chat_completion(
|
4204 |
+
messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p
|
4205 |
+
):
|
4206 |
+
token = message.choices[0].delta.content
|
4207 |
+
response += token
|
4208 |
+
yield response
|
4209 |
+
except Exception as e:
|
4210 |
+
print(f"Error occurred: {e}")
|
4211 |
+
response = random.choice(errored_responses)
|
4212 |
+
yield response
|
4213 |
|
4214 |
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"]):
|
4215 |
response = random.choice(alternative_responses)
|
4216 |
|
4217 |
yield response
|
4218 |
|
4219 |
+
|
4220 |
css = """
|
4221 |
/* Import Caveat font from Google Fonts */
|
4222 |
@import url('https://fonts.googleapis.com/css2?family=Caveat&display=swap');
|