mirror of https://github.com/buster-so/buster.git
Update useChatStreamMessage.ts
This commit is contained in:
parent
74167c27a9
commit
0db64cd4a4
|
@ -157,19 +157,9 @@ export const useChatStreamMessage = () => {
|
||||||
if (!response_message?.id) return;
|
if (!response_message?.id) return;
|
||||||
|
|
||||||
const responseMessageId = response_message.id;
|
const responseMessageId = response_message.id;
|
||||||
const foundResponseMessage: BusterChatMessageResponse | undefined =
|
const existingMessage =
|
||||||
chatRef.current[chat_id]?.messages?.[message_id]?.response_messages?.[responseMessageId];
|
chatRef.current[chat_id]?.messages?.[message_id]?.response_messages?.[responseMessageId];
|
||||||
const isNewMessage = !foundResponseMessage;
|
const isNewMessage = !existingMessage;
|
||||||
|
|
||||||
if (response_message.type === 'text') {
|
|
||||||
const existingMessage =
|
|
||||||
(foundResponseMessage as BusterChatResponseMessage_text)?.message || '';
|
|
||||||
const isStreaming =
|
|
||||||
response_message.message_chunk !== undefined || response_message.message_chunk !== null;
|
|
||||||
if (isStreaming) {
|
|
||||||
response_message.message = existingMessage + response_message.message_chunk;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNewMessage) {
|
if (isNewMessage) {
|
||||||
initializeOrUpdateMessage(chat_id, message_id, (draft) => {
|
initializeOrUpdateMessage(chat_id, message_id, (draft) => {
|
||||||
|
@ -182,6 +172,28 @@ export const useChatStreamMessage = () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response_message.type === 'text') {
|
||||||
|
const existingResponseMessageText = existingMessage as BusterChatResponseMessage_text;
|
||||||
|
const isStreaming =
|
||||||
|
response_message.message_chunk !== undefined || response_message.message_chunk !== null;
|
||||||
|
|
||||||
|
initializeOrUpdateMessage(chat_id, message_id, (draft) => {
|
||||||
|
const responseMessage =
|
||||||
|
draft[chat_id]?.messages?.[message_id]?.response_messages?.[responseMessageId];
|
||||||
|
if (!responseMessage) return;
|
||||||
|
const messageText = responseMessage as BusterChatMessageReasoning_text;
|
||||||
|
|
||||||
|
Object.assign(messageText, {
|
||||||
|
...existingResponseMessageText,
|
||||||
|
...response_message,
|
||||||
|
message: isStreaming
|
||||||
|
? (existingResponseMessageText?.message || '') +
|
||||||
|
(response_message.message_chunk || '')
|
||||||
|
: response_message.message
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const response_messages = chatRef.current[chat_id]?.messages?.[message_id]?.response_messages;
|
const response_messages = chatRef.current[chat_id]?.messages?.[message_id]?.response_messages;
|
||||||
const response_message_ids =
|
const response_message_ids =
|
||||||
chatRef.current[chat_id]?.messages?.[message_id]?.response_message_ids;
|
chatRef.current[chat_id]?.messages?.[message_id]?.response_message_ids;
|
||||||
|
|
Loading…
Reference in New Issue