Render history of conversation
This commit is contained in:
parent
4703b77dd4
commit
37ac2e235a
19
cli.go
19
cli.go
@ -3,7 +3,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/elk-language/go-prompt"
|
"github.com/elk-language/go-prompt"
|
||||||
|
"github.com/fatih/color"
|
||||||
"github.com/ollama/ollama/api"
|
"github.com/ollama/ollama/api"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,6 +23,10 @@ func onUserInput(input string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runAsCommandLine() {
|
func runAsCommandLine() {
|
||||||
|
for _, msg := range conversation {
|
||||||
|
fmt.Printf("%s: %s\n", colorRole(roleToInt(msg.Role)), msg.Content)
|
||||||
|
}
|
||||||
|
|
||||||
runner := prompt.New(
|
runner := prompt.New(
|
||||||
onUserInput,
|
onUserInput,
|
||||||
prompt.WithTitle("llamachat"),
|
prompt.WithTitle("llamachat"),
|
||||||
@ -41,3 +47,16 @@ func executeCommand(cli string) {
|
|||||||
}
|
}
|
||||||
fmt.Println("Unknown command")
|
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
14
main.go
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/ollama/ollama/api"
|
"github.com/ollama/ollama/api"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"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 {
|
func loadMessageFromDb() []api.Message {
|
||||||
dbMessages := GetMesages()
|
dbMessages := GetMesages()
|
||||||
var chatMessages []api.Message
|
var chatMessages []api.Message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user