From b86818bbfb4963daa122674f61367f7bda26a26f Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Mon, 10 Mar 2025 17:50:57 +0800 Subject: [PATCH] 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 --- core/models/models/llm_provider.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/models/models/llm_provider.go b/core/models/models/llm_provider.go index 5acbf6c7..2c74d8f6 100644 --- a/core/models/models/llm_provider.go +++ b/core/models/models/llm_provider.go @@ -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 }