(c *gin.Context)
| 13 | ) |
| 14 | |
| 15 | func Playground(c *gin.Context) { |
| 16 | var newAPIError *types.NewAPIError |
| 17 | |
| 18 | defer func() { |
| 19 | if newAPIError != nil { |
| 20 | c.JSON(newAPIError.StatusCode, gin.H{ |
| 21 | "error": newAPIError.ToOpenAIError(), |
| 22 | }) |
| 23 | } |
| 24 | }() |
| 25 | |
| 26 | useAccessToken := c.GetBool("use_access_token") |
| 27 | if useAccessToken { |
| 28 | newAPIError = types.NewError(errors.New("暂不支持使用 access token"), types.ErrorCodeAccessDenied, types.ErrOptionWithSkipRetry()) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | relayInfo, err := relaycommon.GenRelayInfo(c, types.RelayFormatOpenAI, nil, nil) |
| 33 | if err != nil { |
| 34 | newAPIError = types.NewError(err, types.ErrorCodeInvalidRequest, types.ErrOptionWithSkipRetry()) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | userId := c.GetInt("id") |
| 39 | |
| 40 | // Write user context to ensure acceptUnsetRatio is available |
| 41 | userCache, err := model.GetUserCache(userId) |
| 42 | if err != nil { |
| 43 | newAPIError = types.NewError(err, types.ErrorCodeQueryDataError, types.ErrOptionWithSkipRetry()) |
| 44 | return |
| 45 | } |
| 46 | userCache.WriteContext(c) |
| 47 | |
| 48 | tempToken := &model.Token{ |
| 49 | UserId: userId, |
| 50 | Name: fmt.Sprintf("playground-%s", relayInfo.UsingGroup), |
| 51 | Group: relayInfo.UsingGroup, |
| 52 | } |
| 53 | _ = middleware.SetupContextForToken(c, tempToken) |
| 54 | |
| 55 | Relay(c, types.RelayFormatOpenAI) |
| 56 | } |
nothing calls this directly
no test coverage detected