Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: admin feedback uses the same method create_feedback (#22580)

jiangbo721ffee6f3288eb
diff --git a/api/controllers/console/app/message.py b/api/controllers/console/app/message.py
index b7a4c31a156..ea659f9f5b7 100644
--- a/api/controllers/console/app/message.py
+++ b/api/controllers/console/app/message.py
@@ -5,6 +5,7 @@ from flask_restful import Resource, fields, marshal_with, reqparse
from flask_restful.inputs import int_range
from werkzeug.exceptions import Forbidden, InternalServerError, NotFound
+import services
from controllers.console import api
from controllers.console.app.error import (
CompletionRequestError,
@@ -27,7 +28,7 @@ from fields.conversation_fields import annotation_fields, message_detail_fields
from libs.helper import uuid_value
from libs.infinite_scroll_pagination import InfiniteScrollPagination
from libs.login import login_required
-from models.model import AppMode, Conversation, Message, MessageAnnotation, MessageFeedback
+from models.model import AppMode, Conversation, Message, MessageAnnotation
from services.annotation_service import AppAnnotationService
from services.errors.conversation import ConversationNotExistsError
from services.errors.message import MessageNotExistsError, SuggestedQuestionsAfterAnswerDisabledError
@@ -124,33 +125,16 @@ class MessageFeedbackApi(Resource):
parser.add_argument("rating", type=str, choices=["like", "dislike", None], location="json")
args = parser.parse_args()
- message_id = str(args["message_id"])
-
- message = db.session.query(Message).filter(Message.id == message_id, Message.app_id == app_model.id).first()
-
- if not message:
- raise NotFound("Message Not Exists.")
-
- feedback = message.admin_feedback
-
- if not args["rating"] and feedback:
- db.session.delete(feedback)
- elif args["rating"] and feedback:
- feedback.rating = args["rating"]
- elif not args["rating"] and not feedback:
- raise ValueError("rating cannot be None when feedback not exists")
- else:
- feedback = MessageFeedback(
- app_id=app_model.id,
- conversation_id=message.conversation_id,
- message_id=message.id,
- rating=args["rating"],
- from_source="admin",
- from_account_id=current_user.id,
+ try:
+ MessageService.create_feedback(
+ app_model=app_model,
+ message_id=str(args["message_id"]),
+ user=current_user,
+ rating=args.get("rating"),
+ content=None,
)
- db.session.add(feedback)
-
- db.session.commit()
+ except services.errors.message.MessageNotExistsError:
+ raise NotFound("Message Not Exists.")
return {"result": "success"}