- Implement 'Show Problems Only' toggle combining degraded status, high CPU/memory alerts, and needs backup filters - Add 'Investigate with AI' button to filter bar for problematic guests - Fix dashboard column sizing inconsistencies between bars and sparklines view modes - Fix PBS backups display and polling - Refine AI prompt for general-purpose usage - Fix frontend flickering and reload loops during initial load - Integrate persistent SQLite metrics store with Monitor - Fortify AI command routing with improved validation and logging - Fix CSRF token handling for note deletion - Debug and fix AI command execution issues - Various AI reliability improvements and command safety enhancements
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package providers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/config"
|
|
)
|
|
|
|
// NewFromConfig creates a Provider based on the AIConfig settings
|
|
func NewFromConfig(cfg *config.AIConfig) (Provider, error) {
|
|
if cfg == nil {
|
|
return nil, fmt.Errorf("AI config is nil")
|
|
}
|
|
|
|
if !cfg.Enabled {
|
|
return nil, fmt.Errorf("AI is not enabled")
|
|
}
|
|
|
|
switch cfg.Provider {
|
|
case config.AIProviderAnthropic:
|
|
if cfg.APIKey == "" {
|
|
return nil, fmt.Errorf("Anthropic API key is required")
|
|
}
|
|
return NewAnthropicClient(cfg.APIKey, cfg.GetModel()), nil
|
|
|
|
case config.AIProviderOpenAI:
|
|
if cfg.APIKey == "" {
|
|
return nil, fmt.Errorf("OpenAI API key is required")
|
|
}
|
|
return NewOpenAIClient(cfg.APIKey, cfg.GetModel(), cfg.GetBaseURL()), nil
|
|
|
|
case config.AIProviderOllama:
|
|
return NewOllamaClient(cfg.GetModel(), cfg.GetBaseURL()), nil
|
|
|
|
case config.AIProviderDeepSeek:
|
|
if cfg.APIKey == "" {
|
|
return nil, fmt.Errorf("DeepSeek API key is required")
|
|
}
|
|
// DeepSeek uses OpenAI-compatible API
|
|
return NewOpenAIClient(cfg.APIKey, cfg.GetModel(), cfg.GetBaseURL()), nil
|
|
|
|
default:
|
|
return nil, fmt.Errorf("unknown provider: %s", cfg.Provider)
|
|
}
|
|
}
|