Skip to content

Commit

Permalink
feat: add official feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Nov 28, 2023
1 parent 989e61c commit e862bf4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions manager/transhipment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type TranshipmentForm struct {
TopK *int `json:"top_k"`
Tools *globals.FunctionTools
ToolChoice *interface{}
Official bool `json:"official"`
}

type Choice struct {
Expand All @@ -49,7 +50,7 @@ type TranshipmentResponse struct {
Model string `json:"model"`
Choices []Choice `json:"choices"`
Usage Usage `json:"usage"`
Quota float32 `json:"quota"`
Quota *float32 `json:"quota,omitempty"`
}

type ChoiceDelta struct {
Expand All @@ -65,7 +66,7 @@ type TranshipmentStreamResponse struct {
Model string `json:"model"`
Choices []ChoiceDelta `json:"choices"`
Usage Usage `json:"usage"`
Quota float32 `json:"quota"`
Quota *float32 `json:"quota,omitempty"`
}

func ModelAPI(c *gin.Context) {
Expand Down Expand Up @@ -116,6 +117,11 @@ func TranshipmentAPI(c *gin.Context) {
}
}

if strings.HasSuffix(form.Model, "-official") {
form.Model = strings.TrimSuffix(form.Model, "-official")
form.Official = true
}

check, plan := auth.CanEnableModelWithSubscription(db, cache, user, form.Model)
if !check {
c.JSON(http.StatusForbidden, gin.H{
Expand Down Expand Up @@ -185,7 +191,7 @@ func sendTranshipmentResponse(c *gin.Context, form TranshipmentForm, id string,
CompletionTokens: buffer.CountOutputToken(),
TotalTokens: buffer.CountToken(),
},
Quota: buffer.GetQuota(),
Quota: utils.Multi[*float32](form.Official, nil, utils.ToPtr(buffer.GetQuota())),
})
}

Expand All @@ -210,7 +216,7 @@ func getStreamTranshipmentForm(id string, created int64, form TranshipmentForm,
CompletionTokens: utils.MultiF(end, func() int { return buffer.CountOutputToken() }, 0),
TotalTokens: utils.MultiF(end, func() int { return buffer.CountToken() }, 0),
},
Quota: buffer.GetQuota(),
Quota: utils.Multi[*float32](form.Official, nil, utils.ToPtr(buffer.GetQuota())),
}
}

Expand Down

0 comments on commit e862bf4

Please sign in to comment.