Commit 4e0c8761 by archer

perf: chat ui

parent 3e5118c4
接受一个csv文件,表格头包含 question 和 answer。question 代表问题,answer 代表答案。 接受一个 csv 文件,表格头包含 question 和 answer。question 代表问题,answer 代表答案。
导入前会进行去重,如果问题和答案完全相同,则不会被导入,所以最终导入的内容可能会比文件的内容少。但是,对于带有换行的内容,目前无法去重。 导入前会进行去重,如果问题和答案完全相同,则不会被导入,所以最终导入的内容可能会比文件的内容少。但是,对于带有换行的内容,目前无法去重。
**请保证 csv 文件为 utf-8 编码**
| question | answer | | question | answer |
| --- | --- | | --- | --- |
| 什么是 laf | laf 是一个云函数开发平台…… | | 什么是 laf | laf 是一个云函数开发平台…… |
......
...@@ -27,7 +27,7 @@ export const postSaveChat = (data: { ...@@ -27,7 +27,7 @@ export const postSaveChat = (data: {
modelId: string; modelId: string;
newChatId: '' | string; newChatId: '' | string;
chatId: '' | string; chatId: '' | string;
prompts: ChatItemType[]; prompts: [ChatItemType, ChatItemType];
}) => POST<string>('/chat/saveChat', data); }) => POST<string>('/chat/saveChat', data);
/** /**
......
...@@ -17,12 +17,6 @@ const Navbar = () => { ...@@ -17,12 +17,6 @@ const Navbar = () => {
const navbarList = useMemo( const navbarList = useMemo(
() => [ () => [
{ {
label: 'AI助手',
icon: 'model',
link: `/model?modelId=${lastModelId}`,
activeLink: ['/model']
},
{
label: '聊天', label: '聊天',
icon: 'chat', icon: 'chat',
link: `/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`, link: `/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`,
...@@ -30,6 +24,12 @@ const Navbar = () => { ...@@ -30,6 +24,12 @@ const Navbar = () => {
}, },
{ {
label: 'AI助手',
icon: 'model',
link: `/model?modelId=${lastModelId}`,
activeLink: ['/model']
},
{
label: '共享', label: '共享',
icon: 'shareMarket', icon: 'shareMarket',
link: '/model/share', link: '/model/share',
......
...@@ -10,18 +10,18 @@ const NavbarPhone = () => { ...@@ -10,18 +10,18 @@ const NavbarPhone = () => {
const navbarList = useMemo( const navbarList = useMemo(
() => [ () => [
{ {
label: 'AI助手',
icon: 'tabbarModel',
link: `/model`,
activeLink: ['/model']
},
{
label: '聊天', label: '聊天',
icon: 'tabbarChat', icon: 'tabbarChat',
link: `/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`, link: `/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`,
activeLink: ['/chat'] activeLink: ['/chat']
}, },
{ {
label: 'AI助手',
icon: 'tabbarModel',
link: `/model`,
activeLink: ['/model']
},
{
label: '发现', label: '发现',
icon: 'tabbarMore', icon: 'tabbarMore',
link: '/tools', link: '/tools',
......
...@@ -13,7 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -13,7 +13,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
newChatId: '' | string; newChatId: '' | string;
chatId: '' | string; chatId: '' | string;
modelId: string; modelId: string;
prompts: ChatItemType[]; prompts: [ChatItemType, ChatItemType];
}; };
if (!prompts) { if (!prompts) {
...@@ -41,7 +41,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -41,7 +41,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
modelId, modelId,
content, content,
title: content[0].value.slice(0, 20), title: content[0].value.slice(0, 20),
latestChat: content[content.length - 1].value latestChat: content[1].value
}); });
return jsonRes(res, { return jsonRes(res, {
data: _id data: _id
...@@ -54,8 +54,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -54,8 +54,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
$each: content $each: content
} }
}, },
updateTime: new Date(), title: content[0].value.slice(0, 20),
latestChat: content[content.length - 1].value latestChat: content[1].value,
updateTime: new Date()
}); });
} }
jsonRes(res); jsonRes(res);
......
...@@ -172,7 +172,7 @@ const PhoneSliderBar = ({ ...@@ -172,7 +172,7 @@ const PhoneSliderBar = ({
<Divider my={3} colorScheme={useColorModeValue('gray', 'white')} /> <Divider my={3} colorScheme={useColorModeValue('gray', 'white')} />
<RenderButton onClick={() => router.push('/')}> <RenderButton onClick={() => router.push('/model')}>
<> <>
<MyIcon name="out" fill={'white'} w={'18px'} h={'18px'} mr={4} /> <MyIcon name="out" fill={'white'} w={'18px'} h={'18px'} mr={4} />
退出聊天 退出聊天
......
...@@ -145,7 +145,7 @@ const ModelEditForm = ({ ...@@ -145,7 +145,7 @@ const ModelEditForm = ({
</Flex> </Flex>
{isOwner && ( {isOwner && (
<Flex mt={5} alignItems={'center'}> <Flex mt={5} alignItems={'center'}>
<Box flex={'0 0 150px'}>删除AI和知识库</Box> <Box flex={'0 0 120px'}>删除AI和知识库</Box>
<Button <Button
colorScheme={'gray'} colorScheme={'gray'}
variant={'outline'} variant={'outline'}
......
...@@ -17,7 +17,7 @@ const modelList = () => { ...@@ -17,7 +17,7 @@ const modelList = () => {
/* 加载模型 */ /* 加载模型 */
const { data, isLoading, Pagination, getData, pageNum } = usePagination<ShareModelItem>({ const { data, isLoading, Pagination, getData, pageNum } = usePagination<ShareModelItem>({
api: getShareModelList, api: getShareModelList,
pageSize: 20, pageSize: 24,
params: { params: {
searchText searchText
} }
......
...@@ -88,3 +88,28 @@ export const formatTimeToChatTime = (time: Date) => { ...@@ -88,3 +88,28 @@ export const formatTimeToChatTime = (time: Date) => {
// 如果是更久之前,展示某年某月某日 // 如果是更久之前,展示某年某月某日
return target.format('YYYY/M/D'); return target.format('YYYY/M/D');
}; };
/**
* voice broadcast
*/
export const voiceBroadcast = ({ text }: { text: string }) => {
window.speechSynthesis?.cancel();
const msg = new SpeechSynthesisUtterance(text);
const voices = window.speechSynthesis?.getVoices?.(); // 获取语言包
const voice = voices.find((item) => {
return item.name === 'Microsoft Yaoyao - Chinese (Simplified, PRC)';
});
if (voice) {
msg.voice = voice;
}
window.speechSynthesis?.speak(msg);
msg.onerror = (e) => {
console.log(e);
};
return {
cancel: () => window.speechSynthesis?.cancel()
};
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment