Download controller/playground.go from AZILS/new-api: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/AZILS/new-api/resolve/main/controller/playground.go
- Command line
-
hf download hf://spaces/AZILS/new-api/controller/playground.go
-
curl -L -o playground.go https://huggingface.co/spaces/AZILS/new-api/resolve/main/controller/playground.go
1.59 kB
| package controller | |
| import ( | |
| "errors" | |
| "fmt" | |
| "time" | |
| "github.com/QuantumNous/new-api/common" | |
| "github.com/QuantumNous/new-api/constant" | |
| "github.com/QuantumNous/new-api/middleware" | |
| "github.com/QuantumNous/new-api/model" | |
| "github.com/QuantumNous/new-api/types" | |
| "github.com/gin-gonic/gin" | |
| ) | |
| func Playground(c *gin.Context) { | |
| var newAPIError *types.NewAPIError | |
| defer func() { | |
| if newAPIError != nil { | |
| c.JSON(newAPIError.StatusCode, gin.H{ | |
| "error": newAPIError.ToOpenAIError(), | |
| }) | |
| } | |
| }() | |
| useAccessToken := c.GetBool("use_access_token") | |
| if useAccessToken { | |
| newAPIError = types.NewError(errors.New("暂不支持使用 access token"), types.ErrorCodeAccessDenied, types.ErrOptionWithSkipRetry()) | |
| return | |
| } | |
| group := common.GetContextKeyString(c, constant.ContextKeyUsingGroup) | |
| modelName := c.GetString("original_model") | |
| userId := c.GetInt("id") | |
| // Write user context to ensure acceptUnsetRatio is available | |
| userCache, err := model.GetUserCache(userId) | |
| if err != nil { | |
| newAPIError = types.NewError(err, types.ErrorCodeQueryDataError, types.ErrOptionWithSkipRetry()) | |
| return | |
| } | |
| userCache.WriteContext(c) | |
| tempToken := &model.Token{ | |
| UserId: userId, | |
| Name: fmt.Sprintf("playground-%s", group), | |
| Group: group, | |
| } | |
| _ = middleware.SetupContextForToken(c, tempToken) | |
| _, newAPIError = getChannel(c, group, modelName, 0) | |
| if newAPIError != nil { | |
| return | |
| } | |
| //middleware.SetupContextForSelectedChannel(c, channel, playgroundRequest.Model) | |
| common.SetContextKey(c, constant.ContextKeyRequestStartTime, time.Now()) | |
| Relay(c, types.RelayFormatOpenAI) | |
| } | |