-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (67 loc) · 1.71 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
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/pranavmangal/termq/common"
"github.com/pranavmangal/termq/config"
"github.com/pranavmangal/termq/providers/cerebras"
"github.com/pranavmangal/termq/providers/gemini"
"github.com/pranavmangal/termq/providers/groq"
"github.com/briandowns/spinner"
"github.com/charmbracelet/glamour"
)
func main() {
args := os.Args
if len(args) < 2 {
fmt.Println("Please provide a query to run.")
return
}
s := spinner.New(spinner.CharSets[14], 20*time.Millisecond)
s.Start()
if !common.ModelCacheExists() {
common.CreateModelCache()
} else {
go func() {
common.UpdateModelCache()
}()
}
if !config.Exists() {
configFilePath := config.Create()
fmt.Println("No configuration file was found. It has been created for you at:")
fmt.Println(" " + configFilePath)
fmt.Println("Please fill atleast one provider and try again.")
return
}
cfg, err := config.Parse()
if err != nil {
log.Fatalf("The configuration is invalid: %v\nPlease fix the errors and try again.", err)
}
query := args[1]
var queryResp string
// Prefer fastest provider first
if cfg.Cerebras.Exists() {
queryResp, err = cerebras.RunQuery(query, cfg)
} else if cfg.Groq.Exists() {
queryResp, err = groq.RunQuery(query, cfg)
} else if cfg.Gemini.Exists() {
queryResp, err = gemini.RunQuery(query, cfg)
} else {
s.Stop()
fmt.Println("No provider is configured. Please configure one and try again.")
return
}
if err != nil {
s.Stop()
log.Fatalf("Error while running query: %v\n", err)
}
r, _ := glamour.NewTermRenderer(glamour.WithAutoStyle())
mdOutput, err := r.Render(queryResp)
s.Stop()
if err != nil {
fmt.Println(queryResp)
} else {
fmt.Println(mdOutput)
}
}