feat: 添加 AI 审核模块
- 新增 apps/core/ai_audit.py AI 审核服务 - 新增 apps/core/views.py API 视图 - 新增 apps/core/urls.py URL 路由 - 更新 config/urls.py 注册 AI 审核 API - 支持文章/评论/服务的自动审核 - 包含敏感词检测、广告检测、内容质量评估
This commit is contained in:
124
backend/apps/core/views.py
Normal file
124
backend/apps/core/views.py
Normal file
@@ -0,0 +1,124 @@
|
||||
"""
|
||||
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': [
|
||||
'敏感词检测',
|
||||
'广告检测',
|
||||
'内容质量评估',
|
||||
]
|
||||
})
|
||||
Reference in New Issue
Block a user