-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
98 lines (78 loc) · 1.92 KB
/
main.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
// Main version
import (
"bufio"
"fmt"
"log"
"os"
"strings"
"github.com/joho/godotenv"
)
type Config struct {
API_KEY string
WD string
SAVE bool
SAVEPATH string
}
func main() {
err := godotenv.Load()
if err != nil {
if strings.Contains(err.Error(), "no such file or directory") {
log.Println("You do not have an .env file in this dir, make sure your linux enviroment have GEMINI_API_KEY exported, or create an env file ")
}
log.Println(err)
}
wd, err := os.Getwd()
if err != nil {
log.Println(err)
}
apiKey := os.Getenv("GEMINI_API_KEY")
if apiKey == "" {
log.Println("empty API_KEY")
return
}
savegochatstr := os.Getenv("SAVE_GO_CHAT")
savegochat := false
if savegochatstr == "true" {
savegochat = true
}
config := Config{
API_KEY: apiKey,
WD: wd,
SAVE: savegochat,
}
fmt.Println("Welcome to GOCHAT, Your low budget copilot :) ......, You can always run help command for helps and manual ")
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Print("Input your prompt ...... ")
scanner.Scan()
text := scanner.Text()
if len(text) == 0 {
continue
}
cleaned := cleanText(text)
command := cleaned[0]
switch command {
case "help":
// Handle the help command
fmt.Println(`
------Welcome to gochats , here are neccesary details.--------
Expect more functionalities soon.
If you set SAVE_GO_CHAT=true in env your chats will be saved as md files at $HOMEDIR/gochat/data/chats.
tips:
if you use vscode run '$HOMEDIR/gochat/data/chats' , so you can see each of your chats as an md file.
Incoming functionality:
add history and only create new file whe you called the tab command.
for now this should serve as a good helper on the terminal
`)
default:
// Handle other commands
config.chat(text)
}
}
}
func cleanText(s string) []string {
s = strings.ToLower(s)
words := strings.Split(s, " ")
return words
}