Spaces:
Running
Running
Updated space
Browse files
app.py
CHANGED
@@ -125,9 +125,13 @@ def moderate(messages):
|
|
125 |
return False
|
126 |
|
127 |
try:
|
128 |
-
|
|
|
129 |
except KeyError:
|
130 |
-
|
|
|
|
|
|
|
131 |
|
132 |
async def streamChat(params):
|
133 |
async with aiohttp.ClientSession() as session:
|
@@ -268,7 +272,7 @@ By continuing to use our application, you explicitly consent to the collection,
|
|
268 |
To agree to user consent, please do the followings:
|
269 |
1. Scroll down to find the section labeled 'Additional Inputs' below this page.
|
270 |
2. Find and click the check box that says 'User Consent [I agree to the terms and conditions. (can't make a button for it)]'.
|
271 |
-
3. After agreeing, click either the
|
272 |
return
|
273 |
|
274 |
messages = [{"role": "system", "content": system_message}]
|
@@ -287,8 +291,18 @@ To agree to user consent, please do the followings:
|
|
287 |
if user_message:
|
288 |
messages.append(user_message)
|
289 |
|
290 |
-
|
291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
return
|
293 |
|
294 |
response = ""
|
|
|
125 |
return False
|
126 |
|
127 |
try:
|
128 |
+
if any(result["flagged"] for result in moderation_result["results"]):
|
129 |
+
return moderation_result
|
130 |
except KeyError:
|
131 |
+
if moderation_result["flagged"]:
|
132 |
+
return moderation_result
|
133 |
+
|
134 |
+
return False
|
135 |
|
136 |
async def streamChat(params):
|
137 |
async with aiohttp.ClientSession() as session:
|
|
|
272 |
To agree to user consent, please do the followings:
|
273 |
1. Scroll down to find the section labeled 'Additional Inputs' below this page.
|
274 |
2. Find and click the check box that says 'User Consent [I agree to the terms and conditions. (can't make a button for it)]'.
|
275 |
+
3. After agreeing, click either the `ποΈ Clear` button, the `β©οΈ Undo` button, or the `π Retry` button located above the message input area."""
|
276 |
return
|
277 |
|
278 |
messages = [{"role": "system", "content": system_message}]
|
|
|
291 |
if user_message:
|
292 |
messages.append(user_message)
|
293 |
|
294 |
+
mode = moderate(messages)
|
295 |
+
if mode:
|
296 |
+
reasons = []
|
297 |
+
categories = mode[0].get('categories', {}) if isinstance(mode, list) else mode.get('categories', {})
|
298 |
+
for category, flagged in categories.items():
|
299 |
+
if flagged:
|
300 |
+
reasons.append(category)
|
301 |
+
|
302 |
+
if reasons:
|
303 |
+
yield "[MODERATION] I'm sorry, but I can't assist with that.\n\nReasons:\n```\n" + "\n".join([f"{i+1}. {reason}" for i, reason in enumerate(reasons)]) + "\n```"
|
304 |
+
else:
|
305 |
+
yield "[MODERATION] I'm sorry, but I can't assist with that."
|
306 |
return
|
307 |
|
308 |
response = ""
|