125 lines
2.7 KiB
Python
125 lines
2.7 KiB
Python
|
|
"""
|
||
|
|
AI 审核 API 视图
|
||
|
|
"""
|
||
|
|
from rest_framework import viewsets, permissions, status
|
||
|
|
from rest_framework.decorators import api_view, permission_classes
|
||
|
|
from rest_framework.response import Response
|
||
|
|
from rest_framework.permissions import IsAuthenticated, IsAdminUser
|
||
|
|
|
||
|
|
from .ai_audit import AIAuditService
|
||
|
|
|
||
|
|
|
||
|
|
@api_view(['POST'])
|
||
|
|
@permission_classes([IsAuthenticated])
|
||
|
|
def audit_article(request):
|
||
|
|
"""
|
||
|
|
审核文章
|
||
|
|
|
||
|
|
请求体:
|
||
|
|
{
|
||
|
|
"title": "文章标题",
|
||
|
|
"content": "文章内容"
|
||
|
|
}
|
||
|
|
|
||
|
|
返回:
|
||
|
|
{
|
||
|
|
"approved": true/false,
|
||
|
|
"reason": "审核结果说明",
|
||
|
|
"details": {...}
|
||
|
|
}
|
||
|
|
"""
|
||
|
|
title = request.data.get('title', '')
|
||
|
|
content = request.data.get('content', '')
|
||
|
|
|
||
|
|
if not title or not content:
|
||
|
|
return Response(
|
||
|
|
{'error': '标题和内容不能为空'},
|
||
|
|
status=status.HTTP_400_BAD_REQUEST
|
||
|
|
)
|
||
|
|
|
||
|
|
result = AIAuditService.audit_article(title, content)
|
||
|
|
|
||
|
|
return Response(result)
|
||
|
|
|
||
|
|
|
||
|
|
@api_view(['POST'])
|
||
|
|
@permission_classes([IsAuthenticated])
|
||
|
|
def audit_comment(request):
|
||
|
|
"""
|
||
|
|
审核评论
|
||
|
|
|
||
|
|
请求体:
|
||
|
|
{
|
||
|
|
"content": "评论内容"
|
||
|
|
}
|
||
|
|
|
||
|
|
返回:
|
||
|
|
{
|
||
|
|
"approved": true/false,
|
||
|
|
"reason": "审核结果说明",
|
||
|
|
"details": {...}
|
||
|
|
}
|
||
|
|
"""
|
||
|
|
content = request.data.get('content', '')
|
||
|
|
|
||
|
|
if not content:
|
||
|
|
return Response(
|
||
|
|
{'error': '评论内容不能为空'},
|
||
|
|
status=status.HTTP_400_BAD_REQUEST
|
||
|
|
)
|
||
|
|
|
||
|
|
result = AIAuditService.audit_comment(content)
|
||
|
|
|
||
|
|
return Response(result)
|
||
|
|
|
||
|
|
|
||
|
|
@api_view(['POST'])
|
||
|
|
@permission_classes([IsAuthenticated])
|
||
|
|
def audit_service(request):
|
||
|
|
"""
|
||
|
|
审核特色服务
|
||
|
|
|
||
|
|
请求体:
|
||
|
|
{
|
||
|
|
"name": "服务名称",
|
||
|
|
"description": "服务描述"
|
||
|
|
}
|
||
|
|
|
||
|
|
返回:
|
||
|
|
{
|
||
|
|
"approved": true/false,
|
||
|
|
"reason": "审核结果说明",
|
||
|
|
"details": {...}
|
||
|
|
}
|
||
|
|
"""
|
||
|
|
name = request.data.get('name', '')
|
||
|
|
description = request.data.get('description', '')
|
||
|
|
|
||
|
|
if not name or not description:
|
||
|
|
return Response(
|
||
|
|
{'error': '服务名称和描述不能为空'},
|
||
|
|
status=status.HTTP_400_BAD_REQUEST
|
||
|
|
)
|
||
|
|
|
||
|
|
result = AIAuditService.audit_service(name, description)
|
||
|
|
|
||
|
|
return Response(result)
|
||
|
|
|
||
|
|
|
||
|
|
@api_view(['GET'])
|
||
|
|
@permission_classes([IsAuthenticated])
|
||
|
|
def audit_status(request):
|
||
|
|
"""
|
||
|
|
获取 AI 审核服务状态
|
||
|
|
"""
|
||
|
|
return Response({
|
||
|
|
'status': 'active',
|
||
|
|
'service': 'AI Audit Service',
|
||
|
|
'version': '1.0.0',
|
||
|
|
'features': [
|
||
|
|
'敏感词检测',
|
||
|
|
'广告检测',
|
||
|
|
'内容质量评估',
|
||
|
|
]
|
||
|
|
})
|