120 timeout if only one upstream

This commit is contained in:
2023-11-08 20:42:36 +08:00
parent b932331bdc
commit 6aab4fb44b
2 changed files with 8 additions and 4 deletions

View File

@@ -133,6 +133,10 @@ func main() {
shouldResponse := index == len(upstreams)-1
if len(upstreams) == 1 {
upstream.Timeout = 120
}
err = processRequest(c, &upstream, &record, shouldResponse)
if err != nil {
log.Println("Error from upstream", upstream.Endpoint, "should retry", err)

View File

@@ -62,16 +62,16 @@ func processRequest(c *gin.Context, upstream *OPENAI_UPSTREAM, record *Record, s
// set timeout, default is 60 second
timeout := 60 * time.Second
if upstream.Timeout > 0 {
// convert upstream.Timeout(second) to nanosecond
timeout = time.Duration(upstream.Timeout) * time.Second
}
if requestBodyOK == nil && requestBody.Stream {
timeout = 5 * time.Second
}
if len(inBody) > 1024*128 {
timeout = 20 * time.Second
}
if upstream.Timeout > 0 {
// convert upstream.Timeout(second) to nanosecond
timeout = time.Duration(upstream.Timeout) * time.Second
}
// timeout out request
go func() {