-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
81 lines (69 loc) · 2.36 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
package main
import (
"log"
"strings"
"github.com/Justin-Fernbaugh/FinSight/handlers"
llm "github.com/Justin-Fernbaugh/FinSight/pkg"
"github.com/brunomvsouza/ynab.go"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
serviceName = "FinSight"
)
var (
command = &cobra.Command {
Use: serviceName,
Run: run,
}
projectID string
location string
modelName string
ynabClientID string
ynabToken string
tgBotToken string
tgUserID int64
daysBack int
databaseName string
)
func init() {
command.Flags().StringVar(&projectID, "project-id", "", "The GCP project ID (required)")
command.Flags().StringVar(&ynabClientID, "ynab-client-id", "", "The YNAB application client ID (required)")
command.Flags().StringVar(&ynabToken, "ynab-token", "", "The YNAB client secret (required)")
command.Flags().StringVar(&databaseName, "database-name", "", "The GCP Firestore database name (required)")
command.Flags().StringVar(&tgBotToken, "tg-bot-token", "", "The Telegram bot token (required)")
command.Flags().Int64Var(&tgUserID, "tg-user-id", 0, "The Telegram user ID to send the msg (required)")
command.Flags().StringVar(&location, "location", "us-west1", "The GCP location")
command.Flags().IntVar(&daysBack, "days-back", 7, "The number of days back to retrieve transactions")
command.Flags().StringVar(&modelName, "model-name", "gemini-1.5-flash-001", "The LLM model name")
// Mark the flags as required
for _, flag := range []string{"ynab-token", "tg-bot-token", "tg-user-id", "project-id"} {
err := command.MarkFlagRequired(flag)
if err != nil {
log.Fatalf("Error marking flag %s as required: %v", flag, err)
}
}
viper.BindPFlags(command.Flags())
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
}
func run(cmd *cobra.Command, args []string) {
log.Println("Starting FinSight ...")
_, err := handlers.NewBotHandler(tgBotToken)
if err != nil {
log.Fatalf("Error creating bot handler: %v", err)
}
gemini, err := llm.Handler(projectID, location, modelName, daysBack)
if err != nil {
log.Fatalf("Error creating LLM handler: %v", err)
}
ynabClient := ynab.NewClient(ynabToken)
if err := handlers.NewHandler(ynabClient, gemini, tgUserID, daysBack); err != nil {
log.Fatalf("Error creating handler: %v", err)
}
log.Println("FinSight exiting ...")
}
func main() {
// run the command
command.Execute()
}