perf: attribute
This commit is contained in:
1
client/src/components/Icon/icons/light/chat.svg
Normal file
1
client/src/components/Icon/icons/light/chat.svg
Normal 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 |
@@ -36,7 +36,8 @@ const map = {
|
|||||||
date: require('./icons/date.svg').default,
|
date: require('./icons/date.svg').default,
|
||||||
apikey: require('./icons/apikey.svg').default,
|
apikey: require('./icons/apikey.svg').default,
|
||||||
save: require('./icons/save.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;
|
export type IconName = keyof typeof map;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const Navbar = ({ unread }: { unread: number }) => {
|
|||||||
{
|
{
|
||||||
label: '聊天',
|
label: '聊天',
|
||||||
icon: 'chat',
|
icon: 'chat',
|
||||||
link: `/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`,
|
link: `/chat?appId=${lastChatModelId}&chatId=${lastChatId}`,
|
||||||
activeLink: ['/chat']
|
activeLink: ['/chat']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const NavbarPhone = ({ unread }: { unread: number }) => {
|
|||||||
{
|
{
|
||||||
label: '聊天',
|
label: '聊天',
|
||||||
icon: 'tabbarChat',
|
icon: 'tabbarChat',
|
||||||
link: `/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`,
|
link: `/chat?appId=${lastChatModelId}&chatId=${lastChatId}`,
|
||||||
activeLink: ['/chat'],
|
activeLink: ['/chat'],
|
||||||
unread: 0
|
unread: 0
|
||||||
},
|
},
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -72,6 +72,12 @@ export async function kbSearch({
|
|||||||
maxToken = 2500,
|
maxToken = 2500,
|
||||||
userChatInput
|
userChatInput
|
||||||
}: Props): Promise<Response> {
|
}: Props): Promise<Response> {
|
||||||
|
if (kb_ids.length === 0)
|
||||||
|
return {
|
||||||
|
isEmpty: true,
|
||||||
|
rawSearch: [],
|
||||||
|
quotePrompt: undefined
|
||||||
|
};
|
||||||
// get vector
|
// get vector
|
||||||
const promptVector = await openaiEmbedding_system({
|
const promptVector = await openaiEmbedding_system({
|
||||||
input: [userChatInput]
|
input: [userChatInput]
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ const Settings = ({ modelId }: { modelId: string }) => {
|
|||||||
router.prefetch('/chat');
|
router.prefetch('/chat');
|
||||||
await saveUpdateModel();
|
await saveUpdateModel();
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
router.push(`/chat?modelId=${modelId}`);
|
router.push(`/chat?appId=${modelId}`);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
对话
|
对话
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ const ModuleStoreList = ({
|
|||||||
position={'fixed'}
|
position={'fixed'}
|
||||||
top={0}
|
top={0}
|
||||||
left={0}
|
left={0}
|
||||||
right={0}
|
|
||||||
bottom={0}
|
bottom={0}
|
||||||
|
w={'360px'}
|
||||||
></Box>
|
></Box>
|
||||||
<Flex
|
<Flex
|
||||||
zIndex={3}
|
zIndex={3}
|
||||||
@@ -66,7 +66,7 @@ const ModuleStoreList = ({
|
|||||||
borderRadius={'md'}
|
borderRadius={'md'}
|
||||||
draggable
|
draggable
|
||||||
onDragEnd={(e) => {
|
onDragEnd={(e) => {
|
||||||
// if (e.clientX < 400) return;
|
if (e.clientX < 360) return;
|
||||||
onAddNode({
|
onAddNode({
|
||||||
template: item,
|
template: item,
|
||||||
position: { x: e.clientX, y: e.clientY }
|
position: { x: e.clientX, y: e.clientY }
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ const AppEdit = ({ app, onBack }: Props) => {
|
|||||||
targets: [] as FlowOutputTargetItemType[]
|
targets: [] as FlowOutputTargetItemType[]
|
||||||
}))
|
}))
|
||||||
}));
|
}));
|
||||||
|
console.log(modules);
|
||||||
|
|
||||||
// update inputs and outputs
|
// update inputs and outputs
|
||||||
modules.forEach((module) => {
|
modules.forEach((module) => {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
|
|||||||
<Box display={['block', 'flex']} h={'100%'}>
|
<Box display={['block', 'flex']} h={'100%'}>
|
||||||
{/* pc tab */}
|
{/* pc tab */}
|
||||||
<Box display={['none', 'block']} p={4} w={'200px'} borderRight={theme.borders.base}>
|
<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'} />
|
<Avatar src={appDetail.avatar} w={'34px'} borderRadius={'lg'} />
|
||||||
<Box ml={2} fontWeight={'bold'}>
|
<Box ml={2} fontWeight={'bold'}>
|
||||||
{appDetail.name}
|
{appDetail.name}
|
||||||
@@ -97,7 +97,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
|
|||||||
activeId={currentTab}
|
activeId={currentTab}
|
||||||
onChange={(e: any) => {
|
onChange={(e: any) => {
|
||||||
if (e === 'startChat') {
|
if (e === 'startChat') {
|
||||||
router.push(`/chat?modelId=${appId}`);
|
router.push(`/chat?appId=${appId}`);
|
||||||
} else {
|
} else {
|
||||||
setCurrentTab(e);
|
setCurrentTab(e);
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
|
|||||||
activeId={currentTab}
|
activeId={currentTab}
|
||||||
onChange={(e: any) => {
|
onChange={(e: any) => {
|
||||||
if (e === 'startChat') {
|
if (e === 'startChat') {
|
||||||
router.push(`/chat?modelId=${appId}`);
|
router.push(`/chat?appId=${appId}`);
|
||||||
} else {
|
} else {
|
||||||
setCurrentTab(e);
|
setCurrentTab(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,47 +21,16 @@ import { getErrText } from '@/utils/tools';
|
|||||||
import { useToast } from '@/hooks/useToast';
|
import { useToast } from '@/hooks/useToast';
|
||||||
import { postCreateApp } from '@/api/app';
|
import { postCreateApp } from '@/api/app';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { chatAppDemo } from '@/constants/app';
|
import { appTemplates } from '@/constants/app';
|
||||||
import Avatar from '@/components/Avatar';
|
import Avatar from '@/components/Avatar';
|
||||||
import MyIcon from '@/components/Icon';
|
import MyIcon from '@/components/Icon';
|
||||||
|
|
||||||
type FormType = {
|
type FormType = {
|
||||||
avatar: string;
|
avatar: string;
|
||||||
name: 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 CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: () => void }) => {
|
||||||
const [refresh, setRefresh] = useState(false);
|
const [refresh, setRefresh] = useState(false);
|
||||||
const [creating, setCreating] = useState(false);
|
const [creating, setCreating] = useState(false);
|
||||||
@@ -72,7 +41,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
|
|||||||
defaultValues: {
|
defaultValues: {
|
||||||
avatar: '/icon/logo.png',
|
avatar: '/icon/logo.png',
|
||||||
name: '',
|
name: '',
|
||||||
templateId: 0
|
templateId: appTemplates[0].id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -110,7 +79,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
|
|||||||
const id = await postCreateApp({
|
const id = await postCreateApp({
|
||||||
avatar: data.avatar,
|
avatar: data.avatar,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
modules: templates.find((item) => item.id === data.templateId)?.modules || []
|
modules: appTemplates.find((item) => item.id === data.templateId)?.modules || []
|
||||||
});
|
});
|
||||||
toast({
|
toast({
|
||||||
title: '创建成功',
|
title: '创建成功',
|
||||||
@@ -163,7 +132,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
|
|||||||
gridTemplateColumns={['repeat(1,1fr)', 'repeat(2,1fr)']}
|
gridTemplateColumns={['repeat(1,1fr)', 'repeat(2,1fr)']}
|
||||||
gridGap={4}
|
gridGap={4}
|
||||||
>
|
>
|
||||||
{templates.map((item) => (
|
{appTemplates.map((item) => (
|
||||||
<Card
|
<Card
|
||||||
key={item.id}
|
key={item.id}
|
||||||
border={theme.borders.base}
|
border={theme.borders.base}
|
||||||
@@ -186,7 +155,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Flex alignItems={'center'}>
|
<Flex alignItems={'center'}>
|
||||||
<MyIcon name={'apikey'} w={'16px'} />
|
<Avatar src={item.avatar} borderRadius={'md'} w={'20px'} />
|
||||||
<Box ml={3} fontWeight={'bold'}>
|
<Box ml={3} fontWeight={'bold'}>
|
||||||
{item.name}
|
{item.name}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -89,22 +89,27 @@ const MyApps = () => {
|
|||||||
border={theme.borders.md}
|
border={theme.borders.md}
|
||||||
boxShadow={'none'}
|
boxShadow={'none'}
|
||||||
userSelect={'none'}
|
userSelect={'none'}
|
||||||
|
position={'relative'}
|
||||||
_hover={{
|
_hover={{
|
||||||
boxShadow: '1px 1px 10px rgba(0,0,0,0.2)',
|
boxShadow: '1px 1px 10px rgba(0,0,0,0.2)',
|
||||||
borderColor: 'transparent',
|
borderColor: 'transparent',
|
||||||
'& .delete': {
|
'& .delete': {
|
||||||
display: 'block'
|
display: 'block'
|
||||||
|
},
|
||||||
|
'& .chat': {
|
||||||
|
display: 'block'
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onClick={() => router.push(`/app/detail?appId=${app._id}`)}
|
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'} />
|
<Avatar src={app.avatar} borderRadius={'md'} w={'28px'} />
|
||||||
<Box ml={3}>{app.name}</Box>
|
<Box ml={3}>{app.name}</Box>
|
||||||
<IconButton
|
<IconButton
|
||||||
className="delete"
|
className="delete"
|
||||||
position={'absolute'}
|
position={'absolute'}
|
||||||
right={0}
|
top={4}
|
||||||
|
right={4}
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
icon={<MyIcon name={'delete'} w={'14px'} />}
|
icon={<MyIcon name={'delete'} w={'14px'} />}
|
||||||
variant={'base'}
|
variant={'base'}
|
||||||
@@ -129,6 +134,25 @@ const MyApps = () => {
|
|||||||
>
|
>
|
||||||
{app.intro || '这个应用还没写介绍~'}
|
{app.intro || '这个应用还没写介绍~'}
|
||||||
</Box>
|
</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>
|
</Card>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const ShareModelList = ({
|
|||||||
size={'sm'}
|
size={'sm'}
|
||||||
variant={'base'}
|
variant={'base'}
|
||||||
w={['60px', '70px']}
|
w={['60px', '70px']}
|
||||||
onClick={() => router.push(`/chat?modelId=${model._id}`)}
|
onClick={() => router.push(`/chat?appId=${model._id}`)}
|
||||||
>
|
>
|
||||||
体验
|
体验
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ const PcSliderBar = ({
|
|||||||
w={'100%'}
|
w={'100%'}
|
||||||
h={'100%'}
|
h={'100%'}
|
||||||
leftIcon={<AddIcon />}
|
leftIcon={<AddIcon />}
|
||||||
onClick={() => router.replace(`/chat?modelId=${modelId}`)}
|
onClick={() => router.replace(`/chat?appId=${modelId}`)}
|
||||||
>
|
>
|
||||||
新对话
|
新对话
|
||||||
</Button>
|
</Button>
|
||||||
@@ -176,9 +176,9 @@ const PcSliderBar = ({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (item._id === chatId) return;
|
if (item._id === chatId) return;
|
||||||
if (isPc) {
|
if (isPc) {
|
||||||
router.replace(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
|
router.replace(`/chat?appId=${item.modelId}&chatId=${item._id}`);
|
||||||
} else {
|
} else {
|
||||||
router.push(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
|
router.push(`/chat?appId=${item.modelId}&chatId=${item._id}`);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onContextMenu={(e) => onclickContextMenu(e, item)}
|
onContextMenu={(e) => onclickContextMenu(e, item)}
|
||||||
@@ -251,7 +251,7 @@ const PcSliderBar = ({
|
|||||||
try {
|
try {
|
||||||
await onclickDelHistory(contextMenuData.history._id);
|
await onclickDelHistory(contextMenuData.history._id);
|
||||||
if (contextMenuData.history._id === chatId) {
|
if (contextMenuData.history._id === chatId) {
|
||||||
router.replace(`/chat?modelId=${modelId}`);
|
router.replace(`/chat?appId=${modelId}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const ModelList = ({ models, modelId }: { models: AppListItemType[]; modelId: st
|
|||||||
}
|
}
|
||||||
: {})}
|
: {})}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.replace(`/chat?modelId=${item._id}`);
|
router.replace(`/chat?appId=${item._id}`);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Avatar src={item.avatar} w={'34px'} h={'34px'} />
|
<Avatar src={item.avatar} w={'34px'} h={'34px'} />
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ const PhoneSliderBar = ({
|
|||||||
color={'white'}
|
color={'white'}
|
||||||
leftIcon={<AddIcon />}
|
leftIcon={<AddIcon />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.replace(`/chat?modelId=${modelId}`);
|
router.replace(`/chat?appId=${modelId}`);
|
||||||
onClose();
|
onClose();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -128,7 +128,7 @@ const PhoneSliderBar = ({
|
|||||||
: {})}
|
: {})}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
if (item._id === modelId) return;
|
if (item._id === modelId) return;
|
||||||
router.replace(`/chat?modelId=${item._id}`);
|
router.replace(`/chat?appId=${item._id}`);
|
||||||
onClose();
|
onClose();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -159,7 +159,7 @@ const PhoneSliderBar = ({
|
|||||||
: {})}
|
: {})}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (item._id === chatId) return;
|
if (item._id === chatId) return;
|
||||||
router.replace(`/chat?modelId=${item.modelId}&chatId=${item._id}`);
|
router.replace(`/chat?appId=${item.modelId}&chatId=${item._id}`);
|
||||||
onClose();
|
onClose();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -177,7 +177,7 @@ const PhoneSliderBar = ({
|
|||||||
await delChatHistoryById(item._id);
|
await delChatHistoryById(item._id);
|
||||||
loadHistory({ pageNum: 1, init: true });
|
loadHistory({ pageNum: 1, init: true });
|
||||||
if (item._id === chatId) {
|
if (item._id === chatId) {
|
||||||
router.replace(`/chat?modelId=${modelId}`);
|
router.replace(`/chat?appId=${modelId}`);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ const textareaMinH = '22px';
|
|||||||
|
|
||||||
const Chat = () => {
|
const Chat = () => {
|
||||||
const router = useRouter();
|
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 theme = useTheme();
|
||||||
|
|
||||||
const ChatBox = useRef<HTMLDivElement>(null);
|
const ChatBox = useRef<HTMLDivElement>(null);
|
||||||
@@ -179,7 +179,7 @@ const Chat = () => {
|
|||||||
data: {
|
data: {
|
||||||
messages,
|
messages,
|
||||||
chatId,
|
chatId,
|
||||||
appId: modelId,
|
appId,
|
||||||
model: ''
|
model: ''
|
||||||
},
|
},
|
||||||
onMessage: (text: string) => {
|
onMessage: (text: string) => {
|
||||||
@@ -206,7 +206,7 @@ const Chat = () => {
|
|||||||
// save chat
|
// save chat
|
||||||
if (newChatId) {
|
if (newChatId) {
|
||||||
setForbidLoadChatData(true);
|
setForbidLoadChatData(true);
|
||||||
router.replace(`/chat?modelId=${modelId}&chatId=${newChatId}`);
|
router.replace(`/chat?appId=${appId}&chatId=${newChatId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
abortSignal.signal.aborted && (await delay(500));
|
abortSignal.signal.aborted && (await delay(500));
|
||||||
@@ -243,7 +243,7 @@ const Chat = () => {
|
|||||||
},
|
},
|
||||||
[
|
[
|
||||||
chatId,
|
chatId,
|
||||||
modelId,
|
appId,
|
||||||
setChatData,
|
setChatData,
|
||||||
generatingMessage,
|
generatingMessage,
|
||||||
setForbidLoadChatData,
|
setForbidLoadChatData,
|
||||||
@@ -474,17 +474,17 @@ const Chat = () => {
|
|||||||
// 获取对话信息
|
// 获取对话信息
|
||||||
const loadChatInfo = useCallback(
|
const loadChatInfo = useCallback(
|
||||||
async ({
|
async ({
|
||||||
modelId,
|
appId,
|
||||||
chatId,
|
chatId,
|
||||||
loading = false
|
loading = false
|
||||||
}: {
|
}: {
|
||||||
modelId: string;
|
appId: string;
|
||||||
chatId: string;
|
chatId: string;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
loading && setIsLoading(true);
|
loading && setIsLoading(true);
|
||||||
const res = await getInitChatSiteInfo(modelId, chatId);
|
const res = await getInitChatSiteInfo(appId, chatId);
|
||||||
|
|
||||||
setChatData({
|
setChatData({
|
||||||
...res,
|
...res,
|
||||||
@@ -502,9 +502,9 @@ const Chat = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 空 modelId 请求, 重定向到新的 model 聊天
|
// 空 modelId 请求, 重定向到新的 model 聊天
|
||||||
if (res.modelId !== modelId) {
|
if (res.modelId !== appId) {
|
||||||
setForbidLoadChatData(true);
|
setForbidLoadChatData(true);
|
||||||
router.replace(`/chat?modelId=${res.modelId}`);
|
router.replace(`/chat?appId=${res.modelId}`);
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
// reset all chat tore
|
// reset all chat tore
|
||||||
@@ -529,15 +529,15 @@ const Chat = () => {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
// 初始化聊天框
|
// 初始化聊天框
|
||||||
useQuery(['init', modelId, chatId], () => {
|
useQuery(['init', appId, chatId], () => {
|
||||||
// pc: redirect to latest model chat
|
// pc: redirect to latest model chat
|
||||||
if (!modelId && lastChatModelId) {
|
if (!appId && lastChatModelId) {
|
||||||
router.replace(`/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`);
|
router.replace(`/chat?appId=${lastChatModelId}&chatId=${lastChatId}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// store id
|
// store id
|
||||||
modelId && setLastChatModelId(modelId);
|
appId && setLastChatModelId(appId);
|
||||||
setLastChatId(chatId);
|
setLastChatId(chatId);
|
||||||
|
|
||||||
if (forbidLoadChatData) {
|
if (forbidLoadChatData) {
|
||||||
@@ -546,7 +546,7 @@ const Chat = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return loadChatInfo({
|
return loadChatInfo({
|
||||||
modelId,
|
appId,
|
||||||
chatId,
|
chatId,
|
||||||
loading: true
|
loading: true
|
||||||
});
|
});
|
||||||
@@ -559,7 +559,7 @@ const Chat = () => {
|
|||||||
isLeavePage.current = true;
|
isLeavePage.current = true;
|
||||||
controller.current?.abort();
|
controller.current?.abort();
|
||||||
};
|
};
|
||||||
}, [modelId, chatId]);
|
}, [appId, chatId]);
|
||||||
|
|
||||||
// context menu component
|
// context menu component
|
||||||
const RenderContextMenu = useCallback(
|
const RenderContextMenu = useCallback(
|
||||||
@@ -611,14 +611,14 @@ const Chat = () => {
|
|||||||
backgroundColor={useColorModeValue('#fdfdfd', '')}
|
backgroundColor={useColorModeValue('#fdfdfd', '')}
|
||||||
>
|
>
|
||||||
{/* pc always show history. */}
|
{/* pc always show history. */}
|
||||||
{(isPc || !modelId) && (
|
{(isPc || !appId) && (
|
||||||
<SideBar>
|
<SideBar>
|
||||||
<History onclickDelHistory={onclickDelHistory} onclickExportChat={onclickExportChat} />
|
<History onclickDelHistory={onclickDelHistory} onclickExportChat={onclickExportChat} />
|
||||||
</SideBar>
|
</SideBar>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* 聊天内容 */}
|
{/* 聊天内容 */}
|
||||||
{modelId && (
|
{appId && (
|
||||||
<Flex
|
<Flex
|
||||||
position={'relative'}
|
position={'relative'}
|
||||||
h={[0, '100%']}
|
h={[0, '100%']}
|
||||||
@@ -667,15 +667,13 @@ const Chat = () => {
|
|||||||
/>
|
/>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuList minW={`90px !important`}>
|
<MenuList minW={`90px !important`}>
|
||||||
<MenuItem onClick={() => router.replace(`/chat?modelId=${modelId}`)}>
|
<MenuItem onClick={() => router.replace(`/chat?appId=${appId}`)}>新对话</MenuItem>
|
||||||
新对话
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem
|
<MenuItem
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
await onclickDelHistory(chatData.chatId);
|
await onclickDelHistory(chatData.chatId);
|
||||||
router.replace(`/chat?modelId=${modelId}`);
|
router.replace(`/chat?appId=${appId}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
@@ -901,7 +899,7 @@ const Chat = () => {
|
|||||||
<Drawer isOpen={isOpenSlider} placement="left" size={'xs'} onClose={onCloseSlider}>
|
<Drawer isOpen={isOpenSlider} placement="left" size={'xs'} onClose={onCloseSlider}>
|
||||||
<DrawerOverlay backgroundColor={'rgba(255,255,255,0.5)'} />
|
<DrawerOverlay backgroundColor={'rgba(255,255,255,0.5)'} />
|
||||||
<DrawerContent maxW={'70%'}>
|
<DrawerContent maxW={'70%'}>
|
||||||
<PhoneSliderBar chatId={chatId} modelId={modelId} onClose={onCloseSlider} />
|
<PhoneSliderBar chatId={chatId} modelId={appId} onClose={onCloseSlider} />
|
||||||
</DrawerContent>
|
</DrawerContent>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user