- Add AI service with Anthropic, OpenAI, and Ollama providers - Add AI chat UI component with streaming responses - Add AI settings page for configuration - Add agent exec framework for command execution - Add API endpoints for AI chat and configuration
38 lines
931 B
Go
38 lines
931 B
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
|
|
|
|
default:
|
|
return nil, fmt.Errorf("unknown provider: %s", cfg.Provider)
|
|
}
|
|
}
|