Spaces:
Building
Building
Upload app.py
Browse files
app.py
CHANGED
@@ -232,18 +232,21 @@ def handle_api_error(error, attempt):
|
|
232 |
switch_api_key()
|
233 |
return 0, None
|
234 |
|
235 |
-
elif isinstance(error, BlockedPromptException):
|
236 |
-
reason = error.block_reason
|
237 |
-
if reason == generation_types.BlockReason.SAFETY:
|
238 |
-
logger.warning(f"提示因安全原因被阻止:{error.safety_ratings}")
|
239 |
return 2, None
|
240 |
-
elif reason == generation_types.BlockReason.BLOCKLIST:
|
241 |
logger.warning(f"提示因包含阻止列表中的术语而被阻止")
|
242 |
return 2, None
|
243 |
-
elif reason == generation_types.BlockReason.PROHIBITED_CONTENT:
|
244 |
logger.warning(f"提示因包含禁止内容而被阻止")
|
245 |
return 2, None
|
246 |
-
elif reason == generation_types.BlockReason.OTHER:
|
|
|
|
|
|
|
247 |
logger.warning(f"提示因未知原因被阻止")
|
248 |
return 2, None
|
249 |
else:
|
|
|
232 |
switch_api_key()
|
233 |
return 0, None
|
234 |
|
235 |
+
elif isinstance(error, generation_types.BlockedPromptException):
|
236 |
+
reason = error.prompt_feedback.block_reason
|
237 |
+
if reason == generation_types.PromptFeedback.BlockReason.SAFETY:
|
238 |
+
logger.warning(f"提示因安全原因被阻止:{error.prompt_feedback.safety_ratings}")
|
239 |
return 2, None
|
240 |
+
elif reason == generation_types.PromptFeedback.BlockReason.BLOCKLIST:
|
241 |
logger.warning(f"提示因包含阻止列表中的术语而被阻止")
|
242 |
return 2, None
|
243 |
+
elif reason == generation_types.PromptFeedback.BlockReason.PROHIBITED_CONTENT:
|
244 |
logger.warning(f"提示因包含禁止内容而被阻止")
|
245 |
return 2, None
|
246 |
+
elif reason == generation_types.PromptFeedback.BlockReason.OTHER:
|
247 |
+
logger.warning(f"提示因未知原因被阻止")
|
248 |
+
return 2, None
|
249 |
+
elif reason == generation_types.PromptFeedback.BlockReason.BLOCK_REASON_UNSPECIFIED:
|
250 |
logger.warning(f"提示因未知原因被阻止")
|
251 |
return 2, None
|
252 |
else:
|