feat: chunking + progress bar
This commit is contained in:
parent
0277157919
commit
68391cf532
6 changed files with 339 additions and 17 deletions
|
@ -8,16 +8,29 @@ import (
|
|||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// ChunkConfig stores configuration for chunked translation
|
||||
type ChunkConfig struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Size int `yaml:"size"`
|
||||
Prompt string `yaml:"prompt"`
|
||||
Context int `yaml:"context"`
|
||||
}
|
||||
|
||||
// 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"`
|
||||
APIBase string `yaml:"api_base"`
|
||||
APIKey string `yaml:"api_key"`
|
||||
Model string `yaml:"model"`
|
||||
SystemPrompt string `yaml:"system_prompt"`
|
||||
// Concurrency related settings
|
||||
Concurrency int `yaml:"concurrency"`
|
||||
// Chunk related settings
|
||||
Chunk ChunkConfig `yaml:"chunk"`
|
||||
}
|
||||
|
||||
// Default system prompt as a placeholder
|
||||
const DefaultSystemPrompt = "Placeholder"
|
||||
const DefaultChunkPrompt = "Please continue translation"
|
||||
|
||||
// LoadConfig loads configuration from ~/.config/d10n.yaml
|
||||
func LoadConfig() (*Config, error) {
|
||||
|
@ -34,6 +47,13 @@ func LoadConfig() (*Config, error) {
|
|||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
return &Config{
|
||||
SystemPrompt: DefaultSystemPrompt,
|
||||
Concurrency: 3, // Default concurrency
|
||||
Chunk: ChunkConfig{
|
||||
Enabled: false, // Chunking disabled by default
|
||||
Size: 10240, // Default chunk size in tokens
|
||||
Prompt: DefaultChunkPrompt, // Default chunk prompt
|
||||
Context: 2, // Default context size
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -49,10 +69,28 @@ func LoadConfig() (*Config, error) {
|
|||
return nil, fmt.Errorf("could not parse config file: %w", err)
|
||||
}
|
||||
|
||||
// Set default system prompt if not specified
|
||||
// Set default values if not specified
|
||||
if config.SystemPrompt == "" {
|
||||
config.SystemPrompt = DefaultSystemPrompt
|
||||
}
|
||||
|
||||
// Set default for concurrency
|
||||
if config.Concurrency <= 0 {
|
||||
config.Concurrency = 3
|
||||
}
|
||||
|
||||
// Set defaults for chunk settings
|
||||
if config.Chunk.Size <= 0 {
|
||||
config.Chunk.Size = 10240
|
||||
}
|
||||
|
||||
if config.Chunk.Prompt == "" {
|
||||
config.Chunk.Prompt = DefaultChunkPrompt
|
||||
}
|
||||
|
||||
if config.Chunk.Context <= 0 {
|
||||
config.Chunk.Context = 2
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue