Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
63c832d8
authored
Aug 10, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: search prompt, upload step and psw len
parent
9ea19b8e
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
82 additions
and
27 deletions
+82
-27
client/public/locales/en/common.json
+3
-0
client/public/locales/zh/common.json
+4
-0
client/src/components/ChatBox/QuoteModal.tsx
+16
-5
client/src/pages/account/components/UpdatePswModal.tsx
+33
-4
client/src/pages/api/openapi/kb/pushData.ts
+2
-3
client/src/pages/kb/detail/components/Import/Chunk.tsx
+1
-1
client/src/pages/kb/detail/components/Import/Csv.tsx
+2
-2
client/src/pages/kb/detail/components/Import/QA.tsx
+1
-1
client/src/pages/login/components/ForgetPasswordForm.tsx
+3
-3
client/src/pages/login/components/LoginForm.tsx
+2
-2
client/src/pages/login/components/RegisterForm.tsx
+3
-3
client/src/service/moduleDispatch/agent/classifyQuestion.ts
+4
-0
client/src/service/moduleDispatch/chat/oneapi.ts
+4
-2
client/src/service/utils/chat/index.ts
+4
-1
No files found.
client/public/locales/en/common.json
View file @
63c832d8
...
@@ -22,6 +22,9 @@
...
@@ -22,6 +22,9 @@
"New Chat"
:
"New Chat"
,
"New Chat"
:
"New Chat"
,
"You need to a chat app"
:
"You need to a chat app"
"You need to a chat app"
:
"You need to a chat app"
},
},
"commom"
:
{
"Password inconsistency"
:
"Password inconsistency"
},
"common"
:
{
"common"
:
{
"Add"
:
"Add"
,
"Add"
:
"Add"
,
"Cancel"
:
"Cancel"
,
"Cancel"
:
"Cancel"
,
...
...
client/public/locales/zh/common.json
View file @
63c832d8
...
@@ -22,11 +22,15 @@
...
@@ -22,11 +22,15 @@
"New Chat"
:
"新对话"
,
"New Chat"
:
"新对话"
,
"You need to a chat app"
:
"你需要创建一个应用"
"You need to a chat app"
:
"你需要创建一个应用"
},
},
"commom"
:
{
"Password inconsistency"
:
"两次密码不一致"
},
"common"
:
{
"common"
:
{
"Add"
:
"添加"
,
"Add"
:
"添加"
,
"Cancel"
:
"取消"
,
"Cancel"
:
"取消"
,
"Collect"
:
"收藏"
,
"Collect"
:
"收藏"
,
"Copy"
:
"复制"
,
"Copy"
:
"复制"
,
"Course"
:
""
,
"Delete"
:
"删除"
,
"Delete"
:
"删除"
,
"Filed is repeat"
:
""
,
"Filed is repeat"
:
""
,
"Filed is repeated"
:
"字段重复了"
,
"Filed is repeated"
:
"字段重复了"
,
...
...
client/src/components/ChatBox/QuoteModal.tsx
View file @
63c832d8
import
React
,
{
useCallback
,
useState
}
from
'react'
;
import
React
,
{
useCallback
,
useState
}
from
'react'
;
import
{
ModalBody
,
ModalCloseButton
,
ModalHeader
,
Box
,
useTheme
}
from
'@chakra-ui/react'
;
import
{
ModalBody
,
Box
,
useTheme
}
from
'@chakra-ui/react'
;
import
{
getKbDataItemById
}
from
'@/api/plugins/kb'
;
import
{
getKbDataItemById
}
from
'@/api/plugins/kb'
;
import
{
useLoading
}
from
'@/hooks/useLoading'
;
import
{
useLoading
}
from
'@/hooks/useLoading'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
...
@@ -9,13 +9,21 @@ import MyIcon from '@/components/Icon';
...
@@ -9,13 +9,21 @@ import MyIcon from '@/components/Icon';
import
InputDataModal
from
'@/pages/kb/detail/components/InputDataModal'
;
import
InputDataModal
from
'@/pages/kb/detail/components/InputDataModal'
;
import
MyModal
from
'../MyModal'
;
import
MyModal
from
'../MyModal'
;
type
SearchType
=
{
kb_id
?:
string
;
id
?:
string
;
q
:
string
;
a
?:
string
;
source
?:
string
|
undefined
;
};
const
QuoteModal
=
({
const
QuoteModal
=
({
onUpdateQuote
,
onUpdateQuote
,
rawSearch
=
[],
rawSearch
=
[],
onClose
onClose
}:
{
}:
{
onUpdateQuote
:
(
quoteId
:
string
,
sourceText
:
string
)
=>
Promise
<
void
>
;
onUpdateQuote
:
(
quoteId
:
string
,
sourceText
:
string
)
=>
Promise
<
void
>
;
rawSearch
:
QuoteItem
Type
[];
rawSearch
:
Search
Type
[];
onClose
:
()
=>
void
;
onClose
:
()
=>
void
;
})
=>
{
})
=>
{
const
theme
=
useTheme
();
const
theme
=
useTheme
();
...
@@ -32,7 +40,8 @@ const QuoteModal = ({
...
@@ -32,7 +40,8 @@ const QuoteModal = ({
* click edit, get new kbDataItem
* click edit, get new kbDataItem
*/
*/
const
onclickEdit
=
useCallback
(
const
onclickEdit
=
useCallback
(
async
(
item
:
QuoteItemType
)
=>
{
async
(
item
:
SearchType
)
=>
{
if
(
!
item
.
id
)
return
;
try
{
try
{
setIsLoading
(
true
);
setIsLoading
(
true
);
const
data
=
(
await
getKbDataItemById
(
item
.
id
))
as
QuoteItemType
;
const
data
=
(
await
getKbDataItemById
(
item
.
id
))
as
QuoteItemType
;
...
@@ -77,9 +86,9 @@ const QuoteModal = ({
...
@@ -77,9 +86,9 @@ const QuoteModal = ({
}
}
>
>
<
ModalBody
pt=
{
0
}
whiteSpace=
{
'pre-wrap'
}
textAlign=
{
'justify'
}
fontSize=
{
'sm'
}
>
<
ModalBody
pt=
{
0
}
whiteSpace=
{
'pre-wrap'
}
textAlign=
{
'justify'
}
fontSize=
{
'sm'
}
>
{
rawSearch
.
map
((
item
)
=>
(
{
rawSearch
.
map
((
item
,
i
)
=>
(
<
Box
<
Box
key=
{
i
tem
.
id
}
key=
{
i
}
flex=
{
'1 0 0'
}
flex=
{
'1 0 0'
}
p=
{
2
}
p=
{
2
}
borderRadius=
{
'lg'
}
borderRadius=
{
'lg'
}
...
@@ -91,6 +100,7 @@ const QuoteModal = ({
...
@@ -91,6 +100,7 @@ const QuoteModal = ({
{
item
.
source
&&
<
Box
color=
{
'myGray.600'
}
>
(
{
item
.
source
}
)
</
Box
>
}
{
item
.
source
&&
<
Box
color=
{
'myGray.600'
}
>
(
{
item
.
source
}
)
</
Box
>
}
<
Box
>
{
item
.
q
}
</
Box
>
<
Box
>
{
item
.
q
}
</
Box
>
<
Box
>
{
item
.
a
}
</
Box
>
<
Box
>
{
item
.
a
}
</
Box
>
{
item
.
id
&&
(
<
Box
<
Box
className=
"edit"
className=
"edit"
display=
{
'none'
}
display=
{
'none'
}
...
@@ -116,6 +126,7 @@ const QuoteModal = ({
...
@@ -116,6 +126,7 @@ const QuoteModal = ({
onClick=
{
()
=>
onclickEdit
(
item
)
}
onClick=
{
()
=>
onclickEdit
(
item
)
}
/>
/>
</
Box
>
</
Box
>
)
}
</
Box
>
</
Box
>
))
}
))
}
</
ModalBody
>
</
ModalBody
>
...
...
client/src/pages/account/components/UpdatePswModal.tsx
View file @
63c832d8
...
@@ -6,9 +6,15 @@ import { useForm } from 'react-hook-form';
...
@@ -6,9 +6,15 @@ import { useForm } from 'react-hook-form';
import
{
useRequest
}
from
'@/hooks/useRequest'
;
import
{
useRequest
}
from
'@/hooks/useRequest'
;
import
{
updatePasswordByOld
}
from
'@/api/user'
;
import
{
updatePasswordByOld
}
from
'@/api/user'
;
type
FormType
=
{
oldPsw
:
string
;
newPsw
:
string
;
confirmPsw
:
string
;
};
const
UpdatePswModal
=
({
onClose
}:
{
onClose
:
()
=>
void
})
=>
{
const
UpdatePswModal
=
({
onClose
}:
{
onClose
:
()
=>
void
})
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
{
register
,
handleSubmit
}
=
useForm
({
const
{
register
,
handleSubmit
}
=
useForm
<
FormType
>
({
defaultValues
:
{
defaultValues
:
{
oldPsw
:
''
,
oldPsw
:
''
,
newPsw
:
''
,
newPsw
:
''
,
...
@@ -17,7 +23,10 @@ const UpdatePswModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -17,7 +23,10 @@ const UpdatePswModal = ({ onClose }: { onClose: () => void }) => {
});
});
const
{
mutate
:
onSubmit
,
isLoading
}
=
useRequest
({
const
{
mutate
:
onSubmit
,
isLoading
}
=
useRequest
({
mutationFn
:
(
data
)
=>
{
mutationFn
:
(
data
:
FormType
)
=>
{
if
(
data
.
newPsw
!==
data
.
confirmPsw
)
{
return
Promise
.
reject
(
t
(
'commom.Password inconsistency'
));
}
return
updatePasswordByOld
(
data
);
return
updatePasswordByOld
(
data
);
},
},
onSuccess
()
{
onSuccess
()
{
...
@@ -36,11 +45,31 @@ const UpdatePswModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -36,11 +45,31 @@ const UpdatePswModal = ({ onClose }: { onClose: () => void }) => {
</
Flex
>
</
Flex
>
<
Flex
alignItems=
{
'center'
}
mt=
{
5
}
>
<
Flex
alignItems=
{
'center'
}
mt=
{
5
}
>
<
Box
flex=
{
'0 0 70px'
}
>
新密码:
</
Box
>
<
Box
flex=
{
'0 0 70px'
}
>
新密码:
</
Box
>
<
Input
flex=
{
1
}
type=
{
'password'
}
{
...
register
('
newPsw
',
{
required
:
true
})}
></
Input
>
<
Input
flex=
{
1
}
type=
{
'password'
}
{
...
register
('
newPsw
',
{
required
:
true
,
maxLength
:
{
value
:
20,
message
:
'密码最少
4
位最多
20
位'
}
})}
></
Input
>
</
Flex
>
</
Flex
>
<
Flex
alignItems=
{
'center'
}
mt=
{
5
}
>
<
Flex
alignItems=
{
'center'
}
mt=
{
5
}
>
<
Box
flex=
{
'0 0 70px'
}
>
确认密码:
</
Box
>
<
Box
flex=
{
'0 0 70px'
}
>
确认密码:
</
Box
>
<
Input
flex=
{
1
}
type=
{
'password'
}
{
...
register
('
confirmPsw
',
{
required
:
true
})}
></
Input
>
<
Input
flex=
{
1
}
type=
{
'password'
}
{
...
register
('
confirmPsw
',
{
required
:
true
,
maxLength
:
{
value
:
20,
message
:
'密码最少
4
位最多
20
位'
}
})}
></
Input
>
</
Flex
>
</
Flex
>
</
ModalBody
>
</
ModalBody
>
<
ModalFooter
>
<
ModalFooter
>
...
...
client/src/pages/api/openapi/kb/pushData.ts
View file @
63c832d8
...
@@ -90,16 +90,15 @@ export async function pushDataToKb({
...
@@ -90,16 +90,15 @@ export async function pushDataToKb({
data
.
forEach
((
item
)
=>
{
data
.
forEach
((
item
)
=>
{
const
text
=
item
.
q
+
item
.
a
;
const
text
=
item
.
q
+
item
.
a
;
if
(
mode
===
TrainingModeEnum
.
qa
)
{
// count token
// count token
const
token
=
modelToolMap
.
countTokens
({
const
token
=
modelToolMap
.
countTokens
({
model
:
'gpt-3.5-turbo-16k
'
,
model
:
'gpt-3.5-turbo
'
,
messages
:
[{
obj
:
'System'
,
value
:
item
.
q
}]
messages
:
[{
obj
:
'System'
,
value
:
item
.
q
}]
});
});
if
(
token
>
modeMaxToken
[
TrainingModeEnum
.
qa
])
{
if
(
token
>
modeMaxToken
[
TrainingModeEnum
.
qa
])
{
return
;
return
;
}
}
}
if
(
!
set
.
has
(
text
))
{
if
(
!
set
.
has
(
text
))
{
filterData
.
push
(
item
);
filterData
.
push
(
item
);
...
...
client/src/pages/kb/detail/components/Import/Chunk.tsx
View file @
63c832d8
...
@@ -142,7 +142,7 @@ const ChunkImport = ({ kbId }: { kbId: string }) => {
...
@@ -142,7 +142,7 @@ const ChunkImport = ({ kbId }: { kbId: string }) => {
// subsection import
// subsection import
let
success
=
0
;
let
success
=
0
;
const
step
=
1
00
;
const
step
=
5
00
;
for
(
let
i
=
0
;
i
<
chunks
.
length
;
i
+=
step
)
{
for
(
let
i
=
0
;
i
<
chunks
.
length
;
i
+=
step
)
{
const
{
insertLen
}
=
await
postKbDataFromList
({
const
{
insertLen
}
=
await
postKbDataFromList
({
kbId
,
kbId
,
...
...
client/src/pages/kb/detail/components/Import/Csv.tsx
View file @
63c832d8
...
@@ -13,7 +13,7 @@ import { TrainingModeEnum } from '@/constants/plugin';
...
@@ -13,7 +13,7 @@ import { TrainingModeEnum } from '@/constants/plugin';
import
FileSelect
from
'./FileSelect'
;
import
FileSelect
from
'./FileSelect'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
const
nanoid
=
customAlphabet
(
'abcdefghijklmnopqrstuvwxyz1234567890'
,
12
);
const
nanoid
=
customAlphabet
(
'abcdefghijklmnopqrstuvwxyz1234567890'
,
12
);
import
{
fileDownload
,
readCsvContent
}
from
'@/utils/file'
;
import
{
readCsvContent
}
from
'@/utils/file'
;
const
fileExtension
=
'.csv'
;
const
fileExtension
=
'.csv'
;
...
@@ -98,7 +98,7 @@ const CsvImport = ({ kbId }: { kbId: string }) => {
...
@@ -98,7 +98,7 @@ const CsvImport = ({ kbId }: { kbId: string }) => {
// subsection import
// subsection import
let
success
=
0
;
let
success
=
0
;
const
step
=
1
00
;
const
step
=
5
00
;
for
(
let
i
=
0
;
i
<
chunks
.
length
;
i
+=
step
)
{
for
(
let
i
=
0
;
i
<
chunks
.
length
;
i
+=
step
)
{
const
{
insertLen
}
=
await
postKbDataFromList
({
const
{
insertLen
}
=
await
postKbDataFromList
({
kbId
,
kbId
,
...
...
client/src/pages/kb/detail/components/Import/QA.tsx
View file @
63c832d8
...
@@ -132,7 +132,7 @@ const QAImport = ({ kbId }: { kbId: string }) => {
...
@@ -132,7 +132,7 @@ const QAImport = ({ kbId }: { kbId: string }) => {
// subsection import
// subsection import
let
success
=
0
;
let
success
=
0
;
const
step
=
1
00
;
const
step
=
5
00
;
for
(
let
i
=
0
;
i
<
chunks
.
length
;
i
+=
step
)
{
for
(
let
i
=
0
;
i
<
chunks
.
length
;
i
+=
step
)
{
const
{
insertLen
}
=
await
postKbDataFromList
({
const
{
insertLen
}
=
await
postKbDataFromList
({
kbId
,
kbId
,
...
...
client/src/pages/login/components/ForgetPasswordForm.tsx
View file @
63c832d8
...
@@ -129,11 +129,11 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -129,11 +129,11 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
required
:
'密码不能为空',
required
:
'密码不能为空',
minLength
:
{
minLength
:
{
value
:
4,
value
:
4,
message
:
'密码最少
4位最多12
位'
message
:
'密码最少
4
位最多
20
位'
},
},
maxLength
:
{
maxLength
:
{
value
:
12
,
value
:
20
,
message
:
'密码最少
4位最多12
位'
message
:
'密码最少
4
位最多
20
位'
}
}
})}
})}
></
Input
>
></
Input
>
...
...
client/src/pages/login/components/LoginForm.tsx
View file @
63c832d8
...
@@ -97,8 +97,8 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -97,8 +97,8 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
{...register('password', {
{...register('password', {
required: '密码不能为空',
required: '密码不能为空',
maxLength: {
maxLength: {
value:
12
,
value:
20
,
message: '密码最多
12
位'
message: '密码最多
20
位'
}
}
})}
})}
></Input>
></Input>
...
...
client/src/pages/login/components/RegisterForm.tsx
View file @
63c832d8
...
@@ -142,11 +142,11 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
...
@@ -142,11 +142,11 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
required
:
'密码不能为空',
required
:
'密码不能为空',
minLength
:
{
minLength
:
{
value
:
4,
value
:
4,
message
:
'密码最少
4位最多12
位'
message
:
'密码最少
4
位最多
20
位'
},
},
maxLength
:
{
maxLength
:
{
value
:
12
,
value
:
20
,
message
:
'密码最少
4位最多12
位'
message
:
'密码最少
4
位最多
20
位'
}
}
})}
})}
></
Input
>
></
Input
>
...
...
client/src/service/moduleDispatch/agent/classifyQuestion.ts
View file @
63c832d8
...
@@ -30,6 +30,10 @@ const maxTokens = 3000;
...
@@ -30,6 +30,10 @@ const maxTokens = 3000;
export
const
dispatchClassifyQuestion
=
async
(
props
:
Record
<
string
,
any
>
):
Promise
<
CQResponse
>
=>
{
export
const
dispatchClassifyQuestion
=
async
(
props
:
Record
<
string
,
any
>
):
Promise
<
CQResponse
>
=>
{
const
{
agents
,
systemPrompt
,
history
=
[],
userChatInput
,
userOpenaiAccount
}
=
props
as
CQProps
;
const
{
agents
,
systemPrompt
,
history
=
[],
userChatInput
,
userOpenaiAccount
}
=
props
as
CQProps
;
if
(
!
userChatInput
)
{
return
Promise
.
reject
(
'Input is empty'
);
}
const
messages
:
ChatItemType
[]
=
[
const
messages
:
ChatItemType
[]
=
[
...(
systemPrompt
...(
systemPrompt
?
[
?
[
...
...
client/src/service/moduleDispatch/chat/oneapi.ts
View file @
63c832d8
...
@@ -192,7 +192,7 @@ function filterQuote({
...
@@ -192,7 +192,7 @@ function filterQuote({
maxToken
:
model
.
quoteMaxToken
,
maxToken
:
model
.
quoteMaxToken
,
messages
:
quoteQA
.
map
((
item
,
i
)
=>
({
messages
:
quoteQA
.
map
((
item
,
i
)
=>
({
obj
:
ChatRoleEnum
.
System
,
obj
:
ChatRoleEnum
.
System
,
value
:
`
${
i
+
1
}
. [
${
item
.
q
}
\n
${
item
.
a
}
]
`
value
:
item
.
a
?
`{instruction:
${
item
.
q
}
,output:
${
item
.
a
}
}`
:
`{instruction:
${
item
.
q
}
}
`
}))
}))
});
});
...
@@ -202,7 +202,9 @@ function filterQuote({
...
@@ -202,7 +202,9 @@ function filterQuote({
const
quotePrompt
=
const
quotePrompt
=
filterQuoteQA
.
length
>
0
filterQuoteQA
.
length
>
0
?
`下面是知识库内容:
?
`下面是知识库内容:
${
filterQuoteQA
.
map
((
item
)
=>
`{Q:
${
item
.
q
}
,A:
${
item
.
a
}
}`
).
join
(
'\n'
)}
${
filterQuoteQA
.
map
((
item
)
=>
(
item
.
a
?
`{instruction:
${
item
.
q
}
,output:
${
item
.
a
}
}`
:
`{instruction:
${
item
.
q
}
}`
))
.
join
(
'\n'
)}
`
`
:
''
;
:
''
;
...
...
client/src/service/utils/chat/index.ts
View file @
63c832d8
...
@@ -21,13 +21,16 @@ export type StreamResponseType = {
...
@@ -21,13 +21,16 @@ export type StreamResponseType = {
/* slice chat context by tokens */
/* slice chat context by tokens */
export
const
ChatContextFilter
=
({
export
const
ChatContextFilter
=
({
model
,
model
,
prompts
,
prompts
=
[]
,
maxTokens
maxTokens
}:
{
}:
{
model
:
string
;
model
:
string
;
prompts
:
ChatItemType
[];
prompts
:
ChatItemType
[];
maxTokens
:
number
;
maxTokens
:
number
;
})
=>
{
})
=>
{
if
(
!
Array
.
isArray
(
prompts
))
{
return
[];
}
const
rawTextLen
=
prompts
.
reduce
((
sum
,
item
)
=>
sum
+
item
.
value
.
length
,
0
);
const
rawTextLen
=
prompts
.
reduce
((
sum
,
item
)
=>
sum
+
item
.
value
.
length
,
0
);
// If the text length is less than half of the maximum token, no calculation is required
// If the text length is less than half of the maximum token, no calculation is required
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment