-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
68 lines (57 loc) · 1.34 KB
/
main.go
File metadata and controls
68 lines (57 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bufio"
"fmt"
"log"
"os"
"os/signal"
"slices"
"syscall"
"github.com/mrjxtr-dev/mr-aiCLI/config"
"github.com/mrjxtr-dev/mr-aiCLI/custom_errors"
)
func main() {
// Set up channel to listen for interrupt signals
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigChan
fmt.Printf("\n\nCTRL+C signal received, exiting!")
os.Exit(0)
}()
// Initialize client with configuration
client, err := config.LoadClient()
if err != nil {
log.Fatal(err)
}
fmt.Println("------------------------------")
fmt.Println(" Mr-AI Chat ")
fmt.Println("------------------------------")
// Set up input scanner
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Printf("\nYou: ")
if !scanner.Scan() {
break
}
userInput := scanner.Text()
// Check for exit commands
exitCmds := []string{"exit", "quit", "bye", "goodbye", "q"}
if slices.Contains(exitCmds, userInput) {
os.Exit(0)
}
// Send user input to OpenRouter
err := client.SendMessage(userInput)
if err != nil {
custom_errors.HandleError(err)
continue
}
// Display the last assistant response
for i := len(client.Messages) - 1; i >= 0; i-- {
if client.Messages[i].Role == "assistant" {
fmt.Printf("\nMr-AI: %s", client.Messages[i].Content)
break
}
}
}
}