From 4e12c2712b22023095482bfc9f9fa90eb9d63fee Mon Sep 17 00:00:00 2001 From: nullswan Date: Sat, 5 Oct 2024 22:25:46 +0200 Subject: [PATCH] refactor(internal/config): remove memory configuration handling --- internal/config/config.go | 16 +--------------- internal/config/consts.go | 17 +++++++++++++++++ internal/config/paths.go | 5 ----- internal/config/set.go | 23 ----------------------- internal/config/setup.go | 32 -------------------------------- internal/config/types.go | 22 +++++----------------- 6 files changed, 23 insertions(+), 92 deletions(-) create mode 100644 internal/config/consts.go diff --git a/internal/config/config.go b/internal/config/config.go index 732bf5c..3d4cd18 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,14 +8,8 @@ import ( "gopkg.in/yaml.v2" ) -var configFilePath string - -func init() { - configFilePath = getConfigFilePath() -} - func getConfigFilePath() string { - return filepath.Join(GetDataDir(), "config.yml") + return filepath.Join(GetDataDir(), configFileName) } // ConfigExists checks if the configuration file exists. @@ -70,17 +64,12 @@ func SaveConfig(cfg *Config) error { return nil } -const ( - defaultConversationDir = "conversations" -) - // defaultConfig returns the default configuration. func defaultConfig() Config { convDir := GetDataSubdir(defaultConversationDir) return Config{ Input: InputConfig{ - Text: EnabledConfig{Enabled: true}, Voice: EnabledConfig{Enabled: true}, }, Output: OutputConfig{ @@ -93,8 +82,5 @@ func defaultConfig() Config { Path: filepath.Join(convDir, "output.sqlite.db"), }, }, - Memory: MemoryConfig{ - Mode: MemoryModeNone, - }, } } diff --git a/internal/config/consts.go b/internal/config/consts.go new file mode 100644 index 0000000..edc01db --- /dev/null +++ b/internal/config/consts.go @@ -0,0 +1,17 @@ +package config + +const ( + defaultConversationDir = "conversations" + + // configDir is the directory where the configuration file is stored. + configDir = ".golem" + + // configFileName is the name of the configuration file. + configFileName = "config.yml" +) + +var configFilePath string + +func init() { + configFilePath = getConfigFilePath() +} diff --git a/internal/config/paths.go b/internal/config/paths.go index 1a77144..275f9f0 100644 --- a/internal/config/paths.go +++ b/internal/config/paths.go @@ -6,11 +6,6 @@ import ( "runtime" ) -const ( - // configDir is the directory where the configuration file is stored. - configDir = ".golem" -) - // GetHomeDir returns the user's home directory. func GetHomeDir() string { if runtime.GOOS == "windows" { diff --git a/internal/config/set.go b/internal/config/set.go index f41f30d..fc9d126 100644 --- a/internal/config/set.go +++ b/internal/config/set.go @@ -14,8 +14,6 @@ func SetConfigValue(cfg *Config, key string, value string) error { err = setInputConfigValue(&cfg.Input, keys[1:], value) case "output": err = setOutputConfigValue(&cfg.Output, keys[1:], value) - case "memory": - err = setMemoryConfigValue(&cfg.Memory, keys[1:], value) default: err = fmt.Errorf("unknown configuration key '%s'", key) } @@ -32,8 +30,6 @@ func setInputConfigValue( } var enabled *bool switch keys[0] { - case "text": - enabled = &input.Text.Enabled case "voice": enabled = &input.Voice.Enabled default: @@ -95,22 +91,3 @@ func setOutputDetailConfigValue( } return nil } - -func setMemoryConfigValue( - memory *MemoryConfig, - keys []string, - value string, -) error { - if len(keys) != 1 || keys[0] != "mode" { - return fmt.Errorf("invalid key for memory: %v", keys) - } - switch MemoryMode(value) { - case - MemoryModeConversation, - MemoryModeNone: - memory.Mode = MemoryMode(value) - default: - return fmt.Errorf("invalid value for memory.mode") - } - return nil -} diff --git a/internal/config/setup.go b/internal/config/setup.go index 1492053..238609d 100644 --- a/internal/config/setup.go +++ b/internal/config/setup.go @@ -11,10 +11,6 @@ func Setup() error { cfg := defaultConfig() fmt.Println("Starting configuration setup...") - cfg.Input.Text.Enabled = promptForBool( - "Enable text input", - cfg.Input.Text.Enabled, - ) cfg.Input.Voice.Enabled = promptForBool( "Enable voice input", cfg.Input.Voice.Enabled, @@ -42,23 +38,6 @@ func Setup() error { ) } - memoryModes := []MemoryMode{ - MemoryModeConversation, - MemoryModeNone, - } - memoryModeLabels := []string{ - "Knowledge Graph", - "Entity", - "Conversation", - "None", - } - modeIndex := promptForSelect( - "Choose memory mode", - memoryModeLabels, - getDefaultMemoryModeIndex(cfg.Memory.Mode), - ) - cfg.Memory.Mode = memoryModes[modeIndex] - if err := SaveConfig(&cfg); err != nil { return err } @@ -116,14 +95,3 @@ func promptForSelect(label string, items []string, defaultIndex int) int { } return index } - -func getDefaultMemoryModeIndex(mode MemoryMode) int { - switch mode { - case MemoryModeConversation: - return 2 - case MemoryModeNone: - return 3 - default: - return 3 // Default to 'None' if unrecognized - } -} diff --git a/internal/config/types.go b/internal/config/types.go index 0167361..3044c0e 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -3,12 +3,15 @@ package config type Config struct { Input InputConfig `yaml:"input" json:"input"` Output OutputConfig `yaml:"output" json:"output"` - Memory MemoryConfig `yaml:"memory" json:"memory"` + // TODO(nullswan): Add memory configuration } +// Manage the input sources type InputConfig struct { - Text EnabledConfig `yaml:"text" json:"text"` Voice EnabledConfig `yaml:"voice" json:"voice"` + // TODO(nullswan): Differentiate between real-tme voice and alway-on voice + // TODO(nullswan): Add video input + // TODO(nullswan): Add image input } type OutputConfig struct { @@ -16,10 +19,6 @@ type OutputConfig struct { Sqlite OutputDetailConfig `yaml:"sqlite" json:"sqlite"` } -type MemoryConfig struct { - Mode MemoryMode `yaml:"mode" json:"mode"` -} - type EnabledConfig struct { Enabled bool `yaml:"enabled" json:"enabled"` } @@ -28,14 +27,3 @@ type OutputDetailConfig struct { Enabled bool `yaml:"enabled" json:"enabled"` Path string `yaml:"path" json:"path"` } - -type MemoryMode string - -const ( - MemoryModeConversation MemoryMode = "conversation" - MemoryModeNone MemoryMode = "none" -) - -func (m MemoryMode) String() string { - return string(m) -}