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
2330186a
authored
Jul 18, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: abort
parent
8a25aeab
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
28 deletions
+50
-28
client/data/SystemParams.json
+3
-3
client/src/components/ChatBox/index.tsx
+10
-1
client/src/components/Markdown/index.tsx
+12
-9
client/src/pages/api/app/modules/chat/gpt.ts
+10
-2
client/src/pages/api/openapi/v1/chat/completions.ts
+1
-1
client/src/pages/app/list/component/CreateModal.tsx
+12
-10
client/src/pages/chat/index.tsx
+1
-1
client/src/pages/chat/share.tsx
+1
-1
No files found.
client/data/SystemParams.json
View file @
2330186a
{
"vectorMaxProcess"
:
1
0
,
"qaMaxProcess"
:
1
0
,
"pgIvfflatProbe"
:
1
0
,
"vectorMaxProcess"
:
1
5
,
"qaMaxProcess"
:
1
5
,
"pgIvfflatProbe"
:
2
0
,
"sensitiveCheck"
:
false
}
client/src/components/ChatBox/index.tsx
View file @
2330186a
...
...
@@ -5,7 +5,8 @@ import React, {
useMemo
,
forwardRef
,
useImperativeHandle
,
ForwardedRef
ForwardedRef
,
useEffect
}
from
'react'
;
import
{
throttle
}
from
'lodash'
;
import
{
ChatItemType
,
ChatSiteItemType
,
ExportChatType
}
from
'@/types/chat'
;
...
...
@@ -31,6 +32,7 @@ import { MessageItemType } from '@/pages/api/openapi/v1/chat/completions';
import
MyTooltip
from
'../MyTooltip'
;
import
{
fileDownload
}
from
'@/utils/file'
;
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
useRouter
}
from
'next/router'
;
import
dynamic
from
'next/dynamic'
;
const
QuoteModal
=
dynamic
(()
=>
import
(
'./QuoteModal'
));
...
...
@@ -133,6 +135,7 @@ const ChatBox = (
)
=>
{
const
ChatBoxRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
theme
=
useTheme
();
const
router
=
useRouter
();
const
{
copyData
}
=
useCopyData
();
const
{
toast
}
=
useToast
();
const
{
userInfo
}
=
useUserStore
();
...
...
@@ -392,6 +395,12 @@ const ChatBox = (
[
chatHistory
.
length
,
showEmptyIntro
,
variableModules
,
welcomeText
]
);
useEffect
(()
=>
{
return
()
=>
{
controller
.
current
?.
abort
();
};
},
[
router
.
query
]);
return
(
<
Flex
flexDirection=
{
'column'
}
h=
{
'100%'
}
>
<
Box
ref=
{
ChatBoxRef
}
flex=
{
'1 0 0'
}
h=
{
0
}
overflow=
{
'overlay'
}
px=
{
[
2
,
5
,
7
]
}
pt=
{
[
0
,
5
]
}
>
...
...
client/src/components/Markdown/index.tsx
View file @
2330186a
import
React
,
{
useRef
}
from
'react'
;
import
React
,
{
use
Memo
,
use
Ref
}
from
'react'
;
import
ReactMarkdown
from
'react-markdown'
;
import
RemarkGfm
from
'remark-gfm'
;
import
RemarkMath
from
'remark-math'
;
...
...
@@ -48,13 +48,16 @@ const Markdown = ({
isChatting
?:
boolean
;
onClick
?:
(
e
:
any
)
=>
void
;
})
=>
{
const
components
=
useRef
({
a
:
Link
,
img
:
Image
,
pre
:
'div'
,
p
:
'div'
,
code
:
(
props
:
any
)
=>
<
Code
{
...
props
}
onClick=
{
onClick
}
/>
});
const
components
=
useMemo
(
()
=>
({
a
:
Link
,
img
:
Image
,
pre
:
'div'
,
p
:
'div'
,
code
:
(
props
:
any
)
=>
<
Code
{
...
props
}
onClick=
{
onClick
}
/>
}),
[
onClick
]
);
return
(
<
ReactMarkdown
...
...
@@ -64,7 +67,7 @@ const Markdown = ({
remarkPlugins=
{
[
RemarkGfm
,
RemarkMath
,
RemarkBreaks
]
}
rehypePlugins=
{
[
RehypeKatex
]
}
// @ts-ignore
components=
{
components
.
current
}
components=
{
components
}
>
{
source
}
</
ReactMarkdown
>
...
...
client/src/pages/api/app/modules/chat/gpt.ts
View file @
2330186a
...
...
@@ -89,6 +89,14 @@ export async function chatCompletion({
// FastGpt temperature range: 1~10
temperature
=
+
(
modelConstantsData
.
maxTemperature
*
(
temperature
/
10
)).
toFixed
(
2
);
const
limitText
=
(()
=>
{
if
(
limitPrompt
)
return
limitPrompt
;
if
(
quotePrompt
&&
!
limitPrompt
)
{
return
'根据知识库内容回答问题,仅回复知识库提供的内容。'
;
}
return
''
;
})();
const
messages
:
ChatItemType
[]
=
[
...(
quotePrompt
?
[
...
...
@@ -107,11 +115,11 @@ export async function chatCompletion({
]
:
[]),
...
history
,
...(
limit
Promp
t
...(
limit
Tex
t
?
[
{
obj
:
ChatRoleEnum
.
System
,
value
:
limit
Promp
t
value
:
limit
Tex
t
}
]
:
[]),
...
...
client/src/pages/api/openapi/v1/chat/completions.ts
View file @
2330186a
...
...
@@ -145,7 +145,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
});
}
console
.
log
(
`finish time:
${(
Date
.
now
()
-
startTime
)
/
100
}
s`
);
console
.
log
(
`finish time:
${(
Date
.
now
()
-
startTime
)
/
100
0
}
s`
);
if
(
stream
)
{
sseResponse
({
...
...
client/src/pages/app/list/component/CreateModal.tsx
View file @
2330186a
...
...
@@ -23,6 +23,7 @@ import { postCreateApp } from '@/api/app';
import
{
useRouter
}
from
'next/router'
;
import
{
appTemplates
}
from
'@/constants/flow/ModuleTemplate'
;
import
Avatar
from
'@/components/Avatar'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
type
FormType
=
{
avatar
:
string
;
...
...
@@ -102,21 +103,22 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
<
Modal
isOpen
onClose=
{
onClose
}
>
<
ModalOverlay
/>
<
ModalContent
w=
{
'700px'
}
maxW=
{
'90vw'
}
>
<
ModalHeader
fontSize=
{
'2xl'
}
>
开始创建
你的 AI 应用
</
ModalHeader
>
<
ModalHeader
fontSize=
{
'2xl'
}
>
创建属于
你的 AI 应用
</
ModalHeader
>
<
ModalBody
>
<
Box
color=
{
'myGray.800'
}
fontWeight=
{
'bold'
}
>
取个响亮的名字
</
Box
>
<
Flex
mt=
{
3
}
alignItems=
{
'center'
}
>
<
Avatar
src=
{
getValues
(
'avatar'
)
}
w=
{
[
'32px'
,
'36px'
]
}
h=
{
[
'32px'
,
'36px'
]
}
cursor=
{
'pointer'
}
title=
{
'点击选择头像'
}
borderRadius=
{
'md'
}
onClick=
{
onOpenSelectFile
}
/>
<
MyTooltip
label=
{
'点击设置头像'
}
>
<
Avatar
src=
{
getValues
(
'avatar'
)
}
w=
{
[
'32px'
,
'36px'
]
}
h=
{
[
'32px'
,
'36px'
]
}
cursor=
{
'pointer'
}
borderRadius=
{
'md'
}
onClick=
{
onOpenSelectFile
}
/>
</
MyTooltip
>
<
Input
ml=
{
4
}
bg=
{
'myWhite.600'
}
...
...
client/src/pages/chat/index.tsx
View file @
2330186a
...
...
@@ -66,7 +66,7 @@ const Chat = () => {
const
newTitle
=
prompts
[
0
].
content
?.
slice
(
0
,
20
)
||
'新对话'
;
// update history
if
(
newChatId
)
{
if
(
newChatId
&&
!
controller
.
signal
.
aborted
)
{
forbidRefresh
.
current
=
true
;
const
newHistory
:
ChatHistoryItemType
=
{
_id
:
newChatId
,
...
...
client/src/pages/chat/share.tsx
View file @
2330186a
...
...
@@ -69,7 +69,7 @@ const ShareChat = ({ shareId, chatId }: { shareId: string; chatId: string }) =>
shareId
});
if
(
newChatId
)
{
if
(
newChatId
&&
!
controller
.
signal
.
aborted
)
{
router
.
replace
({
query
:
{
shareId
,
...
...
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