Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakurasan committed Aug 11, 2023
1 parent a481a0e commit b3b4f6b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func HandleProy(c *gin.Context) {
auth := c.Request.Header.Get("Authorization")
if len(auth) > 7 && auth[:7] == "Bearer " {
localuser = store.IsExistAuthCache(auth[7:])
c.Set("localuser", localuser)
c.Set("localuser", auth[7:])
}
if c.Request.URL.Path == "/v1/audio/transcriptions" {
WhisperProxy(c)
Expand Down Expand Up @@ -869,11 +869,17 @@ func WhisperProxy(c *gin.Context) {
})
return
}

targetUrl, _ := url.ParseRequestURI(key.EndPoint)
if key.EndPoint == "" {
key.EndPoint = "https://api.openai.com"
}
targetUrl, _ := url.ParseRequestURI(key.EndPoint + c.Request.URL.String())
log.Println(targetUrl)
proxy := httputil.NewSingleHostReverseProxy(targetUrl)
proxy.Director = func(req *http.Request) {
req.Header.Set("Content-Type", "application/json")
req.Host = targetUrl.Host
req.URL.Scheme = targetUrl.Scheme
req.URL.Host = targetUrl.Host

req.Header.Set("Authorization", "Bearer "+key.Key)
}

Expand Down

0 comments on commit b3b4f6b

Please sign in to comment.