Skip to content

Commit

Permalink
fix(chat): fix displaying like/dislike buttons (Issue #2894) (#2895)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaBondar authored Dec 30, 2024
1 parent 45dba39 commit bb429cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions apps/chat/src/components/Chat/ChatMessage/MessageButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { useTranslation } from 'next-i18next';

import classNames from 'classnames';

import { getMessageCustomContent } from '@/src/utils/server/chat';

import { Translation } from '@/src/types/translation';

import { useAppSelector } from '@/src/store/hooks';
Expand Down Expand Up @@ -173,8 +175,7 @@ export const MessageAssistantButtons = ({
))}
<div className="flex flex-row gap-2">
{isLikesEnabled &&
(!message.errorMessage ||
(message.content.trim() && message.errorMessage)) && (
(message.content.trim() || !!getMessageCustomContent(message)) && (
<>
{message.like !== LikeState.Disliked && (
<Tooltip
Expand Down
4 changes: 2 additions & 2 deletions apps/chat/src/pages/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { validateServerSession } from '@/src/utils/auth/session';
import { OpenAIStream } from '@/src/utils/server';
import {
chatErrorHandler,
getMessageCustomContent,
getUserMessageCustomContent,
limitMessagesByTokens,
} from '@/src/utils/server/chat';
import { getSortedEntities } from '@/src/utils/server/get-sorted-entities';
Expand Down Expand Up @@ -99,7 +99,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
});

messagesToSend = messagesToSend.map((message) => ({
...getMessageCustomContent(message),
...getUserMessageCustomContent(message),
role: message.role,
content: message.content,
}));
Expand Down
12 changes: 9 additions & 3 deletions apps/chat/src/utils/server/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ export const hardLimitMessages = (messages: Message[]) => {
export function getMessageCustomContent(
message: Message,
): Partial<Message> | undefined {
if (message.role === Role.Assistant && !message.custom_content?.state) {
return;
}
return message.custom_content?.state ||
message.custom_content?.attachments?.length
? {
Expand All @@ -121,6 +118,15 @@ export function getMessageCustomContent(
: undefined;
}

export function getUserMessageCustomContent(
message: Message,
): Partial<Message> | undefined {
if (message.role === Role.Assistant && !message.custom_content?.state) {
return;
}
return getMessageCustomContent(message);
}

const getResponseBody = (
fieldName: string,
displayMessage: string | undefined,
Expand Down

0 comments on commit bb429cf

Please sign in to comment.