diff --git a/config.yaml.example b/config.yaml.example index 13e1c82..9c740d5 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -13,6 +13,7 @@ ai: model: "anthropic/claude-2" # Other options: "openai/gpt-4", "google/palm-2" temperature: 0.7 # 0.0 to 1.0, lower for more focused responses max_tokens: 2000 # Adjust based on your needs and model limits + default_language: "English" # Fallback language when auto-detection fails (leave empty to disable) context: urls: diff --git a/config/config.go b/config/config.go index 6aed619..53da5ed 100644 --- a/config/config.go +++ b/config/config.go @@ -35,6 +35,7 @@ type AIConfig struct { Model string `yaml:"model"` Temperature float32 `yaml:"temperature"` MaxTokens int `yaml:"max_tokens"` + DefaultLanguage string `yaml:"default_language"` } type ContextConfig struct { diff --git a/internal/ai/ai.go b/internal/ai/ai.go index 61a8dc9..3ab77d4 100644 --- a/internal/ai/ai.go +++ b/internal/ai/ai.go @@ -99,7 +99,15 @@ func (a *AI) GenerateReply(emailContent string, contextContent map[string]string // First, detect the language lang, err := a.detectLanguage(emailContent) if err != nil { - return "", err + if a.config.DefaultLanguage != "" { + logger.WithFields(logrus.Fields{ + "error": err, + "defaultLanguage": a.config.DefaultLanguage, + }).Warn("Language detection failed, falling back to default language") + lang = a.config.DefaultLanguage + } else { + return "", err + } } // Build prompts using exposed methods