feat(api): add provider creation endpoints and weight support

- Add `POST /admin/providers/preset` for streamlined creation of official providers (OpenAI, Anthropic, Gemini)
- Add `POST /admin/providers/custom` for generic OpenAI-compatible providers
- Add `weight` field to provider model and DTOs to enable weighted routing
- Update sync service to propagate provider weights
- Add unit tests for new creation handlers
This commit is contained in:
zenfun
2025-12-17 21:40:54 +08:00
parent 5a4e63b75d
commit 174735f152
8 changed files with 310 additions and 0 deletions

View File

@@ -74,6 +74,7 @@ func (h *Handler) CreateProvider(c *gin.Context) {
Status: status,
AutoBan: autoBan,
BanReason: req.BanReason,
Weight: req.Weight,
}
if !req.BanUntil.IsZero() {
tu := req.BanUntil.UTC()
@@ -162,6 +163,9 @@ func (h *Handler) UpdateProvider(c *gin.Context) {
if req.Models != nil {
update["models"] = strings.Join(req.Models, ",")
}
if req.Weight > 0 {
update["weight"] = req.Weight
}
if strings.TrimSpace(req.Group) != "" {
update["group"] = groupx.Normalize(req.Group)
}