mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-02-04 01:25:07 +08:00
Fix: Fixed the issue that the content of the Dropdown section cannot be seen when selecting the next operator #3221 (#8918)
…be seen when selecting the next operator #3221 ### What problem does this PR solve? Fix: Fixed the issue that the content of the Dropdown section cannot be seen when selecting the next operator #3221 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
53
web/src/pages/next-chats/utils.ts
Normal file
53
web/src/pages/next-chats/utils.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { MessageType } from '@/constants/chat';
|
||||
import { IConversation, IReference } from '@/interfaces/database/chat';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { EmptyConversationId } from './constants';
|
||||
import { IMessage } from './interface';
|
||||
|
||||
export const isConversationIdExist = (conversationId: string) => {
|
||||
return conversationId !== EmptyConversationId && conversationId !== '';
|
||||
};
|
||||
|
||||
export const getDocumentIdsFromConversionReference = (data: IConversation) => {
|
||||
const documentIds = data.reference.reduce(
|
||||
(pre: Array<string>, cur: IReference) => {
|
||||
cur.doc_aggs
|
||||
?.map((x) => x.doc_id)
|
||||
.forEach((x) => {
|
||||
if (pre.every((y) => y !== x)) {
|
||||
pre.push(x);
|
||||
}
|
||||
});
|
||||
return pre;
|
||||
},
|
||||
[],
|
||||
);
|
||||
return documentIds.join(',');
|
||||
};
|
||||
|
||||
export const buildMessageItemReference = (
|
||||
conversation: { message: IMessage[]; reference: IReference[] },
|
||||
message: IMessage,
|
||||
) => {
|
||||
const assistantMessages = conversation.message
|
||||
?.filter((x) => x.role === MessageType.Assistant)
|
||||
.slice(1);
|
||||
const referenceIndex = assistantMessages.findIndex(
|
||||
(x) => x.id === message.id,
|
||||
);
|
||||
const reference = !isEmpty(message?.reference)
|
||||
? message?.reference
|
||||
: (conversation?.reference ?? [])[referenceIndex];
|
||||
|
||||
return reference ?? { doc_aggs: [], chunks: [], total: 0 };
|
||||
};
|
||||
|
||||
const oldReg = /(#{2}\d+\${2})/g;
|
||||
export const currentReg = /\[ID:(\d+)\]/g;
|
||||
|
||||
// To be compatible with the old index matching mode
|
||||
export const replaceTextByOldReg = (text: string) => {
|
||||
return text?.replace(oldReg, (substring: string) => {
|
||||
return `[ID:${substring.slice(2, -2)}]`;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user