MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / Playground

Function Playground

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

Source from the content-addressed store, hash-verified

16)
17
18func Playground(c *gin.Context) {
19 var newAPIError *types.NewAPIError
20
21 defer func() {
22 if newAPIError != nil {
23 c.JSON(newAPIError.StatusCode, gin.H{
24 "error": newAPIError.ToOpenAIError(),
25 })
26 }
27 }()
28
29 useAccessToken := c.GetBool("use_access_token")
30 if useAccessToken {
31 newAPIError = types.NewError(errors.New("暂不支持使用 access token"), types.ErrorCodeAccessDenied)
32 return
33 }
34
35 playgroundRequest := &dto.PlayGroundRequest{}
36 err := common.UnmarshalBodyReusable(c, playgroundRequest)
37 if err != nil {
38 newAPIError = types.NewError(err, types.ErrorCodeInvalidRequest)
39 return
40 }
41
42 if playgroundRequest.Model == "" {
43 newAPIError = types.NewError(errors.New("请选择模型"), types.ErrorCodeInvalidRequest)
44 return
45 }
46 c.Set("original_model", playgroundRequest.Model)
47 group := playgroundRequest.Group
48 userGroup := c.GetString("group")
49
50 if group == "" {
51 group = userGroup
52 } else {
53 if !setting.GroupInUserUsableGroups(group) && group != userGroup {
54 newAPIError = types.NewError(errors.New("无权访问该分组"), types.ErrorCodeAccessDenied)
55 return
56 }
57 c.Set("group", group)
58 }
59
60 userId := c.GetInt("id")
61
62 // Write user context to ensure acceptUnsetRatio is available
63 userCache, err := model.GetUserCache(userId)
64 if err != nil {
65 newAPIError = types.NewError(err, types.ErrorCodeQueryDataError)
66 return
67 }
68 userCache.WriteContext(c)
69
70 tempToken := &model.Token{
71 UserId: userId,
72 Name: fmt.Sprintf("playground-%s", group),
73 Group: group,
74 }
75 _ = middleware.SetupContextForToken(c, tempToken)

Callers

nothing calls this directly

Calls 10

ToOpenAIErrorMethod · 0.95
NewErrorFunction · 0.92
UnmarshalBodyReusableFunction · 0.92
GroupInUserUsableGroupsFunction · 0.92
GetUserCacheFunction · 0.92
SetupContextForTokenFunction · 0.92
SetContextKeyFunction · 0.92
getChannelFunction · 0.85
RelayFunction · 0.85
WriteContextMethod · 0.80

Tested by

no test coverage detected