Render history of conversation

This commit is contained in:
Sebastiaan de Schaetzen 2024-11-14 16:17:55 +01:00
parent 4703b77dd4
commit 37ac2e235a
2 changed files with 19 additions and 14 deletions

19
cli.go

@ -3,7 +3,9 @@ package main
import (
"fmt"
"github.com/elk-language/go-prompt"
"github.com/fatih/color"
"github.com/ollama/ollama/api"
"log"
"strings"
)
@ -21,6 +23,10 @@ func onUserInput(input string) {
}
func runAsCommandLine() {
for _, msg := range conversation {
fmt.Printf("%s: %s\n", colorRole(roleToInt(msg.Role)), msg.Content)
}
runner := prompt.New(
onUserInput,
prompt.WithTitle("llamachat"),
@ -41,3 +47,16 @@ func executeCommand(cli string) {
}
fmt.Println("Unknown command")
}
func colorRole(role MessageType) string {
if role == MT_SYSTEM {
return color.RedString("system")
} else if role == MT_ASSISTANT {
return color.GreenString("assistant")
} else if role == MT_USER {
return color.BlueString("user")
} else {
log.Fatalf("Invalid role type %d\n", role)
return ""
}
}

14
main.go

@ -4,7 +4,6 @@ import (
"context"
"flag"
"fmt"
"github.com/fatih/color"
"github.com/ollama/ollama/api"
"log"
"os"
@ -39,19 +38,6 @@ func roleToInt(role string) MessageType {
}
}
func colorRole(role MessageType) string {
if role == MT_SYSTEM {
return color.RedString("system")
} else if role == MT_ASSISTANT {
return color.GreenString("assistant")
} else if role == MT_USER {
return color.BlueString("user")
} else {
log.Fatalf("Invalid role type %d\n", role)
return ""
}
}
func loadMessageFromDb() []api.Message {
dbMessages := GetMesages()
var chatMessages []api.Message