Skip to content

Commit

Permalink
Perf: vector queue and app ui (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Jun 13, 2024
1 parent 05611df commit b8b26ad
Show file tree
Hide file tree
Showing 23 changed files with 157 additions and 61 deletions.
3 changes: 3 additions & 0 deletions docSite/content/zh-cn/docs/development/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Mongo 数据库需要注意,需要注意在连接地址中增加 `directConnec
# 给自动化脚本代码执行权限(非 linux 系统, 可以手动执行里面的 postinstall.sh 文件内容)
chmod -R +x ./scripts/
# 代码根目录下执行,会安装根 package、projects 和 packages 内所有依赖
# 如果提示 isolate-vm 安装失败,可以参考:https://github.com/laverdet/isolated-vm?tab=readme-ov-file#requirements
pnpm i

# 非 Make 运行
Expand All @@ -103,6 +104,8 @@ docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/f
make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 proxy=taobao
```

如果不使用 `docker` 打包,需要手动把 `Dockerfile` 里 run 阶段的内容全部手动执行一遍(非常不推荐)。

## 提交代码至开源仓库

1. 确保你的代码是 Fork [FastGPT](https://github.com/labring/FastGPT) 仓库
Expand Down
3 changes: 2 additions & 1 deletion docSite/content/zh-cn/docs/development/upgrading/484.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ curl --location --request POST 'https://{{host}}/api/admin/init/484' \
4. 修复 - Debug 模式下,相同 source 和 target 内容,导致连线显示异常。
5. 修复 - 定时执行初始化错误。
6. 修复 - 应用调用传参异常。
7. 调整组件库全局theme。
7. 修复 - ctrl + cv 复杂节点时,nodeId错误。
8. 调整组件库全局theme。
9 changes: 8 additions & 1 deletion packages/service/common/mongo/sessionRun.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { addLog } from '../system/log';
import { connectionMongo, ClientSession } from './index';

export const mongoSessionRun = async <T = unknown>(fn: (session: ClientSession) => Promise<T>) => {
const session = await connectionMongo.startSession();
let committed = false;

try {
session.startTransaction();
const result = await fn(session);

await session.commitTransaction();
committed = true;

return result as T;
} catch (error) {
await session.abortTransaction();
if (!committed) {
await session.abortTransaction();
} else {
addLog.warn('Un catch mongo session error', { error });
}
return Promise.reject(error);
} finally {
await session.endSession();
Expand Down
6 changes: 3 additions & 3 deletions packages/service/core/workflow/dispatch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons

if (res?.closed || props.maxRunTimes <= 0) return;
props.maxRunTimes--;
console.log(props.maxRunTimes, user._id);
addLog.debug(`Run node`, { maxRunTimes: props.maxRunTimes, uid: user._id });

await surrenderProcess();

if (status === 'run') {
addLog.info(`[dispatchWorkFlow] nodeRunWithActive: ${node.name}`);
addLog.debug(`[dispatchWorkFlow] nodeRunWithActive: ${node.name}`);
return nodeRunWithActive(node);
}
if (status === 'skip') {
addLog.info(`[dispatchWorkFlow] nodeRunWithSkip: ${node.name}`);
addLog.debug(`[dispatchWorkFlow] nodeRunWithSkip: ${node.name}`);
return nodeRunWithSkip(node);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/web/components/common/Icon/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const iconPaths = {
'core/app/simpleMode/whisper': () => import('./icons/core/app/simpleMode/whisper.svg'),
'core/app/toolCall': () => import('./icons/core/app/toolCall.svg'),
'core/app/ttsFill': () => import('./icons/core/app/ttsFill.svg'),
'core/app/type/simple': () => import('./icons/core/app/type/simple.svg'),
'core/app/type/workflow': () => import('./icons/core/app/type/workflow.svg'),
'core/app/variable/external': () => import('./icons/core/app/variable/external.svg'),
'core/app/variable/input': () => import('./icons/core/app/variable/input.svg'),
'core/app/variable/select': () => import('./icons/core/app/variable/select.svg'),
Expand Down
15 changes: 15 additions & 0 deletions packages/web/components/common/Icon/icons/core/app/type/simple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/web/components/common/MyModal/EditFolderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const EditFolderModal = ({
</Box>
</ModalBody>
<ModalFooter>
<Button isLoading={loading} onClick={handleSubmit(onSave)}>
<Button isLoading={loading} onClick={handleSubmit(onSave)} px={6}>
{t('common.Confirm')}
</Button>
</ModalFooter>
Expand Down
42 changes: 17 additions & 25 deletions packages/web/components/common/MyTooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,24 @@ const MyTooltip = ({ children, forceShow = false, shouldWrapChildren = true, ...
const [isPc] = useMediaQuery('(min-width: 900px)');

return isPc || forceShow ? (
<Box
css={css({
'& span': {
display: 'block'
}
})}
<Tooltip
className="chakra-tooltip"
bg={'white'}
arrowShadowColor={'rgba(0,0,0,0.05)'}
hasArrow
arrowSize={12}
offset={[-15, 15]}
color={'myGray.800'}
px={4}
py={2}
borderRadius={'8px'}
whiteSpace={'pre-wrap'}
boxShadow={'1px 1px 10px rgba(0,0,0,0.2)'}
shouldWrapChildren={shouldWrapChildren}
{...props}
>
<Tooltip
className="chakra-tooltip"
bg={'white'}
arrowShadowColor={'rgba(0,0,0,0.05)'}
hasArrow
arrowSize={12}
offset={[-15, 15]}
color={'myGray.800'}
px={4}
py={2}
borderRadius={'8px'}
whiteSpace={'pre-wrap'}
boxShadow={'1px 1px 10px rgba(0,0,0,0.2)'}
shouldWrapChildren={shouldWrapChildren}
{...props}
>
{children}
</Tooltip>
</Box>
{children}
</Tooltip>
) : (
<>{children}</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CodeEditor = (props: Props) => {
<MyEditor {...props} bg={'myGray.50'} defaultHeight={600} />
</ModalBody>
<ModalFooter>
<Button mr={2} onClick={onClose}>
<Button mr={2} onClick={onClose} px={6}>
{t('common.Confirm')}
</Button>
</ModalFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const PromptEditor = ({
/>
</ModalBody>
<ModalFooter>
<Button mr={2} onClick={onClose}>
<Button mr={2} onClick={onClose} px={6}>
{t('common.Confirm')}
</Button>
</ModalFooter>
Expand Down
4 changes: 3 additions & 1 deletion packages/web/hooks/useConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const useConfirm = (props?: {
onClose();
typeof cancelCb.current === 'function' && cancelCb.current();
}}
px={5}
>
{closeText}
</Button>
Expand All @@ -109,8 +110,9 @@ export const useConfirm = (props?: {
size={'sm'}
bg={bg ? bg : map.bg}
isDisabled={countDownAmount > 0}
ml={4}
ml={3}
isLoading={isLoading || requesting}
px={5}
onClick={async () => {
setRequesting(true);
try {
Expand Down
4 changes: 3 additions & 1 deletion packages/web/hooks/useEditTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export const useEditTextarea = ({
{closeBtnText}
</Button>
)}
<Button onClick={onclickConfirm}>{t('common.Confirm')}</Button>
<Button onClick={onclickConfirm} px={6}>
{t('common.Confirm')}
</Button>
</ModalFooter>
</MyModal>
),
Expand Down
4 changes: 4 additions & 0 deletions projects/app/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@
},
"modules": {
"Title is required": "Module name cannot be empty"
},
"type": {
"Simple bot": "Simple bot",
"Workflow bot": "Workflow"
}
}
4 changes: 4 additions & 0 deletions projects/app/i18n/zh/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@
},
"modules": {
"Title is required": "模块名不能为空"
},
"type": {
"Simple bot": "简易应用",
"Workflow bot": "工作流"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const EditResourceModal = ({
</Box>
</ModalBody>
<ModalFooter>
<Button isLoading={loading} onClick={handleSubmit(onSave)}>
<Button isLoading={loading} onClick={handleSubmit(onSave)} px={6}>
{t('common.Confirm')}
</Button>
</ModalFooter>
Expand Down
35 changes: 35 additions & 0 deletions projects/app/src/components/core/app/TypeTag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useRef } from 'react';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import MyTag from '@fastgpt/web/components/common/Tag/index';
import { useI18n } from '@/web/context/I18n';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { Box } from '@chakra-ui/react';

const AppTypeTag = ({ type }: { type: AppTypeEnum }) => {
const { appT } = useI18n();

const map = useRef({
[AppTypeEnum.simple]: {
label: appT('type.Simple bot'),
icon: 'core/app/type/simple'
},
[AppTypeEnum.advanced]: {
label: appT('type.Workflow bot'),
icon: 'core/app/type/workflow'
},
[AppTypeEnum.folder]: undefined
});

const data = map.current[type];

return data ? (
<MyTag type="borderFill" colorSchema="gray">
<MyIcon name={data.icon as any} w={'0.8rem'} color={'myGray.500'} />
<Box ml={1} fontSize={'mini'}>
{data.label}
</Box>
</MyTag>
) : null;
};

export default AppTypeTag;
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,22 @@ export const useKeyboard = () => {
// filter workflow data
const newNodes = parseData
.filter((item) => !!item.type && item.data?.unique !== true)
.map((item) => ({
// reset id
...item,
id: getNanoid(),
data: {
...item.data,
nodeId: getNanoid()
},
position: {
x: item.position.x + 100,
y: item.position.y + 100
}
}));
.map((item) => {
const nodeId = getNanoid();
return {
// reset id
...item,
id: nodeId,
data: {
...item.data,
nodeId
},
position: {
x: item.position.x + 100,
y: item.position.y + 100
}
};
});

setNodes((prev) =>
prev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const useReference = ({
.filter((item) => item.children.length > 0);

return list;
}, [edges, nodeId, nodeList, t, valueType]);
}, [appDetail.chatConfig, edges, nodeId, nodeList, t, valueType]);

const formatValue = useMemo(() => {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const MemberListCard = ({ tagStyle, ...props }: MemberListCardProps) => {
return (
<Tag key={member.tmbId} type={'fill'} colorSchema="white" {...tagStyle}>
<Avatar src={member.avatar} w="1.25rem" />
<Box fontSize={'sm'}>{member.name}</Box>
<Box fontSize={'sm'} ml={1}>
{member.name}
</Box>
</Tag>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TeamModalContext } from '../../context';
import { TeamPermissionList } from '@fastgpt/global/support/permission/user/constant';
import dynamic from 'next/dynamic';
import MyBox from '@fastgpt/web/components/common/MyBox';
import MyTag from '@fastgpt/web/components/common/Tag/index';

const AddManagerModal = dynamic(() => import('./AddManager'));

Expand Down Expand Up @@ -56,8 +57,8 @@ function PermissionManage() {
bgColor={'myGray.100'}
alignItems={'center'}
alignContent={'center'}
mx={'6'}
px={'3'}
ml={3}
borderRadius={'sm'}
>
{TeamPermissionList['manage'].description}
Expand All @@ -78,19 +79,20 @@ function PermissionManage() {
</Button>
)}
</Flex>
<Flex mt="4" mx="4">
<Flex mt="4" mx="4" flexWrap={'wrap'} gap={3}>
{members.map((member) => {
if (member.permission.hasManagePer && !member.permission.isOwner) {
return (
<Tag key={member.memberName} mx={'2'} px="4" py="2" bg="myGray.100">
<Avatar src={member.avatar} w="20px" />
<TagLabel fontSize={'md'} alignItems="center" mr="6" ml="2">
<MyTag key={member.tmbId} px="4" py="2" type="fill" colorSchema="gray">
<Avatar src={member.avatar} w="1.25rem" />
<Box fontSize={'sm'} ml={1}>
{member.memberName}
</TagLabel>
</Box>
{userInfo?.team.role === 'owner' && (
<MyIcon
ml={4}
name="common/trash"
w="16px"
w="1rem"
color="myGray.500"
cursor="pointer"
_hover={{ color: 'red.600' }}
Expand All @@ -99,7 +101,7 @@ function PermissionManage() {
}}
/>
)}
</Tag>
</MyTag>
);
}
})}
Expand Down
Loading

0 comments on commit b8b26ad

Please sign in to comment.