Skip to content

Commit b8ea546

Browse files
authored
v4.2.2 (labring#312)
1 parent 0bb31b9 commit b8ea546

File tree

25 files changed

+288
-225
lines changed

25 files changed

+288
-225
lines changed

client/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"crypto": "^1.0.1",
2424
"date-fns": "^2.30.0",
2525
"dayjs": "^1.11.7",
26+
"downloadjs": "^1.4.7",
2627
"echarts": "^5.4.1",
2728
"echarts-gl": "^2.0.9",
2829
"formidable": "^2.1.1",
@@ -48,6 +49,7 @@
4849
"openai": "^3.3.0",
4950
"papaparse": "^5.4.1",
5051
"pg": "^8.10.0",
52+
"pg-query-stream": "^4.5.3",
5153
"react": "18.2.0",
5254
"react-day-picker": "^8.7.1",
5355
"react-dom": "18.2.0",
@@ -71,6 +73,7 @@
7173
"devDependencies": {
7274
"@svgr/webpack": "^6.5.1",
7375
"@types/cookie": "^0.5.1",
76+
"@types/downloadjs": "^1.4.3",
7477
"@types/formidable": "^2.0.5",
7578
"@types/js-cookie": "^3.0.3",
7679
"@types/jsdom": "^21.1.1",

client/pnpm-lock.yaml

Lines changed: 56 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/api/plugins/kb.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { Props as UpdateDataProps } from '@/pages/api/openapi/kb/updateData';
1313
import type { KbUpdateParams, CreateKbParams, GetKbDataListProps } from '../request/kb';
1414
import { QuoteItemType } from '@/types/chat';
1515
import { KbTypeEnum } from '@/constants/kb';
16+
import { getToken } from '@/utils/user';
17+
import download from 'downloadjs';
1618

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

3739
/**
38-
* 获取导出数据(不分页)
40+
* export and download data
3941
*/
40-
export const getExportDataList = (data: { kbId: string }) =>
41-
GET<[string, string, string][]>(`/plugins/kb/data/exportModelData`, data, {
42-
timeout: 600000
43-
});
42+
export const exportDataset = (data: { kbId: string }) =>
43+
fetch(`/api/plugins/kb/data/exportAll?kbId=${data.kbId}`, {
44+
method: 'GET',
45+
headers: {
46+
token: getToken()
47+
}
48+
})
49+
.then(async (res) => {
50+
if (!res.ok) {
51+
const data = await res.json();
52+
throw new Error(data?.message || 'Export failed');
53+
}
54+
return res.blob();
55+
})
56+
.then((blob) => download(blob, 'dataset.csv', 'text/csv'));
4457

4558
/**
4659
* 获取模型正在拆分数据的数量

client/src/components/ChatBox/index.tsx

Lines changed: 75 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -452,29 +452,22 @@ const ChatBox = (
452452
border: theme.borders.base,
453453
mr: 3
454454
};
455-
const controlContainerStyle = useCallback((status: ChatSiteItemType['status']) => {
456-
return {
457-
className: 'control',
458-
color: 'myGray.400',
459-
display:
460-
status === 'finish'
461-
? feedbackType === FeedbackTypeEnum.admin
462-
? 'flex'
463-
: ['flex', 'none']
464-
: 'none',
465-
pl: 1,
466-
mt: 2
467-
};
468-
}, []);
455+
const controlContainerStyle = {
456+
className: 'control',
457+
color: 'myGray.400',
458+
display: 'flex',
459+
pl: 1,
460+
mt: 2
461+
};
469462
const MessageCardStyle: BoxProps = {
470463
px: 4,
471464
py: 3,
472465
borderRadius: '0 8px 8px 8px',
473-
boxShadow: '0 0 8px rgba(0,0,0,0.15)'
466+
boxShadow: '0 0 8px rgba(0,0,0,0.15)',
467+
display: 'inline-block',
468+
maxW: ['calc(100% - 25px)', 'calc(100% - 40px)']
474469
};
475470

476-
const messageCardMaxW = ['calc(100% - 25px)', 'calc(100% - 40px)'];
477-
478471
const showEmpty = useMemo(
479472
() =>
480473
feConfigs?.show_emptyChat &&
@@ -542,84 +535,80 @@ const ChatBox = (
542535
{showEmpty && <Empty />}
543536

544537
{!!welcomeText && (
545-
<Flex flexDirection={'column'} alignItems={'flex-start'} py={2}>
538+
<Box py={3}>
546539
{/* avatar */}
547540
<ChatAvatar src={appAvatar} type={'AI'} />
548541
{/* message */}
549-
<Card order={2} mt={2} {...MessageCardStyle} bg={'white'} maxW={messageCardMaxW}>
550-
<Markdown source={`~~~guide \n${welcomeText}`} isChatting={false} />
551-
</Card>
552-
</Flex>
542+
<Box textAlign={'left'}>
543+
<Card order={2} mt={2} {...MessageCardStyle} bg={'white'}>
544+
<Markdown source={`~~~guide \n${welcomeText}`} isChatting={false} />
545+
</Card>
546+
</Box>
547+
</Box>
553548
)}
554549
{/* variable input */}
555550
{!!variableModules?.length && (
556-
<Flex flexDirection={'column'} alignItems={'flex-start'} py={2}>
551+
<Box py={3}>
557552
{/* avatar */}
558553
<ChatAvatar src={appAvatar} type={'AI'} />
559554
{/* message */}
560-
<Card
561-
order={2}
562-
mt={2}
563-
bg={'white'}
564-
w={'400px'}
565-
maxW={messageCardMaxW}
566-
{...MessageCardStyle}
567-
>
568-
{variableModules.map((item) => (
569-
<Box key={item.id} mb={4}>
570-
<VariableLabel required={item.required}>{item.label}</VariableLabel>
571-
{item.type === VariableInputEnum.input && (
572-
<Input
573-
isDisabled={variableIsFinish}
574-
{...register(item.key, {
575-
required: item.required
576-
})}
577-
/>
578-
)}
579-
{item.type === VariableInputEnum.select && (
580-
<MySelect
581-
width={'100%'}
582-
isDisabled={variableIsFinish}
583-
list={(item.enums || []).map((item) => ({
584-
label: item.value,
585-
value: item.value
586-
}))}
587-
{...register(item.key, {
588-
required: item.required
589-
})}
590-
value={getValues(item.key)}
591-
onchange={(e) => {
592-
setValue(item.key, e);
593-
setRefresh(!refresh);
594-
}}
595-
/>
596-
)}
597-
</Box>
598-
))}
599-
{!variableIsFinish && (
600-
<Button
601-
leftIcon={<MyIcon name={'chatFill'} w={'16px'} />}
602-
size={'sm'}
603-
maxW={'100px'}
604-
borderRadius={'lg'}
605-
onClick={handleSubmit((data) => {
606-
onUpdateVariable?.(data);
607-
setVariables(data);
608-
setVariableInputFinish(true);
609-
})}
610-
>
611-
{'开始对话'}
612-
</Button>
613-
)}
614-
</Card>
615-
</Flex>
555+
<Box textAlign={'left'}>
556+
<Card order={2} mt={2} bg={'white'} w={'400px'} {...MessageCardStyle}>
557+
{variableModules.map((item) => (
558+
<Box key={item.id} mb={4}>
559+
<VariableLabel required={item.required}>{item.label}</VariableLabel>
560+
{item.type === VariableInputEnum.input && (
561+
<Input
562+
isDisabled={variableIsFinish}
563+
{...register(item.key, {
564+
required: item.required
565+
})}
566+
/>
567+
)}
568+
{item.type === VariableInputEnum.select && (
569+
<MySelect
570+
width={'100%'}
571+
isDisabled={variableIsFinish}
572+
list={(item.enums || []).map((item) => ({
573+
label: item.value,
574+
value: item.value
575+
}))}
576+
{...register(item.key, {
577+
required: item.required
578+
})}
579+
value={getValues(item.key)}
580+
onchange={(e) => {
581+
setValue(item.key, e);
582+
setRefresh(!refresh);
583+
}}
584+
/>
585+
)}
586+
</Box>
587+
))}
588+
{!variableIsFinish && (
589+
<Button
590+
leftIcon={<MyIcon name={'chatFill'} w={'16px'} />}
591+
size={'sm'}
592+
maxW={'100px'}
593+
borderRadius={'lg'}
594+
onClick={handleSubmit((data) => {
595+
onUpdateVariable?.(data);
596+
setVariables(data);
597+
setVariableInputFinish(true);
598+
})}
599+
>
600+
{'开始对话'}
601+
</Button>
602+
)}
603+
</Card>
604+
</Box>
605+
</Box>
616606
)}
617607

