chore: fix trimmed end break line

This commit is contained in:
Louis 2023-09-29 15:11:36 +07:00 committed by Louis
parent a0afdda16e
commit 706e8e9c78
2 changed files with 5 additions and 5 deletions

View File

@ -48,7 +48,7 @@ export default function renderChatMessage({
avatarUrl={senderAvatarUrl} avatarUrl={senderAvatarUrl}
senderName={senderName} senderName={senderName}
createdAt={createdAt} createdAt={createdAt}
text={htmlText ?? text} text={htmlText && htmlText.trim().length > 0 ? htmlText : text}
/> />
) : ( ) : (
<StreamTextMessage <StreamTextMessage
@ -57,7 +57,7 @@ export default function renderChatMessage({
avatarUrl={senderAvatarUrl} avatarUrl={senderAvatarUrl}
senderName={senderName} senderName={senderName}
createdAt={createdAt} createdAt={createdAt}
text={htmlText ?? text} text={htmlText && htmlText.trim().length > 0 ? htmlText : text}
/> />
); );
default: default:

View File

@ -116,7 +116,7 @@ export default function useSendChatMessage() {
const data = JSON.parse(line.replace("data: ", "")); const data = JSON.parse(line.replace("data: ", ""));
answer += data.choices[0]?.delta?.content ?? ""; answer += data.choices[0]?.delta?.content ?? "";
if (answer.startsWith("assistant: ")) { if (answer.startsWith("assistant: ")) {
answer = answer.replace("assistant: ", "").trim(); answer = answer.replace("assistant: ", "");
} }
updateStreamMessage({ updateStreamMessage({
...responseChatMessage, ...responseChatMessage,
@ -133,11 +133,11 @@ export default function useSendChatMessage() {
updateMessage( updateMessage(
responseChatMessage.id, responseChatMessage.id,
responseChatMessage.conversationId, responseChatMessage.conversationId,
answer answer.trimEnd()
); );
await executeSerial(DataService.UPDATE_MESSAGE, { await executeSerial(DataService.UPDATE_MESSAGE, {
...newResponse, ...newResponse,
message: answer, message: answer.trimEnd(),
updated_at: new Date() updated_at: new Date()
.toISOString() .toISOString()
.replace("T", " ") .replace("T", " ")