mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-17 16:06:38 +08:00
fix: streaming timeout
This commit is contained in:
parent
8a730cfe12
commit
1e536ee7d9
@ -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]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user