diff --git a/main.go b/main.go index 1070353..86f8f5f 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/process.go b/process.go index 5622437..57ef97f 100644 --- a/process.go +++ b/process.go @@ -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() {