package main import ( "bufio" "errors" "fmt" "os" "strings" ) type RemoteChatApp struct { config RemoteChatConfiguration } func main() { configPath := os.Getenv("HOME") + "/.config/remote-chat/config.json" if _, err := os.Stat(configPath); errors.Is(err, os.ErrNotExist) { fmt.Printf("Config file %s doesn't exist\n", configPath) os.Exit(1) } cfg := GetClientConfig(configPath) var c = RemoteChatApp{config: cfg} model := cfg.Model if len(os.Args) > 1 { model = os.Args[1] } db, err := openDB(cfg.DbFile) if err != nil { fmt.Fprintf(os.Stderr, "❌ Cannot open database: %v\n", err) os.Exit(1) } defer db.Close() if err := initSchema(db); err != nil { fmt.Fprintf(os.Stderr, "❌ Cannot initialise schema: %v\n", err) os.Exit(1) } fmt.Printf("\n Ollama CLI Chat\n") fmt.Printf(" model : %s\n", model) fmt.Printf(" database : %s\n", cfg.DbFile) fmt.Printf(" commands : :history :model :quit\n") fmt.Printf("%s\n\n", strings.Repeat("─", 64)) scanner := bufio.NewScanner(os.Stdin) ch := make(chan result, 1) for { fmt.Print("πŸ‘€ You : ") if !scanner.Scan() { break } input := strings.TrimSpace(scanner.Text()) if input == "" { continue } switch { case input == ":quit" || input == ":exit" || input == ":q": fmt.Println("πŸ‘‹ Goodbye!") return case input == ":history": printHistory(db) continue case strings.HasPrefix(input, ":model "): model = strings.TrimPrefix(input, ":model ") fmt.Printf("βœ… Model switched to: %s\n\n", model) continue } fmt.Print("πŸ€– Bot : ⏳ thinking…") c.processMessage(db, input, model, ch) res := <-ch fmt.Print("\rπŸ€– Bot : ") if res.err != nil { fmt.Printf("❌ %v\n\n", res.err) } else { fmt.Printf("%s\n\n", strings.TrimSpace(res.text)) } } if err := scanner.Err(); err != nil { fmt.Fprintf(os.Stderr, "❌ Scanner: %v\n", err) } }