Spaces:
Building
Building
Upload app.py
Browse files
app.py
CHANGED
@@ -56,6 +56,10 @@ safety_settings = [
|
|
56 |
"threshold": "BLOCK_NONE"
|
57 |
},
|
58 |
]
|
|
|
|
|
|
|
|
|
59 |
|
60 |
class APIKeyManager:
|
61 |
def __init__(self):
|
@@ -120,7 +124,7 @@ GEMINI_MODELS = [
|
|
120 |
|
121 |
@app.route('/')
|
122 |
def index():
|
123 |
-
main_content = "Moonfanz Reminiproxy v2.1.
|
124 |
html_template = """
|
125 |
<!DOCTYPE html>
|
126 |
<html>
|
@@ -232,6 +236,20 @@ def handle_api_error(error, attempt):
|
|
232 |
switch_api_key()
|
233 |
return 0, None
|
234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
else:
|
236 |
logger.error(f"其他错误↙\n {error}")
|
237 |
return 2, None
|
|
|
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):
|
|
|
124 |
|
125 |
@app.route('/')
|
126 |
def index():
|
127 |
+
main_content = "Moonfanz Reminiproxy v2.1.4 2025-01-09"
|
128 |
html_template = """
|
129 |
<!DOCTYPE html>
|
130 |
<html>
|
|
|
236 |
switch_api_key()
|
237 |
return 0, None
|
238 |
|
239 |
+
elif isinstance(error, PromptBlockedException):
|
240 |
+
if error.block_reason == "SAFETY":
|
241 |
+
logger.error(f"{current_api_key[:11]} → 用户消息由于安全原因被阻止: {error.safety_ratings}")
|
242 |
+
elif error.block_reason == "OTHER":
|
243 |
+
logger.error(f"{current_api_key[:11]} → 用户消息由于未知原因被阻止")
|
244 |
+
elif error.block_reason == "BLOCKLIST":
|
245 |
+
logger.error(f"{current_api_key[:11]} → 用户消息由于包含黑名单词汇被阻止")
|
246 |
+
elif error.block_reason == "PROHIBITED_CONTENT":
|
247 |
+
logger.error(f"{current_api_key[:11]} → 用户消息由于包含禁止内容被阻止")
|
248 |
+
else:
|
249 |
+
logger.error(f"{current_api_key[:11]} → 用户消息由于未知原因被阻止: {error.block_reason}")
|
250 |
+
|
251 |
+
switch_api_key()
|
252 |
+
return 0, None
|
253 |
else:
|
254 |
logger.error(f"其他错误↙\n {error}")
|
255 |
return 2, None
|