Skip to content

Commit

Permalink
Feat: Exclude reference from the data returned by the conversation/ge…
Browse files Browse the repository at this point in the history
…t interface #3909 (#3962)

### What problem does this PR solve?

Feat: Exclude reference from the data returned by the conversation/get
interface #3909

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Dec 10, 2024
1 parent fc4e644 commit 601d741
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
10 changes: 2 additions & 8 deletions web/src/components/message-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const MessageItem = ({
item,
reference,
loading = false,
avatar = '',
avatar,
sendLoading = false,
clickDocumentButton,
index,
Expand Down Expand Up @@ -102,13 +102,7 @@ const MessageItem = ({
})}
>
{item.role === MessageType.User ? (
<Avatar
size={40}
src={
avatar ??
'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
}
/>
<Avatar size={40} src={avatar ?? '/logo.svg'} />
) : (
<AssistantIcon></AssistantIcon>
)}
Expand Down
7 changes: 4 additions & 3 deletions web/src/pages/chat/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { MessageType } from '@/constants/chat';
import { IConversation, IReference } from '@/interfaces/database/chat';
import { isEmpty } from 'lodash';
import { EmptyConversationId } from './constants';
import { IMessage } from './interface';

Expand Down Expand Up @@ -34,9 +35,9 @@ export const buildMessageItemReference = (
const referenceIndex = assistantMessages.findIndex(
(x) => x.id === message.id,
);
const reference = message?.reference
const reference = !isEmpty(message?.reference)
? message?.reference
: (conversation?.reference ?? {})[referenceIndex];
: (conversation?.reference ?? [])[referenceIndex];

return reference;
return reference ?? { doc_aggs: [], chunks: [], total: 0 };
};
3 changes: 2 additions & 1 deletion web/src/utils/chat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EmptyConversationId, MessageType } from '@/constants/chat';
import { Message } from '@/interfaces/database/chat';
import { IMessage } from '@/pages/chat/interface';
import { omit } from 'lodash';
import { v4 as uuid } from 'uuid';

export const isConversationIdExist = (conversationId: string) => {
Expand All @@ -27,7 +28,7 @@ export const getMessagePureId = (id?: string) => {
export const buildMessageListWithUuid = (messages?: Message[]) => {
return (
messages?.map((x: Message | IMessage) => ({
...x,
...omit(x, 'reference'),
id: buildMessageUuid(x),
})) ?? []
);
Expand Down

0 comments on commit 601d741

Please sign in to comment.