Skip to content

Commit

Permalink
v4.2.2 (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Sep 18, 2023
1 parent 0bb31b9 commit b8ea546
Show file tree
Hide file tree
Showing 25 changed files with 288 additions and 225 deletions.
3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"crypto": "^1.0.1",
"date-fns": "^2.30.0",
"dayjs": "^1.11.7",
"downloadjs": "^1.4.7",
"echarts": "^5.4.1",
"echarts-gl": "^2.0.9",
"formidable": "^2.1.1",
Expand All @@ -48,6 +49,7 @@
"openai": "^3.3.0",
"papaparse": "^5.4.1",
"pg": "^8.10.0",
"pg-query-stream": "^4.5.3",
"react": "18.2.0",
"react-day-picker": "^8.7.1",
"react-dom": "18.2.0",
Expand All @@ -71,6 +73,7 @@
"devDependencies": {
"@svgr/webpack": "^6.5.1",
"@types/cookie": "^0.5.1",
"@types/downloadjs": "^1.4.3",
"@types/formidable": "^2.0.5",
"@types/js-cookie": "^3.0.3",
"@types/jsdom": "^21.1.1",
Expand Down
101 changes: 56 additions & 45 deletions client/pnpm-lock.yaml

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions client/src/api/plugins/kb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { Props as UpdateDataProps } from '@/pages/api/openapi/kb/updateData';
import type { KbUpdateParams, CreateKbParams, GetKbDataListProps } from '../request/kb';
import { QuoteItemType } from '@/types/chat';
import { KbTypeEnum } from '@/constants/kb';
import { getToken } from '@/utils/user';
import download from 'downloadjs';

/* knowledge base */
export const getKbList = (data: { parentId?: string; type?: `${KbTypeEnum}` }) =>
Expand All @@ -35,12 +37,23 @@ export const getKbDataList = (data: GetKbDataListProps) =>
POST(`/plugins/kb/data/getDataList`, data);

/**
* 获取导出数据(不分页)
* export and download data
*/
export const getExportDataList = (data: { kbId: string }) =>
GET<[string, string, string][]>(`/plugins/kb/data/exportModelData`, data, {
timeout: 600000
});
export const exportDataset = (data: { kbId: string }) =>
fetch(`/api/plugins/kb/data/exportAll?kbId=${data.kbId}`, {
method: 'GET',
headers: {
token: getToken()
}
})
.then(async (res) => {
if (!res.ok) {
const data = await res.json();
throw new Error(data?.message || 'Export failed');
}
return res.blob();
})
.then((blob) => download(blob, 'dataset.csv', 'text/csv'));

/**
* 获取模型正在拆分数据的数量
Expand Down
165 changes: 75 additions & 90 deletions client/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -452,29 +452,22 @@ const ChatBox = (
border: theme.borders.base,
mr: 3
};
const controlContainerStyle = useCallback((status: ChatSiteItemType['status']) => {
return {
className: 'control',
color: 'myGray.400',
display:
status === 'finish'
? feedbackType === FeedbackTypeEnum.admin
? 'flex'
: ['flex', 'none']
: 'none',
pl: 1,
mt: 2
};
}, []);
const controlContainerStyle = {
className: 'control',
color: 'myGray.400',
display: 'flex',
pl: 1,
mt: 2
};
const MessageCardStyle: BoxProps = {
px: 4,
py: 3,
borderRadius: '0 8px 8px 8px',
boxShadow: '0 0 8px rgba(0,0,0,0.15)'
boxShadow: '0 0 8px rgba(0,0,0,0.15)',
display: 'inline-block',
maxW: ['calc(100% - 25px)', 'calc(100% - 40px)']
};

const messageCardMaxW = ['calc(100% - 25px)', 'calc(100% - 40px)'];

const showEmpty = useMemo(
() =>
feConfigs?.show_emptyChat &&
Expand Down Expand Up @@ -542,84 +535,80 @@ const ChatBox = (
{showEmpty && <Empty />}

{!!welcomeText && (
<Flex flexDirection={'column'} alignItems={'flex-start'} py={2}>
<Box py={3}>
{/* avatar */}
<ChatAvatar src={appAvatar} type={'AI'} />
{/* message */}
<Card order={2} mt={2} {...MessageCardStyle} bg={'white'} maxW={messageCardMaxW}>
<Markdown source={`~~~guide \n${welcomeText}`} isChatting={false} />
</Card>
</Flex>
<Box textAlign={'left'}>
<Card order={2} mt={2} {...MessageCardStyle} bg={'white'}>
<Markdown source={`~~~guide \n${welcomeText}`} isChatting={false} />
</Card>
</Box>
</Box>
)}
{/* variable input */}
{!!variableModules?.length && (
<Flex flexDirection={'column'} alignItems={'flex-start'} py={2}>
<Box py={3}>
{/* avatar */}
<ChatAvatar src={appAvatar} type={'AI'} />
{/* message */}
<Card
order={2}
mt={2}
bg={'white'}
w={'400px'}
maxW={messageCardMaxW}
{...MessageCardStyle}
>
{variableModules.map((item) => (
<Box key={item.id} mb={4}>
<VariableLabel required={item.required}>{item.label}</VariableLabel>
{item.type === VariableInputEnum.input && (
<Input
isDisabled={variableIsFinish}
{...register(item.key, {
required: item.required
})}
/>
)}
{item.type === VariableInputEnum.select && (
<MySelect
width={'100%'}
isDisabled={variableIsFinish}
list={(item.enums || []).map((item) => ({
label: item.value,
value: item.value
}))}
{...register(item.key, {
required: item.required
})}
value={getValues(item.key)}
onchange={(e) => {
setValue(item.key, e);
setRefresh(!refresh);
}}
/>
)}
</Box>
))}
{!variableIsFinish && (
<Button
leftIcon={<MyIcon name={'chatFill'} w={'16px'} />}
size={'sm'}
maxW={'100px'}
borderRadius={'lg'}
onClick={handleSubmit((data) => {
onUpdateVariable?.(data);
setVariables(data);
setVariableInputFinish(true);
})}
>
{'开始对话'}
</Button>
)}
</Card>
</Flex>
<Box textAlign={'left'}>
<Card order={2} mt={2} bg={'white'} w={'400px'} {...MessageCardStyle}>
{variableModules.map((item) => (
<Box key={item.id} mb={4}>
<VariableLabel required={item.required}>{item.label}</VariableLabel>
{item.type === VariableInputEnum.input && (
<Input
isDisabled={variableIsFinish}
{...register(item.key, {
required: item.required
})}
/>
)}
{item.type === VariableInputEnum.select && (
<MySelect
width={'100%'}
isDisabled={variableIsFinish}
list={(item.enums || []).map((item) => ({
label: item.value,
value: item.value
}))}
{...register(item.key, {
required: item.required
})}
value={getValues(item.key)}
onchange={(e) => {
setValue(item.key, e);
setRefresh(!refresh);
}}
/>
)}
</Box>
))}
{!variableIsFinish && (
<Button
leftIcon={<MyIcon name={'chatFill'} w={'16px'} />}
size={'sm'}
maxW={'100px'}
borderRadius={'lg'}
onClick={handleSubmit((data) => {
onUpdateVariable?.(data);
setVariables(data);
setVariableInputFinish(true);
})}
>
{'开始对话'}
</Button>
)}
</Card>
</Box>
</Box>
)}

