Skip to content

Commit

Permalink
perf: flush response after response handled (close songquanpeng#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Aug 12, 2023
1 parent 2a527ee commit 7bddc73
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ var EmailDomainWhitelist = []string{
"foxmail.com",
}

var DebugEnabled = os.Getenv("DEBUG") == "true"

var LogConsumeEnabled = true

var SMTPServer = ""
Expand Down
4 changes: 2 additions & 2 deletions controller/relay-text.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"io"
"net/http"
"one-api/common"
"one-api/model"
"strings"

"github.com/gin-gonic/gin"
)

const (
Expand Down Expand Up @@ -308,6 +307,7 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode {
var textResponse TextResponse

defer func() {
c.Writer.Flush()
if consumeQuota {
quota := 0
completionRatio := 1.0
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func main() {
if os.Getenv("GIN_MODE") != "debug" {
gin.SetMode(gin.ReleaseMode)
}
if common.DebugEnabled {
common.SysLog("running in debug mode")
}
// Initialize SQL Database
err := model.InitDB()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions model/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func InitDB() (err error) {
}
common.SysLog("database connected")
if err == nil {
if common.DebugEnabled {
db = db.Debug()
}
DB = db
sqlDB, err := DB.DB()
if err != nil {
Expand Down

0 comments on commit 7bddc73

Please sign in to comment.