whole file
This commit is contained in:
parent
7cc563ab05
commit
2861e5349d
|
@ -0,0 +1 @@
|
||||||
|
test.md
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -11,6 +12,10 @@ var (
|
||||||
model = flag.String("m", "llama3", "model file")
|
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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *inputFile == "" {
|
if *inputFile == "" {
|
||||||
|
@ -23,11 +28,24 @@ func main() {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
ollama := NewOllama(ollamaHost)
|
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 {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
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"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ func (o *Ollama) Generate(model, prompt string) (string, error) {
|
||||||
}{
|
}{
|
||||||
Model: model,
|
Model: model,
|
||||||
Prompt: prompt,
|
Prompt: prompt,
|
||||||
Format: "json",
|
|
||||||
Stream: false,
|
Stream: false,
|
||||||
}
|
}
|
||||||
reqBodyJSON, err := json.Marshal(reqBody)
|
reqBodyJSON, err := json.Marshal(reqBody)
|
||||||
|
|
Loading…
Reference in New Issue