Просмотр исходного кода

feat: Playground相关接口禁用AccessToken

1808837298@qq.com 1 год назад
Родитель
Сommit
0cf53ac5ff
2 измененных файлов с 7 добавлено и 2 удалено
  1. 6 2
      controller/relay.go
  2. 1 0
      middleware/auth.go

+ 6 - 2
controller/relay.go

@@ -49,6 +49,12 @@ func Playground(c *gin.Context) {
 		}
 		}
 	}()
 	}()
 
 
+	useAccessToken := c.GetBool("use_access_token")
+	if useAccessToken {
+		openaiErr = service.OpenAIErrorWrapperLocal(errors.New("暂不支持使用 access token"), "access_token_not_supported", http.StatusBadRequest)
+		return
+	}
+
 	playgroundRequest := &dto.PlayGroundRequest{}
 	playgroundRequest := &dto.PlayGroundRequest{}
 	err := common.UnmarshalBodyReusable(c, playgroundRequest)
 	err := common.UnmarshalBodyReusable(c, playgroundRequest)
 	if err != nil {
 	if err != nil {
@@ -67,8 +73,6 @@ func Playground(c *gin.Context) {
 	} else {
 	} else {
 		c.Set("group", group)
 		c.Set("group", group)
 	}
 	}
-	log.Printf("group: %s", group)
-	log.Printf("model: %s", playgroundRequest.Model)
 	channel, err := model.CacheGetRandomSatisfiedChannel(group, playgroundRequest.Model, 0)
 	channel, err := model.CacheGetRandomSatisfiedChannel(group, playgroundRequest.Model, 0)
 	if err != nil {
 	if err != nil {
 		openaiErr = service.OpenAIErrorWrapperLocal(err, "get_playground_channel_failed", http.StatusInternalServerError)
 		openaiErr = service.OpenAIErrorWrapperLocal(err, "get_playground_channel_failed", http.StatusInternalServerError)

+ 1 - 0
middleware/auth.go

@@ -122,6 +122,7 @@ func authHelper(c *gin.Context, minRole int) {
 	c.Set("role", role)
 	c.Set("role", role)
 	c.Set("id", id)
 	c.Set("id", id)
 	c.Set("group", session.Get("group"))
 	c.Set("group", session.Get("group"))
+	c.Set("use_access_token", useAccessToken)
 	c.Next()
 	c.Next()
 }
 }