Spaces:
Running
Running
Upload 4 files
Browse files- app.py +31 -18
- requirements.txt +1 -1
app.py
CHANGED
@@ -233,25 +233,38 @@ def handle_api_error(error, attempt):
|
|
233 |
return 0, None
|
234 |
|
235 |
elif isinstance(error, generation_types.BlockedPromptException):
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
return 2, None
|
|
|
255 |
else:
|
256 |
logger.error(f"其他错误↙\n {error}")
|
257 |
return 2, None
|
|
|
233 |
return 0, None
|
234 |
|
235 |
elif isinstance(error, generation_types.BlockedPromptException):
|
236 |
+
logger.warning(f"BlockedPromptException caught. Attributes:")
|
237 |
+
for attr_name in dir(error):
|
238 |
+
try:
|
239 |
+
attr_value = getattr(error, attr_name)
|
240 |
+
logger.warning(f" {attr_name}: {attr_value}")
|
241 |
+
except Exception as e:
|
242 |
+
logger.warning(f" {attr_name}: Could not retrieve value - {e}")
|
243 |
+
|
244 |
+
try:
|
245 |
+
reason = error.prompt_feedback.block_reason
|
246 |
+
if reason == generation_types.PromptFeedback.BlockReason.SAFETY:
|
247 |
+
logger.warning(f"提示因安全原因被阻止:{error.prompt_feedback.safety_ratings}")
|
248 |
+
return 2, None
|
249 |
+
elif reason == generation_types.PromptFeedback.BlockReason.BLOCKLIST:
|
250 |
+
logger.warning(f"提示因包含阻止列表中的术语而被阻止")
|
251 |
+
return 2, None
|
252 |
+
elif reason == generation_types.PromptFeedback.BlockReason.PROHIBITED_CONTENT:
|
253 |
+
logger.warning(f"提示因包含禁止内容而被阻止")
|
254 |
+
return 2, None
|
255 |
+
elif reason == generation_types.PromptFeedback.BlockReason.OTHER:
|
256 |
+
logger.warning(f"提示因未知原因被阻止")
|
257 |
+
return 2, None
|
258 |
+
elif reason == generation_types.PromptFeedback.BlockReason.BLOCK_REASON_UNSPECIFIED:
|
259 |
+
logger.warning(f"提示因未知原因被阻止")
|
260 |
+
return 2, None
|
261 |
+
else:
|
262 |
+
logger.warning(f"提示被阻止,原因未知: {reason}")
|
263 |
+
return 2, None
|
264 |
+
except AttributeError:
|
265 |
+
logger.error("AttributeError: 'BlockedPromptException' object has no attribute 'prompt_feedback'")
|
266 |
return 2, None
|
267 |
+
|
268 |
else:
|
269 |
logger.error(f"其他错误↙\n {error}")
|
270 |
return 2, None
|
requirements.txt
CHANGED
@@ -4,5 +4,5 @@ requests==2.32.3
|
|
4 |
Werkzeug==3.1.3
|
5 |
google==3.0.0
|
6 |
google-generativeai==0.8.3
|
7 |
-
pillow==
|
8 |
APScheduler==3.11.0
|
|
|
4 |
Werkzeug==3.1.3
|
5 |
google==3.0.0
|
6 |
google-generativeai==0.8.3
|
7 |
+
pillow==10.3.0
|
8 |
APScheduler==3.11.0
|