From d534bd732dbda2cc3b569b8d80264645eafe8e58 Mon Sep 17 00:00:00 2001 From: wanjia Date: Mon, 9 Jun 2025 17:50:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AF=B9=E8=AF=9D=E8=AF=84?= =?UTF-8?q?=E4=BC=B01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/rlhf/views.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/apps/rlhf/views.py b/apps/rlhf/views.py index f4ec87a..9872094 100644 --- a/apps/rlhf/views.py +++ b/apps/rlhf/views.py @@ -606,18 +606,34 @@ class ConversationEvaluationViewSet(StandardResponseMixin, viewsets.ModelViewSet status_code=status.HTTP_404_NOT_FOUND ) - # 创建或更新评估 - evaluation_id = str(uuid.uuid4()) - evaluation, created = ConversationEvaluation.objects.update_or_create( + # 检查是否已存在评估 + existing_evaluation = ConversationEvaluation.objects.filter( + conversation_id=conversation_id, + user=request.user + ).first() + + if existing_evaluation: + # 如果已存在评估,返回提示信息 + return self.get_standard_response( + code=400, + message='您已经对这个对话进行过评估,请使用PUT或PATCH方法更新评估', + data={ + 'evaluation_id': existing_evaluation.id, + 'created_at': existing_evaluation.created_at + }, + status_code=status.HTTP_400_BAD_REQUEST + ) + + # 创建新评估 + evaluation = ConversationEvaluation.objects.create( + id=str(uuid.uuid4()), conversation_id=conversation_id, user=request.user, - defaults={ - 'id': evaluation_id, - 'overall_feeling': overall_feeling, - 'has_logical_issues': has_logical_issues, - 'needs_satisfied': needs_satisfied, - 'updated_at': timezone.now() - } + overall_feeling=overall_feeling, + has_logical_issues=has_logical_issues, + needs_satisfied=needs_satisfied, + created_at=timezone.now(), + updated_at=timezone.now() ) # 记录活动日志