perf: attribute

This commit is contained in:
archer
2023-07-08 10:37:25 +08:00
parent 23642af6e2
commit aef42cef9d
17 changed files with 1177 additions and 351 deletions

View File

@@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1688783528309" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5845" xmlns:xlink="http://www.w3.org/1999/xlink" ><path d="M931.53 960H512C264.97 960 64 759.03 64 512S264.97 64 512 64s448 200.97 448 448v419.53c0 15.69-12.77 28.47-28.47 28.47zM512 116.71c-217.96 0-395.29 177.33-395.29 395.29 0 217.97 177.33 395.3 395.29 395.3h395.29V512c0-217.97-177.33-395.29-395.29-395.29z" fill="#333333" p-id="5846"></path><path d="M730.13 439.04H293.87c-14.55 0-26.35-11.8-26.35-26.35s11.8-26.35 26.35-26.35h436.26c14.55 0 26.35 11.8 26.35 26.35s-11.8 26.35-26.35 26.35zM730.13 637.67H293.87c-14.55 0-26.35-11.8-26.35-26.35s11.8-26.35 26.35-26.35h436.26c14.55 0 26.35 11.8 26.35 26.35s-11.8 26.35-26.35 26.35z" p-id="5847"></path></svg>

After

Width:  |  Height:  |  Size: 912 B

View File

@@ -36,7 +36,8 @@ const map = {
date: require('./icons/date.svg').default,
apikey: require('./icons/apikey.svg').default,
save: require('./icons/save.svg').default,
minus: require('./icons/minus.svg').default
minus: require('./icons/minus.svg').default,
chatLight: require('./icons/light/chat.svg').default
};
export type IconName = keyof typeof map;

View File

