init
This commit is contained in:
commit
0277157919
7 changed files with 477 additions and 0 deletions
58
config/config.go
Normal file
58
config/config.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue