Refactor[Go Model Provider]: refactor baseURL and modelConfig (#15627)

### What problem does this PR solve?

As Title

### Type of change

- [x] Refactoring
This commit is contained in:
Haruko386
2026-06-04 17:50:22 +08:00
committed by GitHub
parent 04dc3bb19c
commit baeb0c0431
65 changed files with 2834 additions and 4410 deletions

View File

@@ -29,32 +29,32 @@ type BaseModel struct {
}
func (b *BaseModel) APIConfigCheck(apiConfig *APIConfig) error {
if apiConfig == nil || apiConfig.ApiKey == nil || *apiConfig.ApiKey == "" {
return fmt.Errorf("api key is nil or empty")
}
if apiConfig.BaseURL == nil || *apiConfig.BaseURL == "" {
if apiConfig.Region == nil || *apiConfig.Region == "" {
return fmt.Errorf("no base url and region")
}
if apiConfig == nil || apiConfig.ApiKey == nil || strings.TrimSpace(*apiConfig.ApiKey) == "" {
return fmt.Errorf("api key is required")
}
return nil
}
func (b *BaseModel) GetBaseURL(apiConfig *APIConfig) (string, error) {
if apiConfig.BaseURL != nil && *apiConfig.BaseURL != "" {
if apiConfig != nil && apiConfig.BaseURL != nil && *apiConfig.BaseURL != "" {
return strings.TrimSuffix(*apiConfig.BaseURL, "/"), nil
}
region := "default"
if apiConfig.Region != nil {
hasRegion := false
if apiConfig != nil && apiConfig.Region != nil {
hasRegion = true
region = *apiConfig.Region
}
baseURL, ok := b.BaseURL[region]
if !ok || baseURL == "" {
if (!hasRegion || region == "") && b.BaseURL != nil {
if defaultBaseURL, ok := b.BaseURL["default"]; ok && defaultBaseURL != "" {
return defaultBaseURL, nil
}
}
return "", fmt.Errorf("no base URL configured for region %q", region)
}