Dataset folder manager (#274)

* feat: retry send

* perf: qa default value

* feat: dataset folder

* feat: kb folder delete and path

* fix: ts

* perf: script load

* feat: fileCard and dataCard

* feat: search file

* feat: max token

* feat: select dataset

* fix: preview chunk

* perf: source update

* export data limit file_id

* docs

* fix: export limit
This commit is contained in:
Archer
2023-09-10 16:37:32 +08:00
committed by GitHub
parent a1a63260dd
commit 7917766024
83 changed files with 1996 additions and 702 deletions

View File

@@ -55,6 +55,7 @@ const SelectDataset = dynamic(() => import('./SelectDataset'));
const InputDataModal = dynamic(() => import('@/pages/kb/detail/components/InputDataModal'));
import styles from './index.module.scss';
import Script from 'next/script';
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 24);
@@ -293,7 +294,7 @@ const ChatBox = (
* user confirm send prompt
*/
const sendPrompt = useCallback(
async (variables: Record<string, any> = {}, inputVal = '') => {
async (variables: Record<string, any> = {}, inputVal = '', history = chatHistory) => {
if (!onStartChat) return;
if (isChatting) {
toast({
@@ -314,7 +315,7 @@ const ChatBox = (
}
const newChatList: ChatSiteItemType[] = [
...chatHistory,
...history,
{
dataId: nanoid(),
obj: 'Human',
@@ -407,6 +408,22 @@ const ChatBox = (
]
);
// retry input
const retryInput = useCallback(
async (index: number) => {
if (!onDelMessage) return;
const delHistory = chatHistory.slice(index);
setChatHistory((state) => (index === 0 ? [] : state.slice(0, index)));
await Promise.all(
delHistory.map((item, i) => onDelMessage({ contentId: item.dataId, index: index + i }))
);
sendPrompt(variables, delHistory[0].value, chatHistory.slice(0, index));
},
[chatHistory, onDelMessage, sendPrompt, variables]
);
// output data
useImperativeHandle(ref, () => ({
getChatHistory: () => chatHistory,
@@ -470,7 +487,7 @@ const ChatBox = (
);
const statusBoxData = useMemo(() => {
const colorMap = {
loading: '#67c13b',
loading: 'myGray.700',
running: '#67c13b',
finish: 'myBlue.600'
};
@@ -484,6 +501,7 @@ const ChatBox = (
};
}, [chatHistory, isChatting, t]);
// page change and abort request
useEffect(() => {
return () => {
controller.current?.abort('leave');
@@ -492,16 +510,7 @@ const ChatBox = (
};
}, [router.query]);
useEffect(() => {
event.on('guideClick', ({ text }: { text: string }) => {
if (!text) return;
handleSubmit((data) => sendPrompt(data, text))();
});
return () => {
event.off('guideClick');
};
}, [handleSubmit, sendPrompt]);
// page destroy and abort request
useEffect(() => {
const listen = () => {
cancelBroadcast();
@@ -513,8 +522,22 @@ const ChatBox = (
};
}, []);
// add guide text listener
useEffect(() => {
event.on('guideClick', ({ text }: { text: string }) => {
if (!text) return;
handleSubmit((data) => sendPrompt(data, text))();
});
return () => {
event.off('guideClick');
};
}, [handleSubmit, sendPrompt]);
return (
<Flex flexDirection={'column'} h={'100%'}>
<Script src="/js/html2pdf.bundle.min.js" strategy="lazyOnload"></Script>
<Box ref={ChatBoxRef} flex={'1 0 0'} h={0} w={'100%'} overflow={'overlay'} px={[4, 0]} pb={3}>
<Box id="chat-container" maxW={['100%', '92%']} h={'100%'} mx={'auto'}>
{showEmpty && <Empty />}
@@ -616,7 +639,7 @@ const ChatBox = (
justifyContent={'flex-end'}
mr={3}
>
<MyTooltip label={'复制'}>
<MyTooltip label={t('common.Copy')}>
<MyIcon
{...controlIconStyle}
name={'copy'}
@@ -624,8 +647,18 @@ const ChatBox = (
onClick={() => onclickCopy(item.value)}
/>
</MyTooltip>
{!!onDelMessage && (
<MyTooltip label={t('chat.retry')}>
<MyIcon
{...controlIconStyle}
name={'retryLight'}
_hover={{ color: 'green.500' }}
onClick={() => retryInput(index)}
/>
</MyTooltip>
)}
{onDelMessage && (
<MyTooltip label={'删除'}>
<MyTooltip label={t('common.Delete')}>
<MyIcon
{...controlIconStyle}
mr={0}