mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-04 06:40:29 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user