Spaces:
Building
Building
Upload 4 files
Browse files
app.py
CHANGED
@@ -344,14 +344,24 @@ def chat_completions():
|
|
344 |
else:
|
345 |
try:
|
346 |
text_content = response.text
|
347 |
-
except (AttributeError, IndexError, TypeError) as e:
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
|
356 |
response_data = {
|
357 |
'id': 'chatcmpl-xxxxxxxxxxxx',
|
|
|
344 |
else:
|
345 |
try:
|
346 |
text_content = response.text
|
347 |
+
except (AttributeError, IndexError, TypeError, ValueError) as e:
|
348 |
+
if "response.candidates is empty" in str(e):
|
349 |
+
logger.error(f"你的输入被AI安全过滤器阻止")
|
350 |
+
return jsonify({
|
351 |
+
'error': {
|
352 |
+
'message': '你的输入被AI安全过滤器阻止',
|
353 |
+
'type': 'prompt_blocked_error',
|
354 |
+
'details': str(e)
|
355 |
+
}
|
356 |
+
}), 400
|
357 |
+
else:
|
358 |
+
logger.error(f"AI响应处理失败")
|
359 |
+
return jsonify({
|
360 |
+
'error': {
|
361 |
+
'message': 'AI响应处理失败',
|
362 |
+
'type': 'response_processing_error'
|
363 |
+
}
|
364 |
+
}), 500
|
365 |
|
366 |
response_data = {
|
367 |
'id': 'chatcmpl-xxxxxxxxxxxx',
|