58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// Config stores the application configuration
|
|
type Config struct {
|
|
APIBase string `yaml:"api_base"`
|
|
APIKey string `yaml:"api_key"`
|
|
Model string `yaml:"model"`
|
|
SystemPrompt string `yaml:"system_prompt"`
|
|
}
|
|
|
|
// Default system prompt as a placeholder
|
|
const DefaultSystemPrompt = "Placeholder"
|
|
|
|
// LoadConfig loads configuration from ~/.config/d10n.yaml
|
|
func LoadConfig() (*Config, error) {
|
|
// Get user's home directory
|
|
homeDir, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not get home directory: %w", err)
|
|
}
|
|
|
|
// Default config path
|
|
configPath := filepath.Join(homeDir, ".config", "d10n.yaml")
|
|
|
|
// Check if config file exists
|
|
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
|
return &Config{
|
|
SystemPrompt: DefaultSystemPrompt,
|
|
}, nil
|
|
}
|
|
|
|
// Read config file
|
|
data, err := os.ReadFile(configPath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not read config file: %w", err)
|
|
}
|
|
|
|
// Parse config
|
|
var config Config
|
|
if err := yaml.Unmarshal(data, &config); err != nil {
|
|
return nil, fmt.Errorf("could not parse config file: %w", err)
|
|
}
|
|
|
|
// Set default system prompt if not specified
|
|
if config.SystemPrompt == "" {
|
|
config.SystemPrompt = DefaultSystemPrompt
|
|
}
|
|
|
|
return &config, nil
|
|
}
|