Merge pull request #45 from covespace/stop-generating
Stop generating and load history messages
This commit is contained in:
commit
344a95868c
@ -8,7 +8,7 @@ import { createStyles, keyframes } from '@mantine/core';
|
|||||||
import { ActionIcon } from '@mantine/core';
|
import { ActionIcon } from '@mantine/core';
|
||||||
import { Menu, Button, Text } from '@mantine/core';
|
import { Menu, Button, Text } from '@mantine/core';
|
||||||
import { useElementSize, useListState, useResizeObserver, useViewportSize } from '@mantine/hooks';
|
import { useElementSize, useListState, useResizeObserver, useViewportSize } from '@mantine/hooks';
|
||||||
import { IconAdjustments, IconBulb, IconCameraSelfie, IconCheck, IconClick, IconColumnInsertRight, IconCopy, IconDots, IconEdit, IconFileDiff, IconFolder, IconGitCommit, IconGitCompare, IconMessageDots, IconMessagePlus, IconPrinter, IconPrompt, IconReplace, IconRobot, IconSend, IconSquareRoundedPlus, IconTerminal2, IconUser, IconX } from '@tabler/icons-react';
|
import { IconAdjustments, IconBulb, IconCameraSelfie, IconCheck, IconClick, IconColumnInsertRight, IconCopy, IconDots, IconEdit, IconFileDiff, IconFolder, IconGitCommit, IconGitCompare, IconMessageDots, IconMessagePlus, IconPlayerStop, IconPrinter, IconPrompt, IconReplace, IconRobot, IconSend, IconSquareRoundedPlus, IconTerminal2, IconUser, IconX } from '@tabler/icons-react';
|
||||||
import { IconSettings, IconSearch, IconPhoto, IconMessageCircle, IconTrash, IconArrowsLeftRight } from '@tabler/icons-react';
|
import { IconSettings, IconSearch, IconPhoto, IconMessageCircle, IconTrash, IconArrowsLeftRight } from '@tabler/icons-react';
|
||||||
import { Prism } from '@mantine/prism';
|
import { Prism } from '@mantine/prism';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
@ -95,10 +95,15 @@ const chatPanel = () => {
|
|||||||
const scrollToBottom = () =>
|
const scrollToBottom = () =>
|
||||||
scrollViewport?.current?.scrollTo({ top: scrollViewport.current.scrollHeight, behavior: 'smooth' });
|
scrollViewport?.current?.scrollTo({ top: scrollViewport.current.scrollHeight, behavior: 'smooth' });
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
scrollToBottom();
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
inputRef.current.focus();
|
inputRef.current.focus();
|
||||||
messageUtil.sendMessage({ command: 'regContextList' });
|
messageUtil.sendMessage({ command: 'regContextList' });
|
||||||
messageUtil.sendMessage({ command: 'regCommandList' });
|
messageUtil.sendMessage({ command: 'regCommandList' });
|
||||||
|
messageUtil.sendMessage({ command: 'historyMessages' });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -167,9 +172,16 @@ const chatPanel = () => {
|
|||||||
file: message.file,
|
file: message.file,
|
||||||
context: context,
|
context: context,
|
||||||
});
|
});
|
||||||
console.log(context);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
messageUtil.registerHandler('loadHistoryMessages', (message: { command: string; entries: [{ hash: '', user: '', date: '', request: '', response: '', context: [{ content: '', role: '' }] }] }) => {
|
||||||
|
console.log(JSON.stringify(message));
|
||||||
|
message.entries?.forEach(({ hash, user, date, request, response, context }) => {
|
||||||
|
const contexts = context.map(({ content, role }) => ({ context: JSON.parse(content) }));
|
||||||
|
messageHandlers.append({ type: 'user', message: request, contexts: contexts });
|
||||||
|
messageHandlers.append({ type: 'bot', message: response });
|
||||||
|
});
|
||||||
|
});
|
||||||
}, [registed]);
|
}, [registed]);
|
||||||
|
|
||||||
const handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
const handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
@ -466,6 +478,21 @@ const chatPanel = () => {
|
|||||||
}
|
}
|
||||||
</Accordion>
|
</Accordion>
|
||||||
}
|
}
|
||||||
|
{generating &&
|
||||||
|
<Center>
|
||||||
|
<Button
|
||||||
|
leftIcon={<IconPlayerStop />}
|
||||||
|
variant="white"
|
||||||
|
onClick={() => {
|
||||||
|
messageUtil.sendMessage({
|
||||||
|
command: 'stopDevChat'
|
||||||
|
});
|
||||||
|
setGenerating(false);
|
||||||
|
}}>
|
||||||
|
Stop generating
|
||||||
|
</Button>
|
||||||
|
</Center>
|
||||||
|
}
|
||||||
<Menu
|
<Menu
|
||||||
id='commandMenu'
|
id='commandMenu'
|
||||||
position='top-start'
|
position='top-start'
|
||||||
@ -497,12 +524,12 @@ const chatPanel = () => {
|
|||||||
placeholder="Ctrl + Enter Send a message."
|
placeholder="Ctrl + Enter Send a message."
|
||||||
styles={{ icon: { alignItems: 'flex-start', paddingTop: '9px' }, rightSection: { alignItems: 'flex-start', paddingTop: '9px' } }}
|
styles={{ icon: { alignItems: 'flex-start', paddingTop: '9px' }, rightSection: { alignItems: 'flex-start', paddingTop: '9px' } }}
|
||||||
icon={
|
icon={
|
||||||
<ActionIcon onClick={handlePlusClick} sx={{ pointerEvents: 'all' }}>
|
<ActionIcon disabled={generating} onClick={handlePlusClick} sx={{ pointerEvents: 'all' }}>
|
||||||
<IconSquareRoundedPlus size="1rem" />
|
<IconSquareRoundedPlus size="1rem" />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
}
|
}
|
||||||
rightSection={
|
rightSection={
|
||||||
<ActionIcon onClick={handleSendClick}>
|
<ActionIcon disabled={generating} onClick={handleSendClick}>
|
||||||
<IconSend size="1rem" />
|
<IconSend size="1rem" />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user