whole file

This commit is contained in:
Erik Winter 2024-06-12 08:01:44 +02:00
parent 7cc563ab05
commit 2861e5349d
3 changed files with 21 additions and 3 deletions

1
ollama-translate/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
test.md

View File

@ -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"))
}

View File

@ -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)