From 8e9816d648c10fe04fa42f94c7d55c034ca30d4a Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Tue, 4 Jul 2023 23:00:24 +0800 Subject: [PATCH] app page --- client/src/components/Layout/navbar.tsx | 2 +- client/src/components/SlideTabs/index.tsx | 72 ++++++++++ client/src/constants/theme.ts | 3 +- client/src/pages/api/app/create.ts | 2 +- client/src/pages/api/app/update.ts | 2 +- .../pages/app/detail/components/Settings.tsx | 128 +----------------- client/src/pages/app/detail/index.tsx | 123 ++++++++++------- 7 files changed, 158 insertions(+), 174 deletions(-) create mode 100644 client/src/components/SlideTabs/index.tsx diff --git a/client/src/components/Layout/navbar.tsx b/client/src/components/Layout/navbar.tsx index 7d22e736f..45b335e75 100644 --- a/client/src/components/Layout/navbar.tsx +++ b/client/src/components/Layout/navbar.tsx @@ -30,7 +30,7 @@ const Navbar = ({ unread }: { unread: number }) => { label: '应用', icon: 'model', link: `/app/list`, - activeLink: ['/app/list'] + activeLink: ['/app/list', '/app/detail'] }, { label: '知识库', diff --git a/client/src/components/SlideTabs/index.tsx b/client/src/components/SlideTabs/index.tsx new file mode 100644 index 000000000..21a36cdcc --- /dev/null +++ b/client/src/components/SlideTabs/index.tsx @@ -0,0 +1,72 @@ +import React, { useMemo } from 'react'; +import { Box, Flex, useTheme } from '@chakra-ui/react'; +import type { GridProps } from '@chakra-ui/react'; +import MyIcon, { type IconName } from '../Icon'; + +// @ts-ignore +export interface Props extends GridProps { + list: { id: string; label: string; icon: string }[]; + activeId: string; + size?: 'sm' | 'md' | 'lg'; + onChange: (id: string) => void; +} + +const SlideTabs = ({ list, size = 'md', activeId, onChange, ...props }: Props) => { + const sizeMap = useMemo(() => { + switch (size) { + case 'sm': + return { + fontSize: 'sm', + inlineP: 1 + }; + case 'md': + return { + fontSize: 'md', + inlineP: 2 + }; + case 'lg': + return { + fontSize: 'lg', + inlineP: 3 + }; + } + }, [size]); + + return ( + + {list.map((item) => ( + { + if (activeId === item.id) return; + onChange(item.id); + }} + > + + {item.label} + + ))} + + ); +}; + +export default React.memo(SlideTabs); diff --git a/client/src/constants/theme.ts b/client/src/constants/theme.ts index 0fa847498..f98ae0026 100644 --- a/client/src/constants/theme.ts +++ b/client/src/constants/theme.ts @@ -274,7 +274,8 @@ export const theme = extendTheme({ borders: { sm: '1px solid #EFF0F1', base: '1px solid #DEE0E2', - md: '1px solid #DAE0E2' + md: '1px solid #DAE0E2', + lg: '1px solid #D0E0E2' }, breakpoints: { sm: '900px', diff --git a/client/src/pages/api/app/create.ts b/client/src/pages/api/app/create.ts index 76084bd0e..8a184f73c 100644 --- a/client/src/pages/api/app/create.ts +++ b/client/src/pages/api/app/create.ts @@ -3,7 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; import { connectToDatabase } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; -import { App } from '@/service/models/model'; +import { App } from '@/service/models/app'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { diff --git a/client/src/pages/api/app/update.ts b/client/src/pages/api/app/update.ts index a537e58bb..b70842a41 100644 --- a/client/src/pages/api/app/update.ts +++ b/client/src/pages/api/app/update.ts @@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; import { connectToDatabase } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; -import { App } from '@/service/models/model'; +import { App } from '@/service/models/app'; import type { AppUpdateParams } from '@/types/app'; import { authApp } from '@/service/utils/auth'; diff --git a/client/src/pages/app/detail/components/Settings.tsx b/client/src/pages/app/detail/components/Settings.tsx index c5da9988a..b7b903c99 100644 --- a/client/src/pages/app/detail/components/Settings.tsx +++ b/client/src/pages/app/detail/components/Settings.tsx @@ -1,15 +1,5 @@ import React, { useCallback, useState, useMemo } from 'react'; -import { - Box, - Flex, - Button, - FormControl, - Input, - Textarea, - Divider, - Tooltip -} from '@chakra-ui/react'; -import { QuestionOutlineIcon } from '@chakra-ui/icons'; +import { Box, Flex, Button, FormControl, Input, Textarea, Divider } from '@chakra-ui/react'; import { useQuery } from '@tanstack/react-query'; import { useForm } from 'react-hook-form'; import { useRouter } from 'next/router'; @@ -21,19 +11,10 @@ import { useSelectFile } from '@/hooks/useSelectFile'; import { compressImg } from '@/utils/file'; import { getErrText } from '@/utils/tools'; import { useConfirm } from '@/hooks/useConfirm'; -import { ChatModelMap, getChatModelList } from '@/constants/model'; -import { formatPrice } from '@/utils/user'; import type { AppSchema } from '@/types/mongoSchema'; import Avatar from '@/components/Avatar'; -import MySelect from '@/components/Select'; -import MySlider from '@/components/Slider'; - -const systemPromptTip = - '模型固定的引导词,通过调整该内容,可以引导模型聊天方向。该内容会被固定在上下文的开头。'; -const limitPromptTip = - '限定模型对话范围,会被放置在本次提问前,拥有强引导和限定性。例如:\n1. 知识库是关于 Laf 的介绍,参考知识库回答问题,与 "Laf" 无关内容,直接回复: "我不知道"。\n2. 你仅回答关于 "xxx" 的问题,其他问题回复: "xxxx"'; const Settings = ({ modelId }: { modelId: string }) => { const { toast } = useToast(); @@ -67,15 +48,6 @@ const Settings = ({ modelId }: { modelId: string }) => { () => appDetail.userId === userInfo?._id, [appDetail.userId, userInfo?._id] ); - const tokenLimit = useMemo(() => { - const max = ChatModelMap[getValues('chat.chatModel')]?.contextMaxToken || 4000; - - if (max < getValues('chat.maxToken')) { - setValue('chat.maxToken', max); - } - - return max; - }, [getValues, setValue, refresh]); // 提交保存模型修改 const saveSubmitSuccess = useCallback( @@ -185,17 +157,17 @@ const Settings = ({ modelId }: { modelId: string }) => { } }); - const { data: chatModelList = [] } = useQuery(['initChatModelList'], getChatModelList); - return ( - + 基本信息 + 头像 @@ -235,96 +207,6 @@ const Settings = ({ modelId }: { modelId: string }) => { - - - 对话模型 - - ({ - value: item.chatModel, - label: `${item.name} (${formatPrice( - ChatModelMap[item.chatModel]?.price, - 1000 - )} 元/1k tokens)` - }))} - onchange={(val: any) => { - setValue('chat.chatModel', val); - setRefresh(!refresh); - }} - /> - - - - 温度 - - - { - setValue('chat.temperature', val); - setRefresh(!refresh); - }} - /> - - - - - 回复上限 - - - { - setValue('chat.maxToken', val); - setRefresh(!refresh); - }} - /> - - - - - 提示词 - - - - - - - - - 限定词 - - - - - - -