618608
{/* chat history */}
619609
<Box id={'history'}>
620610
{chatHistory.map((item, index) => (
621-
<Flex
622-
position={'relative'}
611+
<Box
623612
key={item.dataId}
624613
flexDirection={'column'}
625614
alignItems={item.obj === 'Human' ? 'flex-end' : 'flex-start'}
@@ -633,11 +622,7 @@ const ChatBox = (
633622
{item.obj === 'Human' && (
634623
<>
635624
<Flex w={'100%'} alignItems={'center'} justifyContent={'flex-end'}>
636-
<Flex
637-
{...controlContainerStyle(item.status)}
638-
justifyContent={'flex-end'}
639-
mr={3}
640-
>
625+
<Flex {...controlContainerStyle} justifyContent={'flex-end'} mr={3}>
641626
<MyTooltip label={t('common.Copy')}>
642627
<MyIcon
643628
{...controlIconStyle}
@@ -678,7 +663,7 @@ const ChatBox = (
678663
</Flex>
679664
<ChatAvatar src={userAvatar} type={'Human'} />
680665
</Flex>
681-
<Box position={'relative'} maxW={messageCardMaxW} mt={['6px', 2]}>
666+
<Box mt={['6px', 2]} textAlign={'right'}>
682667
<Card
683668
className="markdown"
684669
whiteSpace={'pre-wrap'}
@@ -695,7 +680,7 @@ const ChatBox = (
695680
<>
696681
<Flex w={'100%'} alignItems={'flex-end'}>
697682
<ChatAvatar src={appAvatar} type={'AI'} />
698-
<Flex {...controlContainerStyle(item.status)} ml={3}>
683+
<Flex {...controlContainerStyle} ml={3}>
699684
<MyTooltip label={'复制'}>
700685
<MyIcon
701686
{...controlIconStyle}
@@ -841,7 +826,7 @@ const ChatBox = (
841826
</Flex>
842827
)}
843828
</Flex>
844-
<Box position={'relative'} maxW={messageCardMaxW} mt={['6px', 2]}>
829+
<Box textAlign={'left'} mt={['6px', 2]}>
845830
<Card bg={'white'} {...MessageCardStyle}>
846831
<Markdown
847832
source={item.value}
@@ -869,7 +854,7 @@ const ChatBox = (
869854
</Box>
870855
</>
871856
)}
872-
</Flex>
857+
</Box>
873858
))}
874859
</Box>
875860
</Box>

client/src/constants/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export enum PageTypeEnum {
1414
}
1515

1616
export const BillSourceMap: Record<`${BillSourceEnum}`, string> = {
17-
[BillSourceEnum.fastgpt]: 'FastGPT 平台',
17+
[BillSourceEnum.fastgpt]: '在线使用',
1818
[BillSourceEnum.api]: 'Api',
1919
[BillSourceEnum.shareLink]: '免登录链接'
2020
};

client/src/pages/account/components/Info.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const UserInfo = () => {
251251
</Flex>
252252
</>
253253
)}
254-
{feConfigs?.show_userDetail && (
254+
{feConfigs?.show_openai_account && (
255255
<>
256256
<Divider my={3} />
257257

client/src/pages/account/components/PayModal.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { useQuery } from '@tanstack/react-query';
66
import { useRouter } from 'next/router';
77
import { getErrText } from '@/utils/tools';
88
import { useTranslation } from 'react-i18next';
9+
import { formatPrice } from '@/utils/user';
910
import Markdown from '@/components/Markdown';
1011
import MyModal from '@/components/MyModal';
12+
import { vectorModelList, chatModelList, qaModel } from '@/store/static';
1113

1214
const PayModal = ({ onClose }: { onClose: () => void }) => {
1315
const router = useRouter();
@@ -69,6 +71,7 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
6971
onClose();
7072
}}
7173
title={t('user.Pay')}
74+
isCentered
7275
showCloseBtn={!payId}
7376
>
7477
<ModalBody py={0}>
@@ -100,11 +103,13 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
100103
source={`
101104
| 计费项 | 价格: 元/ 1K tokens(包含上下文)|
102105
| --- | --- |
103-
| 知识库 - 索引 | 0.002 |
104-
| FastAI4k - 对话 | 0.015 |
105-
| FastAI16k - 对话 | 0.03 |
106-
| FastAI-Plus - 对话 | 0.45 |
107-
| 文件QA拆分 | 0.03 |`}
106+
${vectorModelList
107+
.map((item) => `| 索引-${item.name} | ${formatPrice(item.price, 1000)} |`)
108+
.join('\n')}
109+
${chatModelList
110+
.map((item) => `| 对话-${item.name} | ${formatPrice(item.price, 1000)} |`)
111+
.join('\n')}
112+
| 文件QA拆分 | ${formatPrice(qaModel.price, 1000)} |`}
108113
/>
109114
</>
110115
)}

client/src/pages/account/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum TabEnum {
3131

3232
const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
3333
const { t } = useTranslation();
34-
const tabList = useRef([
34+
const tabList = [
3535
{
3636
icon: 'meLight',
3737
label: t('user.Personal Information'),
@@ -67,7 +67,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
6767
label: t('user.Sign Out'),
6868
id: TabEnum.loginout
6969
}
70-
]);
70+
];
7171

7272
const { openConfirm, ConfirmModal } = useConfirm({
7373
content: '确认退出登录?'
@@ -115,7 +115,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
115115
mx={'auto'}
116116
mt={2}
117117
w={'100%'}
118-
list={tabList.current}
118+
list={tabList}
119119
activeId={currentTab}
120120
onChange={setCurrentTab}
121121
/>
@@ -125,7 +125,7 @@ const Account = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
125125
<Tabs
126126
m={'auto'}
127127
size={isPc ? 'md' : 'sm'}
128-
list={tabList.current.map((item) => ({
128+
list={tabList.map((item) => ({
129129
id: item.id,
130130
label: item.label
131131
}))}

0 commit comments

Comments
 (0)