@@ -23,7 +23,7 @@ const Navbar = ({ unread }: { unread: number }) => {
{
label: '聊天',
icon: 'chat',
link: `/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`,
link: `/chat?appId=${lastChatModelId}&chatId=${lastChatId}`,
activeLink: ['/chat']
},
{

View File

@@ -13,7 +13,7 @@ const NavbarPhone = ({ unread }: { unread: number }) => {
{
label: '聊天',
icon: 'tabbarChat',
link: `/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`,
link: `/chat?appId=${lastChatModelId}&chatId=${lastChatId}`,
activeLink: ['/chat'],
unread: 0
},

File diff suppressed because it is too large Load Diff

View File

@@ -72,6 +72,12 @@ export async function kbSearch({
maxToken = 2500,
userChatInput
}: Props): Promise<Response> {
if (kb_ids.length === 0)
return {
isEmpty: true,
rawSearch: [],
quotePrompt: undefined
};
// get vector
const promptVector = await openaiEmbedding_system({
input: [userChatInput]

View File

@@ -238,7 +238,7 @@ const Settings = ({ modelId }: { modelId: string }) => {
router.prefetch('/chat');
await saveUpdateModel();
} catch (error) {}
router.push(`/chat?modelId=${modelId}`);
router.push(`/chat?appId=${modelId}`);
}}
>

View File

@@ -31,8 +31,8 @@ const ModuleStoreList = ({
position={'fixed'}
top={0}
left={0}
right={0}
bottom={0}
w={'360px'}
></Box>
<Flex
zIndex={3}
@@ -66,7 +66,7 @@ const ModuleStoreList = ({
borderRadius={'md'}
draggable
onDragEnd={(e) => {
// if (e.clientX < 400) return;
if (e.clientX < 360) return;
onAddNode({
template: item,
position: { x: e.clientX, y: e.clientY }

View File

@@ -187,6 +187,7 @@ const AppEdit = ({ app, onBack }: Props) => {
targets: [] as FlowOutputTargetItemType[]
}))
}));
console.log(modules);
// update inputs and outputs
modules.forEach((module) => {

View File

@@ -83,7 +83,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
<Box display={['block', 'flex']} h={'100%'}>
{/* pc tab */}
<Box display={['none', 'block']} p={4} w={'200px'} borderRight={theme.borders.base}>
<Flex mb={4}>
<Flex mb={4} alignItems={'center'}>
<Avatar src={appDetail.avatar} w={'34px'} borderRadius={'lg'} />
<Box ml={2} fontWeight={'bold'}>
{appDetail.name}
@@ -97,7 +97,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
activeId={currentTab}
onChange={(e: any) => {
if (e === 'startChat') {
router.push(`/chat?modelId=${appId}`);
router.push(`/chat?appId=${appId}`);
} else {
setCurrentTab(e);
}
@@ -118,7 +118,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
activeId={currentTab}
onChange={(e: any) => {
if (e === 'startChat') {
router.push(`/chat?modelId=${appId}`);
router.push(`/chat?appId=${appId}`);
} else {
setCurrentTab(e);
}

View File

@@ -21,47 +21,16 @@ import { getErrText } from '@/utils/tools';
import { useToast } from '@/hooks/useToast';
import { postCreateApp } from '@/api/app';
import { useRouter } from 'next/router';
import { chatAppDemo } from '@/constants/app';
import { appTemplates } from '@/constants/app';
import Avatar from '@/components/Avatar';
import MyIcon from '@/components/Icon';
type FormType = {
avatar: string;
name: string;
templateId: number;
templateId: string;
};
const templates = [
{
id: 0,
icon: 'settings',
name: '简单的对话',
intro: '一个极其简单的 AI 对话应用',
modules: chatAppDemo.modules
},
{
id: 1,
icon: 'settings',
name: '基础知识库',
intro: '每次提问时进行一次知识库搜索,将搜索结果注入 LLM 模型进行参考回答',
modules: chatAppDemo.modules
},
{
id: 2,
icon: 'settings',
name: '问答前引导',
intro: '可以在每次对话开始前提示用户填写一些内容,作为本次对话的永久内容',
modules: chatAppDemo.modules
},
{
id: 3,
icon: 'settings',
name: '意图识别 + 知识库',
intro: '先对用户的问题进行分类,再根据不同类型问题,执行不同的操作',
modules: chatAppDemo.modules
}
];
const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: () => void }) => {
const [refresh, setRefresh] = useState(false);
const [creating, setCreating] = useState(false);
@@ -72,7 +41,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
defaultValues: {
avatar: '/icon/logo.png',
name: '',
templateId: 0
templateId: appTemplates[0].id
}
});
@@ -110,7 +79,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
const id = await postCreateApp({
avatar: data.avatar,
name: data.name,
modules: templates.find((item) => item.id === data.templateId)?.modules || []
modules: appTemplates.find((item) => item.id === data.templateId)?.modules || []
});
toast({
title: '创建成功',
@@ -163,7 +132,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
gridTemplateColumns={['repeat(1,1fr)', 'repeat(2,1fr)']}
gridGap={4}
>
{templates.map((item) => (
{appTemplates.map((item) => (
<Card
key={item.id}
border={theme.borders.base}
@@ -186,7 +155,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
}}
>
<Flex alignItems={'center'}>
<MyIcon name={'apikey'} w={'16px'} />
<Avatar src={item.avatar} borderRadius={'md'} w={'20px'} />
<Box ml={3} fontWeight={'bold'}>
{item.name}
</Box>

View File

@@ -89,22 +89,27 @@ const MyApps = () => {
border={theme.borders.md}
boxShadow={'none'}
userSelect={'none'}
position={'relative'}
_hover={{
boxShadow: '1px 1px 10px rgba(0,0,0,0.2)',
borderColor: 'transparent',
'& .delete': {
display: 'block'
},
'& .chat': {
display: 'block'
}
}}
onClick={() => router.push(`/app/detail?appId=${app._id}`)}
>
<Flex alignItems={'center'} h={'38px'} position={'relative'}>
<Flex alignItems={'center'} h={'38px'}>
<Avatar src={app.avatar} borderRadius={'md'} w={'28px'} />
<Box ml={3}>{app.name}</Box>
<IconButton
className="delete"
position={'absolute'}
right={0}
top={4}
right={4}
size={'sm'}
icon={<MyIcon name={'delete'} w={'14px'} />}
variant={'base'}
@@ -129,6 +134,25 @@ const MyApps = () => {
>
{app.intro || '这个应用还没写介绍~'}
</Box>
<IconButton
className="chat"
position={'absolute'}
right={4}
bottom={4}
size={'sm'}
icon={<MyIcon name={'chatLight'} w={'14px'} />}
variant={'base'}
borderRadius={'md'}
aria-label={'delete'}
display={['', 'none']}
_hover={{
bg: 'myGray.100'
}}
onClick={(e) => {
e.stopPropagation();
router.push(`/chat?appId=${app._id}`);
}}
/>
</Card>
))}
</Grid>

View File

@@ -77,7 +77,7 @@ const ShareModelList = ({
size={'sm'}
variant={'base'}
w={['60px', '70px']}
onClick={() => router.push(`/chat?modelId=${model._id}`)}
onClick={() => router.push(`/chat?appId=${model._id}`)}
>
</Button>

View File

@@ -125,7 +125,7 @@ const PcSliderBar = ({
w={'100%'}
h={'100%'}
leftIcon={<AddIcon />}
onClick={() => router.replace(`/chat?modelId=${modelId}`)}
onClick={() => router.replace(`/chat?appId=${modelId}`)}
>
</Button>
@@ -176,9 +176,9 @@ const PcSliderBar = ({
onClick={() => {
if (item._id === chatId) return;
if (isPc) {
router.replace(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
router.replace(`/chat?appId=${item.modelId}&chatId=${item._id}`);
} else {
router.push(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
router.push(`/chat?appId=${item.modelId}&chatId=${item._id}`);
}
}}
onContextMenu={(e) => onclickContextMenu(e, item)}
@@ -251,7 +251,7 @@ const PcSliderBar = ({
try {
await onclickDelHistory(contextMenuData.history._id);
if (contextMenuData.history._id === chatId) {
router.replace(`/chat?modelId=${modelId}`);
router.replace(`/chat?appId=${modelId}`);
}
} catch (error) {
console.log(error);

View File

@@ -30,7 +30,7 @@ const ModelList = ({ models, modelId }: { models: AppListItemType[]; modelId: st
}
: {})}
onClick={() => {
router.replace(`/chat?modelId=${item._id}`);
router.replace(`/chat?appId=${item._id}`);
}}
>
<Avatar src={item.avatar} w={'34px'} h={'34px'} />

View File

@@ -95,7 +95,7 @@ const PhoneSliderBar = ({
color={'white'}
leftIcon={<AddIcon />}
onClick={() => {
router.replace(`/chat?modelId=${modelId}`);
router.replace(`/chat?appId=${modelId}`);
onClose();
}}
>
@@ -128,7 +128,7 @@ const PhoneSliderBar = ({
: {})}
onClick={async () => {
if (item._id === modelId) return;
router.replace(`/chat?modelId=${item._id}`);
router.replace(`/chat?appId=${item._id}`);
onClose();
}}
>
@@ -159,7 +159,7 @@ const PhoneSliderBar = ({
: {})}
onClick={() => {
if (item._id === chatId) return;
router.replace(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
router.replace(`/chat?appId=${item.modelId}&chatId=${item._id}`);
onClose();
}}
>
@@ -177,7 +177,7 @@ const PhoneSliderBar = ({
await delChatHistoryById(item._id);
loadHistory({ pageNum: 1, init: true });
if (item._id === chatId) {
router.replace(`/chat?modelId=${modelId}`);
router.replace(`/chat?appId=${modelId}`);
}
}}
/>

View File

@@ -65,7 +65,7 @@ const textareaMinH = '22px';
const Chat = () => {
const router = useRouter();
const { modelId = '', chatId = '' } = router.query as { modelId: string; chatId: string };
const { appId = '', chatId = '' } = router.query as { appId: string; chatId: string };
const theme = useTheme();
const ChatBox = useRef<HTMLDivElement>(null);
@@ -179,7 +179,7 @@ const Chat = () => {
data: {
messages,
chatId,
appId: modelId,
appId,
model: ''
},
onMessage: (text: string) => {
@@ -206,7 +206,7 @@ const Chat = () => {
// save chat
if (newChatId) {
setForbidLoadChatData(true);
router.replace(`/chat?modelId=${modelId}&chatId=${newChatId}`);
router.replace(`/chat?appId=${appId}&chatId=${newChatId}`);
}
abortSignal.signal.aborted && (await delay(500));
@@ -243,7 +243,7 @@ const Chat = () => {
},
[
chatId,
modelId,
appId,
setChatData,
generatingMessage,
setForbidLoadChatData,
@@ -474,17 +474,17 @@ const Chat = () => {
// 获取对话信息
const loadChatInfo = useCallback(
async ({
modelId,
appId,
chatId,
loading = false
}: {
modelId: string;
appId: string;
chatId: string;
loading?: boolean;
}) => {
try {
loading && setIsLoading(true);
const res = await getInitChatSiteInfo(modelId, chatId);
const res = await getInitChatSiteInfo(appId, chatId);
setChatData({
...res,
@@ -502,9 +502,9 @@ const Chat = () => {
}
// 空 modelId 请求, 重定向到新的 model 聊天
if (res.modelId !== modelId) {
if (res.modelId !== appId) {
setForbidLoadChatData(true);
router.replace(`/chat?modelId=${res.modelId}`);
router.replace(`/chat?appId=${res.modelId}`);
}
} catch (e: any) {
// reset all chat tore
@@ -529,15 +529,15 @@ const Chat = () => {
]
);
// 初始化聊天框
useQuery(['init', modelId, chatId], () => {
useQuery(['init', appId, chatId], () => {
// pc: redirect to latest model chat
if (!modelId && lastChatModelId) {
router.replace(`/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`);
if (!appId && lastChatModelId) {
router.replace(`/chat?appId=${lastChatModelId}&chatId=${lastChatId}`);
return null;
}
// store id
modelId && setLastChatModelId(modelId);
appId && setLastChatModelId(appId);
setLastChatId(chatId);
if (forbidLoadChatData) {
@@ -546,7 +546,7 @@ const Chat = () => {
}
return loadChatInfo({
modelId,
appId,
chatId,
loading: true
});
@@ -559,7 +559,7 @@ const Chat = () => {
isLeavePage.current = true;
controller.current?.abort();
};
}, [modelId, chatId]);
}, [appId, chatId]);
// context menu component
const RenderContextMenu = useCallback(
@@ -611,14 +611,14 @@ const Chat = () => {
backgroundColor={useColorModeValue('#fdfdfd', '')}
>
{/* pc always show history. */}
{(isPc || !modelId) && (
{(isPc || !appId) && (
<SideBar>
<History onclickDelHistory={onclickDelHistory} onclickExportChat={onclickExportChat} />
</SideBar>
)}
{/* 聊天内容 */}
{modelId && (
{appId && (
<Flex
position={'relative'}
h={[0, '100%']}
@@ -667,15 +667,13 @@ const Chat = () => {
/>
</MenuButton>
<MenuList minW={`90px !important`}>
<MenuItem onClick={() => router.replace(`/chat?modelId=${modelId}`)}>
</MenuItem>
<MenuItem onClick={() => router.replace(`/chat?appId=${appId}`)}></MenuItem>
<MenuItem
onClick={async () => {
try {
setIsLoading(true);
await onclickDelHistory(chatData.chatId);
router.replace(`/chat?modelId=${modelId}`);
router.replace(`/chat?appId=${appId}`);
} catch (err) {
console.log(err);
}
@@ -901,7 +899,7 @@ const Chat = () => {
<Drawer isOpen={isOpenSlider} placement="left" size={'xs'} onClose={onCloseSlider}>
<DrawerOverlay backgroundColor={'rgba(255,255,255,0.5)'} />
<DrawerContent maxW={'70%'}>
<PhoneSliderBar chatId={chatId} modelId={modelId} onClose={onCloseSlider} />
<PhoneSliderBar chatId={chatId} modelId={appId} onClose={onCloseSlider} />
</DrawerContent>
</Drawer>
)}