Perf system plugin and worker (#2126)

* perf: worker pool

* perf: worker register

* perf: worker controller

* perf: system plugin worker

* perf: system plugin worker

* perf: worker

* perf: worker

* worker timeout

* perf: copy icon
This commit is contained in:
Archer
2024-07-23 11:23:42 +08:00
committed by GitHub
parent a4787bce5c
commit e99c91aaa6
34 changed files with 433 additions and 235 deletions

View File

@@ -144,7 +144,16 @@ const ChatItem = ({
)}
</Flex>
{/* content */}
<Box mt={['6px', 2]} className="chat-box-card" textAlign={styleMap.textAlign}>
<Box
mt={['6px', 2]}
className="chat-box-card"
textAlign={styleMap.textAlign}
_hover={{
'& .footer-copy': {
display: 'block'
}
}}
>
<Card
{...MessageCardStyle}
bg={styleMap.bg}
@@ -156,19 +165,21 @@ const ChatItem = ({
{/* 对话框底部的复制按钮 */}
{type == ChatRoleEnum.AI && (!isChatting || (isChatting && !isLastChild)) && (
<Box
className="footer-copy"
display={['block', 'none']}
position={'absolute'}
bottom={0}
right={[0, -2]}
color={'myGray.400'}
right={0}
transform={'translateX(100%)'}
>
<MyTooltip label={t('common.Copy')}>
<MyTooltip label={t('common:common.Copy')}>
<MyIcon
w={'14px'}
w={'1rem'}
cursor="pointer"
p="5px"
bg="white"
name={'copy'}
color={'myGray.500'}
_hover={{ color: 'primary.600' }}
onClick={() => copyData(chatText)}
/>

View File

@@ -40,7 +40,6 @@ const ResponseTags = ({
sourceName: string;
};
}>();
const [isOverflow, setIsOverflow] = useState<boolean>(true);
const [quoteFolded, setQuoteFolded] = useState<boolean>(true);
const [contextModalData, setContextModalData] =
useState<DispatchNodeResponseType['historyPreview']>();
@@ -51,11 +50,9 @@ const ResponseTags = ({
} = useDisclosure();
const quoteListSize = useSize(quoteListRef);
useEffect(() => {
setIsOverflow(
quoteListRef.current ? quoteListRef.current.scrollHeight > (isPc ? 50 : 55) : true
);
}, [isOverflow, quoteListSize]);
const quoteIsOverflow = quoteListRef.current
? quoteListRef.current.scrollHeight > (isPc ? 50 : 55)
: true;
const {
llmModuleAccount,
@@ -114,7 +111,7 @@ const ResponseTags = ({
<Box width={'100%'}>
<ChatBoxDivider icon="core/chat/quoteFill" text={t('common:core.chat.Quote')} />{' '}
</Box>
{quoteFolded && isOverflow && (
{quoteFolded && quoteIsOverflow && (
<MyIcon
_hover={{ color: 'primary.500', cursor: 'pointer' }}
name="core/chat/chevronDown"
@@ -124,89 +121,79 @@ const ResponseTags = ({
)}
</Flex>
<Flex alignItems={'center'} flexWrap={'wrap'} gap={2} position={'relative'}>
{
<Collapse
startingHeight={isPc ? '50px' : '55px'}
in={(!quoteFolded && isOverflow) || !isOverflow}
>
<Flex
ref={quoteListRef}
alignItems={'center'}
position={'relative'}
flexWrap={'wrap'}
gap={2}
height={quoteFolded && isOverflow ? ['55px', '50px'] : 'auto'}
overflow={'hidden'}
_after={
quoteFolded && isOverflow
? {
content: '""',
position: 'absolute',
zIndex: 2,
bottom: 0,
left: 0,
width: '100%',
height: '50%',
background:
'linear-gradient(to bottom, rgba(247,247,247,0), rgba(247, 247, 247, 0.91))',
pointerEvents: 'none'
}
: {}
<Flex
ref={quoteListRef}
alignItems={'center'}
position={'relative'}
flexWrap={'wrap'}
gap={2}
maxH={quoteFolded && quoteIsOverflow ? ['50px', '55px'] : 'auto'}
overflow={'hidden'}
_after={
quoteFolded && quoteIsOverflow
? {
content: '""',
position: 'absolute',
zIndex: 2,
bottom: 0,
left: 0,
width: '100%',
height: '50%',
background:
'linear-gradient(to bottom, rgba(247,247,247,0), rgba(247, 247, 247, 0.91))'
}
>
{sourceList.map((item) => {
return (
<MyTooltip key={item.collectionId} label={t('core.chat.quote.Read Quote')}>
<Flex
alignItems={'center'}
fontSize={'xs'}
border={'sm'}
py={1.5}
px={2}
borderRadius={'sm'}
_hover={{
'.controller': {
display: 'flex'
}
}}
overflow={'hidden'}
position={'relative'}
cursor={'pointer'}
onClick={(e) => {
e.stopPropagation();
setQuoteModalData({
rawSearch: quoteList,
metadata: {
collectionId: item.collectionId,
sourceId: item.sourceId,
sourceName: item.sourceName
}
});
}}
>
<MyIcon name={item.icon as any} mr={1} flexShrink={0} w={'12px'} />
<Box className="textEllipsis3" wordBreak={'break-all'} flex={'1 0 0'}>
{item.sourceName}
</Box>
</Flex>
</MyTooltip>
);
})}
{isOverflow && !quoteFolded && (
<MyIcon
position={'absolute'}
bottom={0}
right={0}
_hover={{ color: 'primary.500', cursor: 'pointer' }}
name="core/chat/chevronUp"
w={'14px'}
onClick={() => setQuoteFolded(!quoteFolded)}
/>
)}
</Flex>
</Collapse>
: {}
}
>
{sourceList.map((item) => {
return (
<MyTooltip key={item.collectionId} label={t('common:core.chat.quote.Read Quote')}>
<Flex
alignItems={'center'}
fontSize={'xs'}
border={'sm'}
py={1.5}
px={2}
borderRadius={'sm'}
_hover={{
'.controller': {
display: 'flex'
}
}}
overflow={'hidden'}
position={'relative'}
cursor={'pointer'}
onClick={(e) => {
e.stopPropagation();
setQuoteModalData({
rawSearch: quoteList,
metadata: {
collectionId: item.collectionId,
sourceId: item.sourceId,
sourceName: item.sourceName
}
});
}}
>
<MyIcon name={item.icon as any} mr={1} flexShrink={0} w={'12px'} />
<Box className="textEllipsis3" wordBreak={'break-all'} flex={'1 0 0'}>
{item.sourceName}
</Box>
</Flex>
</MyTooltip>
);
})}
{!quoteFolded && (
<MyIcon
position={'absolute'}
bottom={0}
right={0}
_hover={{ color: 'primary.500', cursor: 'pointer' }}
name="core/chat/chevronUp"
w={'14px'}
onClick={() => setQuoteFolded(!quoteFolded)}
/>
)}
</Flex>
</>
)}

View File

@@ -11,21 +11,25 @@ import { useI18n } from '@/web/context/I18n';
import { useContextSelector } from 'use-context-selector';
import { AppContext } from '../context';
import { useChatTest } from '../useChatTest';
import { useDatasetStore } from '@/web/core/dataset/store/dataset';
const ChatTest = ({ appForm }: { appForm: AppSimpleEditFormType }) => {
const { t } = useTranslation();
const { appT } = useI18n();
const { appDetail } = useContextSelector(AppContext, (v) => v);
// form2AppWorkflow dependent allDatasets
const { allDatasets } = useDatasetStore();
const [workflowData, setWorkflowData] = useSafeState({
nodes: appDetail.modules || [],
edges: appDetail.edges || []
});
useEffect(() => {
const { nodes, edges } = form2AppWorkflow(appForm);
setWorkflowData({ nodes, edges });
}, [appForm, setWorkflowData]);
}, [appForm, setWorkflowData, allDatasets]);
const { restartChat, ChatContainer } = useChatTest({
...workflowData,