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:
parent
15d0ebe15d
commit
a821a174f2
@ -25,7 +25,7 @@ const StopButton = observer(() => {
|
||||
}
|
||||
}}
|
||||
onClick={() => {
|
||||
chat.stopGenerating(false, null);
|
||||
chat.stopGenerating(false, '', chat.currentMessage);
|
||||
messageUtil.sendMessage({
|
||||
command: 'stopDevChat'
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user