MCPcopy
hub / github.com/QuantumNous/new-api / Playground

Function Playground

controller/playground.go:15–56  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

13)
14
15func 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}

Callers

nothing calls this directly

Calls 7

ToOpenAIErrorMethod · 0.95
NewErrorFunction · 0.92
ErrOptionWithSkipRetryFunction · 0.92
GetUserCacheFunction · 0.92
SetupContextForTokenFunction · 0.92
RelayFunction · 0.85
WriteContextMethod · 0.80

Tested by

no test coverage detected