mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
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:
@@ -13,6 +13,7 @@ type ProviderDTO struct {
|
||||
Group string `json:"group"`
|
||||
Models []string `json:"models"` // List of supported model names
|
||||
Status string `json:"status"`
|
||||
Weight int `json:"weight,omitempty"`
|
||||
AutoBan *bool `json:"auto_ban,omitempty"`
|
||||
BanReason string `json:"ban_reason,omitempty"`
|
||||
BanUntil time.Time `json:"ban_until,omitempty"`
|
||||
|
||||
35
internal/dto/provider_create.go
Normal file
35
internal/dto/provider_create.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package dto
|
||||
|
||||
// ProviderPresetCreateDTO creates an official provider with sensible defaults.
|
||||
// For preset providers, base_url is derived automatically; users typically only provide api_key.
|
||||
type ProviderPresetCreateDTO struct {
|
||||
Preset string `json:"preset"` // openai | anthropic | gemini
|
||||
|
||||
// Optional fields.
|
||||
Name string `json:"name"`
|
||||
Group string `json:"group"`
|
||||
Models []string `json:"models"`
|
||||
|
||||
APIKey string `json:"api_key"`
|
||||
GoogleProject string `json:"google_project,omitempty"`
|
||||
GoogleLocation string `json:"google_location,omitempty"`
|
||||
|
||||
Status string `json:"status"`
|
||||
Weight int `json:"weight,omitempty"`
|
||||
AutoBan *bool `json:"auto_ban,omitempty"`
|
||||
}
|
||||
|
||||
// ProviderCustomCreateDTO creates an OpenAI-compatible provider.
|
||||
// For custom providers, base_url is required.
|
||||
type ProviderCustomCreateDTO struct {
|
||||
Name string `json:"name"`
|
||||
Group string `json:"group"`
|
||||
Models []string `json:"models"`
|
||||
|
||||
BaseURL string `json:"base_url"`
|
||||
APIKey string `json:"api_key"`
|
||||
|
||||
Status string `json:"status"`
|
||||
Weight int `json:"weight,omitempty"`
|
||||
AutoBan *bool `json:"auto_ban,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user