Skip to content

Commit

Permalink
feat(translation): enhance translation system and add metadata tracking
Browse files Browse the repository at this point in the history
- Update translation logic for improved results
- Implement metadata tracking (total calls, last used time, model usage, prompt examples, token usage)
- Add retry logic for failed translations
- Improve translation validation
- Upgrade Anthropic client to new beta version with prompt caching
- Update go-anthropic library to v2.6.0
  • Loading branch information
duocnv-firegroup committed Aug 22, 2024
1 parent e1484ca commit e6a22b4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func runTranslate(cmd *cobra.Command, args []string) error {
anthropicTranslator, err := translator.GetAnthropicTranslator(&translator.Config{
APIKey: os.Getenv("ANTHROPIC_KEY"),
Model: cmd.Flag("model").Value.String(),
Temperature: 0.3,
Temperature: 0.7,
MaxTokens: 4096,
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func worker(ctx context.Context, jobs <-chan string, results chan<- error, proce
}
}

var excludeRegex = regexp.MustCompile(`(?i)(preface|introduction|foreword|prologue|toc|table\s*of\s*contents|title|cover|copyright|colophon|dedication|acknowledgements?|about\s*the\s*author|bibliography|glossary|index|appendix|notes?|footnotes?|endnotes?|references|epub-meta|metadata|nav|ncx|opf|front\s*matter|back\s*matter|halftitle|frontispiece|epigraph|list\s*of\s*(figures|tables|illustrations)|copyright\s*page|series\s*page|reviews|praise\s*for|also\s*by\s*the\s*author|author\s*bio|publication\s*info|imprint|credits|permissions|disclaimer|errata|synopsis|summary)`)
var excludeRegex = regexp.MustCompile(`(?i)(preface|introduction|foreword|prologue|toc|table\s*of\s*contents|title|cover|copyright|colophon|dedication|acknowledgements?|about\s*the\s*author|bibliography|glossary|index|appendix|notes?|footnotes?|endnotes?|references|epub-meta|metadata|nav|ncx|opf|front\s*matter|back\s*matter|halftitle|frontispiece|epigraph|list\s*of\s*(figures|tables|illustrations)|copyright\s*page|series\s*page|reviews|praise|also\s*by\s*the\s*author|author\s*bio|publication\s*info|imprint|credits|permissions|disclaimer|errata|synopsis|summary)`)

// ShouldExcludeFile determines if a file should be excluded based on its name
func ShouldExcludeFile(fileName string) bool {
Expand Down
3 changes: 2 additions & 1 deletion pkg/translator/anthropic.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ type Anthropic struct {
func createTranslationSystem(source, target string) string {
return fmt.Sprintf(`Translation guidelines:
- Preserve HTML structure
- Writing style: Clear, concise, professional, technical, Use %[2]s flexibly, fluently and softly Use active voice and maintain logical flow.
- Writing style: Clear, concise, professional, technical, Use %[2]s flexibly, fluently and softly.
- Use active voice and maintain logical flow.
- Translation approach:
• Translate for meaning, not word-for-word
• Adapt idioms and cultural references to %[2]s equivalents
Expand Down

0 comments on commit e6a22b4

Please sign in to comment.