{/* chat history */}
<Box id={'history'}>
{chatHistory.map((item, index) => (
<Flex
position={'relative'}
<Box
key={item.dataId}
flexDirection={'column'}
alignItems={item.obj === 'Human' ? 'flex-end' : 'flex-start'}
Expand All @@ -633,11 +622,7 @@ const ChatBox = (
{item.obj === 'Human' && (
<>
<Flex w={'100%'} alignItems={'center'} justifyContent={'flex-end'}>
<Flex
{...controlContainerStyle(item.status)}
justifyContent={'flex-end'}
mr={3}
>
<Flex {...controlContainerStyle} justifyContent={'flex-end'} mr={3}>
<MyTooltip label={t('common.Copy')}>
<MyIcon
{...controlIconStyle}
Expand Down Expand Up @@ -678,7 +663,7 @@ const ChatBox = (
</Flex>
<ChatAvatar src={userAvatar} type={'Human'} />
</Flex>
<Box position={'relative'} maxW={messageCardMaxW} mt={['6px', 2]}>
<Box mt={['6px', 2]} textAlign={'right'}>
<Card
className="markdown"
whiteSpace={'pre-wrap'}
Expand All @@ -695,7 +680,7 @@ const ChatBox = (
<>
<Flex w={'100%'} alignItems={'flex-end'}>
<ChatAvatar src={appAvatar} type={'AI'} />
<Flex {...controlContainerStyle(item.status)} ml={3}>
<Flex {...controlContainerStyle} ml={3}>
<MyTooltip label={'复制'}>
<MyIcon
{...controlIconStyle}
Expand Down Expand Up @@ -841,7 +826,7 @@ const ChatBox = (
</Flex>
)}
</Flex>
<Box position={'relative'} maxW={messageCardMaxW} mt={['6px', 2]}>
<Box textAlign={'left'} mt={['6px', 2]}>
<Card bg={'white'} {...MessageCardStyle}>
<Markdown
source={item.value}
Expand Down Expand Up @@ -869,7 +854,7 @@ const ChatBox = (
</Box>
</>
)}
</Flex>
</Box>
))}
</Box>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion client/src/constants/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export enum PageTypeEnum {
}

export const BillSourceMap: Record<`${BillSourceEnum}`, string> = {
[BillSourceEnum.fastgpt]: 'FastGPT 平台',
[BillSourceEnum.fastgpt]: '在线使用',
[BillSourceEnum.api]: 'Api',
[BillSourceEnum.shareLink]: '免登录链接'
};
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/account/components/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const UserInfo = () => {
</Flex>
</>
)}
{feConfigs?.show_userDetail && (
{feConfigs?.show_openai_account && (
<>
<Divider my={3} />

Expand Down
15 changes: 10 additions & 5 deletions client/src/pages/account/components/PayModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { useQuery } from '@tanstack/react-query';
import { useRouter } from 'next/router';
import { getErrText } from '@/utils/tools';
import { useTranslation } from 'react-i18next';
import { formatPrice } from '@/utils/user';
import Markdown from '@/components/Markdown';
import MyModal from '@/components/MyModal';
import { vectorModelList, chatModelList, qaModel } from '@/store/static';

const PayModal = ({ onClose }: { onClose: () => void }) => {
const router = useRouter();
Expand Down Expand Up @@ -69,6 +71,7 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
onClose();
}}
title={t('user.Pay')}
isCentered
showCloseBtn={!payId}
>
<ModalBody py={0}>
Expand Down Expand Up @@ -100,11 +103,13 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
source={`
| 计费项 | 价格: 元/ 1K tokens(包含上下文)|
| --- | --- |
| 知识库 - 索引 | 0.002 |
| FastAI4k - 对话 | 0.015 |
| FastAI16k - 对话 | 0.03 |
| FastAI-Plus - 对话 | 0.45 |
| 文件QA拆分 | 0.03 |`}
${vectorModelList
.map((item) => `| 索引-${item.name} | ${formatPrice(item.price, 1000)} |`)
.join('\n')}
${chatModelList
.map((item) => `| 对话-${item.name} | ${formatPrice(item.price, 1000)} |`)
.join('\n')}
| 文件QA拆分 | ${formatPrice(qaModel.price, 1000)} |`}
/>
</>
)}
Expand Down
8 changes: 4 additions & 4 deletions client/src/pages/account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum TabEnum {

const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
const { t } = useTranslation();
const tabList = useRef([
const tabList = [
{
icon: 'meLight',
label: t('user.Personal Information'),
Expand Down Expand Up @@ -67,7 +67,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
label: t('user.Sign Out'),
id: TabEnum.loginout
}
]);
];

const { openConfirm, ConfirmModal } = useConfirm({
content: '确认退出登录?'
Expand Down Expand Up @@ -115,7 +115,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
mx={'auto'}
mt={2}
w={'100%'}
list={tabList.current}
list={tabList}
activeId={currentTab}
onChange={setCurrentTab}
/>
Expand All @@ -125,7 +125,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
<Tabs
m={'auto'}
size={isPc ? 'md' : 'sm'}
list={tabList.current.map((item) => ({
list={tabList.map((item) => ({
id: item.id,
label: item.label
}))}
Expand Down
Loading

0 comments on commit b8ea546

Please sign in to comment.