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
f382b219
authored
Jul 04, 2023
by
kssdxw
Committed by
GitHub
Jul 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: openai data truncation (#112)
parent
a4744dd7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletions
+12
-1
client/src/service/utils/chat/index.ts
+12
-1
No files found.
client/src/service/utils/chat/index.ts
View file @
f382b219
...
...
@@ -186,16 +186,27 @@ export const V2_StreamResponse = async ({
})
=>
{
let
responseContent
=
''
;
let
error
:
any
=
null
;
let
truncateData
=
''
;
const
clientRes
=
async
(
data
:
string
)
=>
{
//部分代理会导致流式传输时的数据被截断,不为json格式,这里做一个兼容
const
{
content
=
''
}
=
(()
=>
{
try
{
if
(
truncateData
)
{
try
{
//判断是否为json,如果是的话直接跳过后续拼装操作,注意极端情况下可能出现截断成3截以上情况也可以兼容
JSON
.
parse
(
data
);
}
catch
(
e
)
{
data
=
truncateData
+
data
;
}
truncateData
=
''
;
}
const
json
=
JSON
.
parse
(
data
);
const
content
:
string
=
json
?.
choices
?.[
0
].
delta
.
content
||
''
;
error
=
json
.
error
;
responseContent
+=
content
;
return
{
content
};
}
catch
(
error
)
{
truncateData
=
data
;
return
{};
}
})();
...
...
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