Moonfanz commited on
Commit
c1df335
·
verified ·
1 Parent(s): 76c89e5

Upload 4 files

Browse files
Files changed (1) hide show
  1. app.py +18 -8
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
- logger.error(f"处理AI返回消息时出错↙\n{e}")
349
- return jsonify({
350
- 'error': {
351
- 'message': '处理AI返回消息时出错',
352
- 'type': 'response_processing_error'
353
- }
354
- }), 500
 
 
 
 
 
 
 
 
 
 
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',