feat: add domestic model provider presets
This commit is contained in:
@@ -362,7 +362,7 @@ func normalizeInput(input *CreateInput) {
|
||||
|
||||
func validateInput(input CreateInput) error {
|
||||
parsed, err := url.Parse(input.BaseURL)
|
||||
validProvider := input.Provider == "ark" || input.Provider == "openai_compatible"
|
||||
validProvider := extraction.SupportsCompatibleProvider(input.Provider)
|
||||
validURL := err == nil && parsed.Host != "" && (parsed.Scheme == "https" || (parsed.Scheme == "http" && isApprovedLocalModelHost(parsed.Hostname())))
|
||||
if !validUUID(input.TenantID) || len([]rune(input.DisplayName)) < 1 || len([]rune(input.DisplayName)) > 120 || !validProvider || !validURL || input.ModelID == "" || len(input.APIKey) < 8 || input.Temperature < 0 || input.Temperature > 2 || input.MaxTokens < 256 || input.MaxTokens > 8192 {
|
||||
return ErrInvalid
|
||||
|
||||
@@ -2,6 +2,33 @@ package contentmodel
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestValidateInputAcceptsSupportedDomesticProviders(t *testing.T) {
|
||||
providers := []string{"ark", "dashscope", "deepseek", "moonshot", "zhipu", "qianfan", "hunyuan", "minimax", "baichuan", "siliconflow"}
|
||||
for _, provider := range providers {
|
||||
t.Run(provider, func(t *testing.T) {
|
||||
input := CreateInput{
|
||||
TenantID: "10000000-0000-0000-0000-000000000001", DisplayName: provider,
|
||||
Provider: provider, BaseURL: "https://model.example.com/v1", ModelID: "summary-model",
|
||||
APIKey: "test-api-key", Temperature: 0.2, MaxTokens: 1200,
|
||||
}
|
||||
if err := validateInput(input); err != nil {
|
||||
t.Fatalf("supported provider was rejected: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateInputRejectsUnknownProvider(t *testing.T) {
|
||||
input := CreateInput{
|
||||
TenantID: "10000000-0000-0000-0000-000000000001", DisplayName: "unknown",
|
||||
Provider: "unknown", BaseURL: "https://model.example.com/v1", ModelID: "summary-model",
|
||||
APIKey: "test-api-key", Temperature: 0.2, MaxTokens: 1200,
|
||||
}
|
||||
if err := validateInput(input); err == nil {
|
||||
t.Fatal("unknown provider was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateInputAllowsComposeOllamaEndpoint(t *testing.T) {
|
||||
input := CreateInput{
|
||||
TenantID: "10000000-0000-0000-0000-000000000001", DisplayName: "本地 Qwen",
|
||||
|
||||
Reference in New Issue
Block a user