forked from infiniflow/ragflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Submit Feedback infiniflow#2088 (infiniflow#2134)
### What problem does this PR solve? feat: Submit Feedback infiniflow#2088 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
- Loading branch information
Showing
10 changed files
with
185 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useFeedback } from '@/hooks/chat-hooks'; | ||
import { useSetModalState } from '@/hooks/common-hooks'; | ||
import { IFeedbackRequestBody } from '@/interfaces/request/chat'; | ||
import { getMessagePureId } from '@/utils/chat'; | ||
import { useCallback } from 'react'; | ||
|
||
export const useSendFeedback = (messageId: string) => { | ||
const { visible, hideModal, showModal } = useSetModalState(); | ||
const { feedback, loading } = useFeedback(); | ||
|
||
const onFeedbackOk = useCallback( | ||
async (params: IFeedbackRequestBody) => { | ||
const ret = await feedback({ | ||
...params, | ||
messageId: getMessagePureId(messageId), | ||
}); | ||
|
||
if (ret === 0) { | ||
hideModal(); | ||
} | ||
}, | ||
[feedback, hideModal, messageId], | ||
); | ||
|
||
return { | ||
loading, | ||
onFeedbackOk, | ||
visible, | ||
hideModal, | ||
showModal, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface IFeedbackRequestBody { | ||
messageId?: string; | ||
thumbup?: boolean; | ||
feedback?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
import { EmptyConversationId } from '@/constants/chat'; | ||
import { EmptyConversationId, MessageType } from '@/constants/chat'; | ||
import { Message } from '@/interfaces/database/chat'; | ||
import { IMessage } from '@/pages/chat/interface'; | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
export const isConversationIdExist = (conversationId: string) => { | ||
return conversationId !== EmptyConversationId && conversationId !== ''; | ||
}; | ||
|
||
export const buildMessageUuid = (message: Message | IMessage) => { | ||
if ('id' in message && message.id) { | ||
return message.role === MessageType.User | ||
? `${MessageType.User}_${message.id}` | ||
: `${MessageType.Assistant}_${message.id}`; | ||
} | ||
return uuid(); | ||
}; | ||
|
||
export const getMessagePureId = (id: string) => { | ||
const strings = id.split('_'); | ||
if (strings.length > 0) { | ||
return strings.at(-1); | ||
} | ||
return id; | ||
}; |