mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix: In order to distinguish the keys of a pair of messages, add a prefix to the id when rendering the message. #4409 (#4451)
### What problem does this PR solve? Fix: In order to distinguish the keys of a pair of messages, add a prefix to the id when rendering the message. #4409 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { EmptyConversationId, MessageType } from '@/constants/chat';
|
||||
import { EmptyConversationId } from '@/constants/chat';
|
||||
import { Message } from '@/interfaces/database/chat';
|
||||
import { IMessage } from '@/pages/chat/interface';
|
||||
import { omit } from 'lodash';
|
||||
@ -10,21 +10,11 @@ export const isConversationIdExist = (conversationId: string) => {
|
||||
|
||||
export const buildMessageUuid = (message: Partial<Message | IMessage>) => {
|
||||
if ('id' in message && message.id) {
|
||||
return message.role === MessageType.User
|
||||
? `${MessageType.User}_${message.id}`
|
||||
: `${MessageType.Assistant}_${message.id}`;
|
||||
return message.id;
|
||||
}
|
||||
return uuid();
|
||||
};
|
||||
|
||||
export const getMessagePureId = (id?: string) => {
|
||||
const strings = id?.split('_') ?? [];
|
||||
if (strings.length > 0) {
|
||||
return strings.at(-1);
|
||||
}
|
||||
return id;
|
||||
};
|
||||
|
||||
export const buildMessageListWithUuid = (messages?: Message[]) => {
|
||||
return (
|
||||
messages?.map((x: Message | IMessage) => ({
|
||||
@ -37,3 +27,10 @@ export const buildMessageListWithUuid = (messages?: Message[]) => {
|
||||
export const getConversationId = () => {
|
||||
return uuid().replace(/-/g, '');
|
||||
};
|
||||
|
||||
// When rendering each message, add a prefix to the id to ensure uniqueness.
|
||||
export const buildMessageUuidWithRole = (
|
||||
message: Partial<Message | IMessage>,
|
||||
) => {
|
||||
return `${message.role}_${message.id}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user