From 37ac2e235a0aa8a872050368c86442c38d641d01 Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Thu, 14 Nov 2024 16:17:55 +0100 Subject: [PATCH] Render history of conversation --- cli.go | 19 +++++++++++++++++++ main.go | 14 -------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cli.go b/cli.go index e2b9460..51f5eab 100644 --- a/cli.go +++ b/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 "" + } +} diff --git a/main.go b/main.go index e4e3b2c..0965af4 100644 --- a/main.go +++ b/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