Spaces:
Paused
Paused
Upload app.py
Browse files
app.py
CHANGED
|
@@ -56,10 +56,6 @@ safety_settings = [
|
|
| 56 |
"threshold": "BLOCK_NONE"
|
| 57 |
},
|
| 58 |
]
|
| 59 |
-
class PromptBlockedException(Exception):
|
| 60 |
-
def __init__(self, block_reason, safety_ratings=None):
|
| 61 |
-
self.block_reason = block_reason
|
| 62 |
-
self.safety_ratings = safety_ratings if safety_ratings else []
|
| 63 |
|
| 64 |
class APIKeyManager:
|
| 65 |
def __init__(self):
|
|
@@ -236,23 +232,27 @@ def handle_api_error(error, attempt):
|
|
| 236 |
switch_api_key()
|
| 237 |
return 0, None
|
| 238 |
|
| 239 |
-
elif
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
logger.
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
else:
|
| 249 |
-
logger.
|
|
|
|
| 250 |
|
| 251 |
-
switch_api_key()
|
| 252 |
-
return 0, None
|
| 253 |
else:
|
| 254 |
logger.error(f"其他错误↙\n {error}")
|
| 255 |
-
switch_api_key()
|
| 256 |
return 2, None
|
| 257 |
|
| 258 |
@app.route('/hf/v1/chat/completions', methods=['POST'])
|
|
|
|
| 56 |
"threshold": "BLOCK_NONE"
|
| 57 |
},
|
| 58 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
class APIKeyManager:
|
| 61 |
def __init__(self):
|
|
|
|
| 232 |
switch_api_key()
|
| 233 |
return 0, None
|
| 234 |
|
| 235 |
+
elif hasattr(error, 'prompt_feedback') and error.prompt_feedback.block_reason:
|
| 236 |
+
block_reason = error.prompt_feedback.block_reason
|
| 237 |
+
safety_ratings = error.prompt_feedback.safety_ratings
|
| 238 |
+
if block_reason == generation_types.BlockReason.SAFETY:
|
| 239 |
+
logger.warning(f"用户输入被阻挡,原因:SAFETY. 详细信息:{safety_ratings}")
|
| 240 |
+
return 0, None
|
| 241 |
+
elif block_reason == generation_types.BlockReason.OTHER:
|
| 242 |
+
logger.warning(f"用户输入被阻挡,原因:OTHER")
|
| 243 |
+
return 0, None
|
| 244 |
+
elif block_reason == generation_types.BlockReason.BLOCKLIST:
|
| 245 |
+
logger.warning(f"用户输入被阻挡,原因:BLOCKLIST")
|
| 246 |
+
return 0, None
|
| 247 |
+
elif block_reason == generation_types.BlockReason.PROHIBITED_CONTENT:
|
| 248 |
+
logger.warning(f"用户输入被阻挡,原因:PROHIBITED_CONTENT")
|
| 249 |
+
return 0, None
|
| 250 |
else:
|
| 251 |
+
logger.warning(f"用户输入被阻挡,未知阻挡原因:{block_reason}")
|
| 252 |
+
return 0, None
|
| 253 |
|
|
|
|
|
|
|
| 254 |
else:
|
| 255 |
logger.error(f"其他错误↙\n {error}")
|
|
|
|
| 256 |
return 2, None
|
| 257 |
|
| 258 |
@app.route('/hf/v1/chat/completions', methods=['POST'])
|