Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
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
Commit
05dc4bfc
authored
Jul 07, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: streaming timeout
parent
dbf5e07d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
0 deletions
+6
-0
relay/channel/openai/relay-openai.go
+6
-0
No files found.
relay/channel/openai/relay-openai.go
View file @
05dc4bfc
...
@@ -133,13 +133,19 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
...
@@ -133,13 +133,19 @@ func OpenaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.
}()
}()
service
.
SetEventStreamHeaders
(
c
)
service
.
SetEventStreamHeaders
(
c
)
isFirst
:=
true
isFirst
:=
true
ticker
:=
time
.
NewTicker
(
time
.
Duration
(
constant
.
StreamingTimeout
))
defer
ticker
.
Stop
()
c
.
Stream
(
func
(
w
io
.
Writer
)
bool
{
c
.
Stream
(
func
(
w
io
.
Writer
)
bool
{
select
{
select
{
case
<-
ticker
.
C
:
common
.
LogError
(
c
,
"reading data from upstream timeout"
)
return
false
case
data
:=
<-
dataChan
:
case
data
:=
<-
dataChan
:
if
isFirst
{
if
isFirst
{
isFirst
=
false
isFirst
=
false
info
.
FirstResponseTime
=
time
.
Now
()
info
.
FirstResponseTime
=
time
.
Now
()
}
}
ticker
.
Reset
(
time
.
Duration
(
constant
.
StreamingTimeout
))
if
strings
.
HasPrefix
(
data
,
"data: [DONE]"
)
{
if
strings
.
HasPrefix
(
data
,
"data: [DONE]"
)
{
data
=
data
[
:
12
]
data
=
data
[
:
12
]
}
}
...
...
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