Skip to content

Commit

Permalink
refactor(internal/config): remove memory configuration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nullswan committed Oct 5, 2024
1 parent 6469ccf commit 4e12c27
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 92 deletions.
16 changes: 1 addition & 15 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand All @@ -93,8 +82,5 @@ func defaultConfig() Config {
Path: filepath.Join(convDir, "output.sqlite.db"),
},
},
Memory: MemoryConfig{
Mode: MemoryModeNone,
},
}
}
17 changes: 17 additions & 0 deletions internal/config/consts.go
Original file line number Diff line number Diff line change
@@ -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()
}
5 changes: 0 additions & 5 deletions internal/config/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
23 changes: 0 additions & 23 deletions internal/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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:
Expand Down Expand Up @@ -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
}
32 changes: 0 additions & 32 deletions internal/config/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
}
22 changes: 5 additions & 17 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ 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 {
Markdown OutputDetailConfig `yaml:"markdown" json:"markdown"`
Sqlite OutputDetailConfig `yaml:"sqlite" json:"sqlite"`
}

type MemoryConfig struct {
Mode MemoryMode `yaml:"mode" json:"mode"`
}

type EnabledConfig struct {
Enabled bool `yaml:"enabled" json:"enabled"`
}
Expand All @@ -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)
}

0 comments on commit 4e12c27

Please sign in to comment.