44 lines
774 B
Go
44 lines
774 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/elk-language/go-prompt"
|
|
"github.com/ollama/ollama/api"
|
|
"strings"
|
|
)
|
|
|
|
func onUserInput(input string) {
|
|
if strings.HasPrefix(input, "/") {
|
|
executeCommand(input)
|
|
return
|
|
}
|
|
fmt.Print(colorRole(MT_ASSISTANT), ": ")
|
|
sendPromptInput(input, func(r api.ChatResponse) error {
|
|
_, err := fmt.Print(r.Message.Content)
|
|
return err
|
|
})
|
|
fmt.Println()
|
|
}
|
|
|
|
func runAsCommandLine() {
|
|
runner := prompt.New(
|
|
onUserInput,
|
|
prompt.WithTitle("llamachat"),
|
|
prompt.WithPrefix("user: "),
|
|
prompt.WithCompleter(Completer),
|
|
)
|
|
|
|
runner.Run()
|
|
}
|
|
|
|
func executeCommand(cli string) {
|
|
args := strings.Split(cli, " ")
|
|
for _, cmd := range Commands {
|
|
if cmd.Name == args[0] {
|
|
cmd.Action(args)
|
|
return
|
|
}
|
|
}
|
|
fmt.Println("Unknown command")
|
|
}
|