mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
fix: admin dislike feedback lose content (#29327)
This commit is contained in:
parent
8275533418
commit
8f7173b69b
@ -61,6 +61,7 @@ class ChatMessagesQuery(BaseModel):
|
|||||||
class MessageFeedbackPayload(BaseModel):
|
class MessageFeedbackPayload(BaseModel):
|
||||||
message_id: str = Field(..., description="Message ID")
|
message_id: str = Field(..., description="Message ID")
|
||||||
rating: Literal["like", "dislike"] | None = Field(default=None, description="Feedback rating")
|
rating: Literal["like", "dislike"] | None = Field(default=None, description="Feedback rating")
|
||||||
|
content: str | None = Field(default=None, description="Feedback content")
|
||||||
|
|
||||||
@field_validator("message_id")
|
@field_validator("message_id")
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -324,6 +325,7 @@ class MessageFeedbackApi(Resource):
|
|||||||
db.session.delete(feedback)
|
db.session.delete(feedback)
|
||||||
elif args.rating and feedback:
|
elif args.rating and feedback:
|
||||||
feedback.rating = args.rating
|
feedback.rating = args.rating
|
||||||
|
feedback.content = args.content
|
||||||
elif not args.rating and not feedback:
|
elif not args.rating and not feedback:
|
||||||
raise ValueError("rating cannot be None when feedback not exists")
|
raise ValueError("rating cannot be None when feedback not exists")
|
||||||
else:
|
else:
|
||||||
@ -335,6 +337,7 @@ class MessageFeedbackApi(Resource):
|
|||||||
conversation_id=message.conversation_id,
|
conversation_id=message.conversation_id,
|
||||||
message_id=message.id,
|
message_id=message.id,
|
||||||
rating=rating_value,
|
rating=rating_value,
|
||||||
|
content=args.content,
|
||||||
from_source="admin",
|
from_source="admin",
|
||||||
from_account_id=current_user.id,
|
from_account_id=current_user.id,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -816,9 +816,12 @@ const CompletionConversationDetailComp: FC<{ appId?: string; conversationId?: st
|
|||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const handleFeedback = async (mid: string, { rating }: FeedbackType): Promise<boolean> => {
|
const handleFeedback = async (mid: string, { rating, content }: FeedbackType): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
await updateLogMessageFeedbacks({ url: `/apps/${appId}/feedbacks`, body: { message_id: mid, rating } })
|
await updateLogMessageFeedbacks({
|
||||||
|
url: `/apps/${appId}/feedbacks`,
|
||||||
|
body: { message_id: mid, rating, content: content ?? undefined },
|
||||||
|
})
|
||||||
conversationDetailMutate()
|
conversationDetailMutate()
|
||||||
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
||||||
return true
|
return true
|
||||||
@ -861,9 +864,12 @@ const ChatConversationDetailComp: FC<{ appId?: string; conversationId?: string }
|
|||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const handleFeedback = async (mid: string, { rating }: FeedbackType): Promise<boolean> => {
|
const handleFeedback = async (mid: string, { rating, content }: FeedbackType): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
await updateLogMessageFeedbacks({ url: `/apps/${appId}/feedbacks`, body: { message_id: mid, rating } })
|
await updateLogMessageFeedbacks({
|
||||||
|
url: `/apps/${appId}/feedbacks`,
|
||||||
|
body: { message_id: mid, rating, content: content ?? undefined },
|
||||||
|
})
|
||||||
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user