Refactor stopGenerating function in ChatStore

- Changed the parameters of stopGenerating function to accept hash and message as strings.
- Updated the stopGenerating function calls in StopButton and ChatPanel components.
- Added a condition to update the last message when the generation has not completed.
This commit is contained in:
Rankin Zheng 2023-08-30 12:02:23 +08:00
parent 15d0ebe15d
commit a821a174f2
3 changed files with 6 additions and 7 deletions

View File

@ -25,7 +25,7 @@ const StopButton = observer(() => {
}
}}
onClick={() => {
chat.stopGenerating(false, null);
chat.stopGenerating(false, '', chat.currentMessage);
messageUtil.sendMessage({
command: 'stopDevChat'
});

View File

@ -88,8 +88,7 @@ const chatPanel = observer(() => {
timer.start();
});
messageUtil.registerHandler('receiveMessage', (message: { text: string; isError: boolean, hash }) => {
const messageItem = Message.create({ type: 'bot', message: message.text, hash: message.hash });
chat.stopGenerating(true, messageItem);
chat.stopGenerating(true, message.hash, message.text);
if (message.isError) {
chat.happendError(message.text);
}

View File

@ -170,20 +170,20 @@ You can configure DevChat from [Settings](#settings).`;
command: 'regeneration'
});
},
stopGenerating: (hasDone: boolean, message: Instance<typeof Message> | Instance<typeof types.null>) => {
stopGenerating: (hasDone: boolean, hash: string = '', message: string = '') => {
self.generating = false;
self.responsed = false;
self.hasDone = hasDone;
const messagesLength = self.messages.length;
if (hasDone) {
const { hash } = message ? message : { hash: '' };
const messagesLength = self.messages.length;
if (messagesLength > 1) {
self.messages[messagesLength - 2].hash = hash;
self.messages[messagesLength - 1].hash = hash;
} else if (messagesLength > 0) {
self.messages[messagesLength - 1].hash = hash;
}
} else {
self.messages[messagesLength - 1].message = message;
}
},
startResponsing: (message: string) => {