feat: add IsUnset method to LLMProvider

Introduced a new method to check if an LLM provider is considered unset:
- Added Unset field to LLMProvider struct
- Implemented IsUnset() method with logic to validate provider configuration
- Handles special cases for different provider types (azure-openai, openai-compatible)
- Checks for empty API key, missing models, and provider-specific configuration requirements
This commit is contained in:
Marvin Zhang
2025-03-10 17:50:57 +08:00
parent acacd2577e
commit b86818bbfb

View File

@@ -11,4 +11,21 @@ type LLMProvider struct {
ApiBaseUrl string `json:"api_base_url" bson:"api_base_url"` // API base URL for the provider
ApiVersion string `json:"api_version" bson:"api_version"` // API version for the provider
Models []string `json:"models" bson:"models"` // Models supported by this provider
Unset bool `json:"unset" bson:"-"` // Whether the provider is unset
}
func (p *LLMProvider) IsUnset() bool {
if p.ApiKey == "" {
return true
}
if len(p.Models) == 0 {
return true
}
switch p.Key {
case "azure-openai":
return p.ApiBaseUrl == "" && p.ApiVersion == ""
case "openai-compatible":
return p.ApiBaseUrl == ""
}
return false
}