diff --git a/ollama-translate/.gitignore b/ollama-translate/.gitignore new file mode 100644 index 0000000..7545a50 --- /dev/null +++ b/ollama-translate/.gitignore @@ -0,0 +1 @@ +test.md \ No newline at end of file diff --git a/ollama-translate/main.go b/ollama-translate/main.go index 5f59eb1..86ed095 100644 --- a/ollama-translate/main.go +++ b/ollama-translate/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "strings" ) var ( @@ -11,6 +12,10 @@ var ( model = flag.String("m", "llama3", "model file") ) +const ( + promptStart = `Could you translate the following text into English? Try te preserve the original tone of voice as much as possible. Only answer with the translation itself, no additional comments needed.` +) + func main() { flag.Parse() if *inputFile == "" { @@ -23,11 +28,24 @@ func main() { os.Exit(1) } ollama := NewOllama(ollamaHost) - res, err := ollama.Generate(*model, "Could you translate the following text into English? 'Mijn fietsband is lek. Wat moet ik nu doen'") + + doc, err := os.ReadFile(*inputFile) if err != nil { fmt.Println(err) os.Exit(1) } - fmt.Println(res) + translated := make([]string, 0) + for _, chunk := range strings.Split(string(doc), "\n\n") { + prompt := fmt.Sprintf("%s\n---\n%s", promptStart, chunk) + res, err := ollama.Generate(*model, prompt) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Printf(".") + translated = append(translated, res) + } + + fmt.Printf("\n\n%s\n", strings.Join(translated, "\n")) } diff --git a/ollama-translate/ollama.go b/ollama-translate/ollama.go index 6fd31ac..d134f72 100644 --- a/ollama-translate/ollama.go +++ b/ollama-translate/ollama.go @@ -30,7 +30,6 @@ func (o *Ollama) Generate(model, prompt string) (string, error) { }{ Model: model, Prompt: prompt, - Format: "json", Stream: false, } reqBodyJSON, err := json.Marshal(reqBody)