Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/QuantumNous/new-api/model"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetModelPricingConfig(c *gin.Context) {
|
|
snapshot, err := model.GetModelPricingSnapshot(c.QueryArray("model"))
|
|
if err != nil {
|
|
common.ApiError(c, err)
|
|
return
|
|
}
|
|
common.ApiSuccess(c, snapshot)
|
|
}
|
|
|
|
func UpdateModelPricingConfig(c *gin.Context) {
|
|
var request struct {
|
|
Changes []model.ModelPricingChange `json:"changes"`
|
|
}
|
|
if err := common.DecodeJson(c.Request.Body, &request); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": err.Error()})
|
|
return
|
|
}
|
|
if err := model.UpdateModelPricing(request.Changes); err != nil {
|
|
status := http.StatusBadRequest
|
|
if errors.Is(err, model.ErrModelPricingConflict) {
|
|
status = http.StatusConflict
|
|
}
|
|
c.JSON(status, gin.H{"success": false, "message": err.Error()})
|
|
return
|
|
}
|
|
names := make([]string, 0, len(request.Changes))
|
|
for _, change := range request.Changes {
|
|
names = append(names, change.ModelName)
|
|
}
|
|
recordManageAudit(c, "model.pricing.update", map[string]any{"models": names})
|
|
common.ApiSuccess(c, gin.H{"updated_models": names})
|
|
}
|