Spaces:
Building
Building
Upload 4 files
Browse files
app.py
CHANGED
@@ -485,8 +485,9 @@ def chat_completions():
|
|
485 |
else:
|
486 |
try:
|
487 |
text_content = response.text
|
|
|
488 |
except (AttributeError, IndexError, TypeError, ValueError) as e:
|
489 |
-
|
490 |
logger.error(f"用户输入被AI安全过滤器阻止")
|
491 |
return jsonify({
|
492 |
'error': {
|
@@ -495,28 +496,13 @@ def chat_completions():
|
|
495 |
'details': str(e)
|
496 |
}
|
497 |
}), 400
|
498 |
-
|
499 |
return jsonify({
|
500 |
'error': {
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
}), 500
|
505 |
-
try:
|
506 |
-
response_json = json.loads(response.text)
|
507 |
-
if 'candidates' in response_json and response_json['candidates']:
|
508 |
-
candidate = response_json['candidates'][0]
|
509 |
-
if 'content' in candidate:
|
510 |
-
content = candidate['content']
|
511 |
-
if 'parts' in content and content['parts']:
|
512 |
-
parts = content['parts']
|
513 |
-
if is_thinking and not show_thoughts:
|
514 |
-
parts = [part for part in parts if not part.get('thought')]
|
515 |
-
|
516 |
-
if parts:
|
517 |
-
text_content = "".join(part.get('text', '') for part in parts)
|
518 |
-
except json.JSONDecodeError:
|
519 |
-
pass
|
520 |
|
521 |
response_data = {
|
522 |
'id': 'chatcmpl-xxxxxxxxxxxx',
|
|
|
485 |
else:
|
486 |
try:
|
487 |
text_content = response.text
|
488 |
+
logger.info(json.dumps(response.json(), indent=4))
|
489 |
except (AttributeError, IndexError, TypeError, ValueError) as e:
|
490 |
+
if "response.candidates" in str(e) or "response.text" in str(e):
|
491 |
logger.error(f"用户输入被AI安全过滤器阻止")
|
492 |
return jsonify({
|
493 |
'error': {
|
|
|
496 |
'details': str(e)
|
497 |
}
|
498 |
}), 400
|
499 |
+
else:
|
500 |
return jsonify({
|
501 |
'error': {
|
502 |
+
'message': 'AI响应处理失败',
|
503 |
+
'type': 'response_processing_error'
|
504 |
+
}
|
505 |
}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
507 |
response_data = {
|
508 |
'id': 'chatcmpl-xxxxxxxxxxxx',
|