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
057c3411
authored
Jun 24, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: fetch error
parent
83d755ad
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
11 deletions
+26
-11
client/src/api/fetch.ts
+10
-5
client/src/pages/chat/index.tsx
+13
-3
client/src/service/utils/chat/openai.ts
+2
-2
client/src/utils/tools.ts
+1
-1
No files found.
client/src/api/fetch.ts
View file @
057c3411
...
@@ -9,7 +9,8 @@ interface StreamFetchProps {
...
@@ -9,7 +9,8 @@ interface StreamFetchProps {
abortSignal
:
AbortController
;
abortSignal
:
AbortController
;
}
}
export
const
streamFetch
=
({
data
,
onMessage
,
abortSignal
}:
StreamFetchProps
)
=>
export
const
streamFetch
=
({
data
,
onMessage
,
abortSignal
}:
StreamFetchProps
)
=>
new
Promise
<
ChatResponseType
&
{
responseText
:
string
}
>
(
async
(
resolve
,
reject
)
=>
{
new
Promise
<
ChatResponseType
&
{
responseText
:
string
;
errMsg
:
string
}
>
(
async
(
resolve
,
reject
)
=>
{
try
{
try
{
const
response
=
await
window
.
fetch
(
'/api/openapi/v1/chat/completions'
,
{
const
response
=
await
window
.
fetch
(
'/api/openapi/v1/chat/completions'
,
{
method
:
'POST'
,
method
:
'POST'
,
...
@@ -38,6 +39,7 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
...
@@ -38,6 +39,7 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
let
responseText
=
''
;
let
responseText
=
''
;
let
newChatId
=
''
;
let
newChatId
=
''
;
let
quoteLen
=
0
;
let
quoteLen
=
0
;
let
errMsg
=
''
;
const
read
=
async
()
=>
{
const
read
=
async
()
=>
{
try
{
try
{
...
@@ -47,7 +49,8 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
...
@@ -47,7 +49,8 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
return
resolve
({
return
resolve
({
responseText
,
responseText
,
newChatId
,
newChatId
,
quoteLen
quoteLen
,
errMsg
});
});
}
else
{
}
else
{
return
reject
(
'响应过程出现异常~'
);
return
reject
(
'响应过程出现异常~'
);
...
@@ -74,7 +77,7 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
...
@@ -74,7 +77,7 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
newChatId
=
chatResponse
.
newChatId
;
newChatId
=
chatResponse
.
newChatId
;
quoteLen
=
chatResponse
.
quoteLen
||
0
;
quoteLen
=
chatResponse
.
quoteLen
||
0
;
}
else
if
(
item
.
event
===
sseResponseEventEnum
.
error
)
{
}
else
if
(
item
.
event
===
sseResponseEventEnum
.
error
)
{
return
reject
(
getErrText
(
data
,
'流响应错误'
)
);
errMsg
=
getErrText
(
data
,
'流响应错误'
);
}
}
});
});
read
();
read
();
...
@@ -83,7 +86,8 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
...
@@ -83,7 +86,8 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
return
resolve
({
return
resolve
({
responseText
,
responseText
,
newChatId
,
newChatId
,
quoteLen
quoteLen
,
errMsg
});
});
}
}
reject
(
getErrText
(
err
,
'请求异常'
));
reject
(
getErrText
(
err
,
'请求异常'
));
...
@@ -95,4 +99,5 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
...
@@ -95,4 +99,5 @@ export const streamFetch = ({ data, onMessage, abortSignal }: StreamFetchProps)
reject
(
getErrText
(
err
,
'请求异常'
));
reject
(
getErrText
(
err
,
'请求异常'
));
}
}
});
}
);
client/src/pages/chat/index.tsx
View file @
057c3411
...
@@ -174,7 +174,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -174,7 +174,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
const
messages
=
adaptChatItem_openAI
({
messages
:
prompts
,
reserveId
:
true
});
const
messages
=
adaptChatItem_openAI
({
messages
:
prompts
,
reserveId
:
true
});
// 流请求,获取数据
// 流请求,获取数据
const
{
newChatId
,
quoteLen
}
=
await
streamFetch
({
const
{
newChatId
,
quoteLen
,
errMsg
}
=
await
streamFetch
({
data
:
{
data
:
{
messages
,
messages
,
chatId
,
chatId
,
...
@@ -219,7 +219,9 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -219,7 +219,9 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
item
,
...
item
,
status
:
'finish'
,
status
:
'finish'
,
quoteLen
,
quoteLen
,
systemPrompt
:
`
${
chatData
.
systemPrompt
}
\n\n
${
chatData
.
limitPrompt
}
`
systemPrompt
:
`
${
chatData
.
systemPrompt
}${
`
${
chatData
.
limitPrompt
?
`\n\n
${
chatData
.
limitPrompt
}
`
:
''
}
`
}
`
};
};
})
})
}));
}));
...
@@ -230,6 +232,13 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -230,6 +232,13 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
loadHistory
({
pageNum
:
1
,
init
:
true
});
loadHistory
({
pageNum
:
1
,
init
:
true
});
loadMyModels
(
true
);
loadMyModels
(
true
);
},
100
);
},
100
);
if
(
errMsg
)
{
toast
({
status
:
'warning'
,
title
:
errMsg
});
}
},
},
[
[
chatId
,
chatId
,
...
@@ -241,7 +250,8 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -241,7 +250,8 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
chatData
.
systemPrompt
,
chatData
.
systemPrompt
,
chatData
.
limitPrompt
,
chatData
.
limitPrompt
,
loadHistory
,
loadHistory
,
loadMyModels
loadMyModels
,
toast
]
]
);
);
...
...
client/src/service/utils/chat/openai.ts
View file @
057c3411
...
@@ -49,8 +49,8 @@ export const chatResponse = async ({
...
@@ -49,8 +49,8 @@ export const chatResponse = async ({
messages
:
adaptMessages
,
messages
:
adaptMessages
,
frequency_penalty
:
0.5
,
// 越大,重复内容越少
frequency_penalty
:
0.5
,
// 越大,重复内容越少
presence_penalty
:
-
0.5
,
// 越大,越容易出现新内容
presence_penalty
:
-
0.5
,
// 越大,越容易出现新内容
stream
,
stream
stop
:
[
'.!?。'
]
//
stop: ['.!?。']
},
},
{
{
timeout
:
stream
?
60000
:
480000
,
timeout
:
stream
?
60000
:
480000
,
...
...
client/src/utils/tools.ts
View file @
057c3411
...
@@ -116,7 +116,7 @@ export const voiceBroadcast = ({ text }: { text: string }) => {
...
@@ -116,7 +116,7 @@ export const voiceBroadcast = ({ text }: { text: string }) => {
};
};
export
const
getErrText
=
(
err
:
any
,
def
=
''
)
=>
{
export
const
getErrText
=
(
err
:
any
,
def
=
''
)
=>
{
const
msg
=
typeof
err
===
'string'
?
err
:
err
?.
message
||
def
||
''
;
const
msg
:
string
=
typeof
err
===
'string'
?
err
:
err
?.
message
||
def
||
''
;
msg
&&
console
.
log
(
'error =>'
,
msg
);
msg
&&
console
.
log
(
'error =>'
,
msg
);
return
msg
;
return
msg
;
};
};
...
...
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