test(config): add migration tests for litellm provider
Some checks failed
CI / build-and-test (push) Failing after -32m22s
Some checks failed
CI / build-and-test (push) Failing after -32m22s
* Implement tests for migrating configuration from v1 to v2 for the litellm provider. * Validate the structure and values of the migrated configuration. * Ensure migration rejects newer versions of the configuration. fix(validate): enhance AI provider validation logic * Consolidate provider validation into a dedicated method. * Ensure at least one provider is specified and validate its type. * Check for required fields based on provider type. fix(mcpserver): update tool set to use new enrichment tool * Replace RetryMetadataTool with RetryEnrichmentTool in the ToolSet. fix(tools): refactor tools to use embedding and metadata runners * Update tools to utilize EmbeddingRunner and MetadataRunner instead of Provider. * Adjust method calls to align with the new runner interfaces.
This commit is contained in:
@@ -45,38 +45,8 @@ func (c Config) Validate() error {
|
||||
return fmt.Errorf("invalid config: mcp.session_timeout must be greater than zero")
|
||||
}
|
||||
|
||||
switch c.AI.Provider {
|
||||
case "litellm", "ollama", "openrouter":
|
||||
default:
|
||||
return fmt.Errorf("invalid config: unsupported ai.provider %q", c.AI.Provider)
|
||||
}
|
||||
|
||||
if c.AI.Embeddings.Dimensions <= 0 {
|
||||
return fmt.Errorf("invalid config: ai.embeddings.dimensions must be greater than zero")
|
||||
}
|
||||
|
||||
switch c.AI.Provider {
|
||||
case "litellm":
|
||||
if strings.TrimSpace(c.AI.LiteLLM.BaseURL) == "" {
|
||||
return fmt.Errorf("invalid config: ai.litellm.base_url is required when ai.provider=litellm")
|
||||
}
|
||||
if strings.TrimSpace(c.AI.LiteLLM.APIKey) == "" {
|
||||
return fmt.Errorf("invalid config: ai.litellm.api_key is required when ai.provider=litellm")
|
||||
}
|
||||
case "ollama":
|
||||
if strings.TrimSpace(c.AI.Ollama.BaseURL) == "" {
|
||||
return fmt.Errorf("invalid config: ai.ollama.base_url is required when ai.provider=ollama")
|
||||
}
|
||||
if strings.TrimSpace(c.AI.Ollama.APIKey) == "" {
|
||||
return fmt.Errorf("invalid config: ai.ollama.api_key is required when ai.provider=ollama")
|
||||
}
|
||||
case "openrouter":
|
||||
if strings.TrimSpace(c.AI.OpenRouter.BaseURL) == "" {
|
||||
return fmt.Errorf("invalid config: ai.openrouter.base_url is required when ai.provider=openrouter")
|
||||
}
|
||||
if strings.TrimSpace(c.AI.OpenRouter.APIKey) == "" {
|
||||
return fmt.Errorf("invalid config: ai.openrouter.api_key is required when ai.provider=openrouter")
|
||||
}
|
||||
if err := c.AI.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.Server.Port <= 0 {
|
||||
@@ -108,3 +78,61 @@ func (c Config) Validate() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a AIConfig) validate() error {
|
||||
if len(a.Providers) == 0 {
|
||||
return fmt.Errorf("invalid config: ai.providers must contain at least one entry")
|
||||
}
|
||||
for name, p := range a.Providers {
|
||||
if strings.TrimSpace(name) == "" {
|
||||
return fmt.Errorf("invalid config: ai.providers contains an entry with an empty name")
|
||||
}
|
||||
switch p.Type {
|
||||
case "litellm", "ollama", "openrouter":
|
||||
default:
|
||||
return fmt.Errorf("invalid config: ai.providers.%s.type %q is not supported", name, p.Type)
|
||||
}
|
||||
if strings.TrimSpace(p.BaseURL) == "" {
|
||||
return fmt.Errorf("invalid config: ai.providers.%s.base_url is required", name)
|
||||
}
|
||||
if strings.TrimSpace(p.APIKey) == "" {
|
||||
return fmt.Errorf("invalid config: ai.providers.%s.api_key is required", name)
|
||||
}
|
||||
}
|
||||
|
||||
if a.Embeddings.Dimensions <= 0 {
|
||||
return fmt.Errorf("invalid config: ai.embeddings.dimensions must be greater than zero")
|
||||
}
|
||||
|
||||
if err := a.validateChain("ai.embeddings", a.Embeddings.Chain()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := a.validateChain("ai.metadata", a.Metadata.Chain()); err != nil {
|
||||
return err
|
||||
}
|
||||
if a.Background != nil {
|
||||
if a.Background.Embeddings != nil {
|
||||
if err := a.validateChain("ai.background.embeddings", a.Background.Embeddings.AsTargets()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if a.Background.Metadata != nil {
|
||||
if err := a.validateChain("ai.background.metadata", a.Background.Metadata.AsTargets()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a AIConfig) validateChain(prefix string, chain []RoleTarget) error {
|
||||
if len(chain) == 0 {
|
||||
return fmt.Errorf("invalid config: %s.primary must reference a configured provider and model", prefix)
|
||||
}
|
||||
for i, target := range chain {
|
||||
if _, ok := a.Providers[target.Provider]; !ok {
|
||||
return fmt.Errorf("invalid config: %s[%d] references unknown provider %q", prefix, i, target.Provider)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user