From b3b4f6bba1826b95e02f8aeb45dc0c76657617b5 Mon Sep 17 00:00:00 2001 From: Sakurasan <1173092237@qq.com> Date: Fri, 11 Aug 2023 22:42:14 +0800 Subject: [PATCH] fix bug --- router/router.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/router/router.go b/router/router.go index cd90383..05eb743 100644 --- a/router/router.go +++ b/router/router.go @@ -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) @@ -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) }