-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
75 lines (60 loc) · 1.98 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
package main
import (
"flag"
"fmt"
"log"
"os"
"gopkg.in/yaml.v3"
)
// loadConfig loads the server configuration from a file.
func loadConfig(configPath string) ServerConfig {
// Try to read the specified config file
configFile, err := os.ReadFile(configPath)
if err != nil {
fmt.Printf("[Init] Could not read specified config file: %s\n", configPath)
fmt.Println("[Init] Trying default config file: config.yaml")
// Try to read the default config file
configFile, err = os.ReadFile("config.yaml")
if err != nil {
fmt.Println("[Init] Error: No config file found.")
fmt.Println("Usage: ./program --config [path_to_config_file]")
fmt.Println("If no config file is specified, the program will try to use 'config.yaml' in the current directory.")
os.Exit(1)
}
}
fmt.Printf("[Init] Using config file: %s\n", configPath)
// Parse the configuration
var config ServerConfig
err = yaml.Unmarshal(configFile, &config)
if err != nil {
log.Fatalf("[Init] Error parsing config file: %v", err)
}
return config
}
func main() {
// Define command-line flags
configPath := flag.String("config", "config.yaml", "Path to the config file")
llmDebug := flag.Bool("llm-local-debug", false, "Enable local debug mode for LLM, preventing requests to the LLM endpoint")
// Parse command-line flags
flag.Parse()
// Print debug information if --llm-debug flag is set
if *llmDebug {
fmt.Println("[Init] LLM Local Debug mode is enabled. Requests won't be sent to the LLM endpoint.")
}
// Load the configuration
config := loadConfig(*configPath)
// Create a new chatbot instance
bot := NewChatbotFromConfig(config)
llm := NewLlmConnector(config.Channels, *llmDebug)
// Register callbacks.
bot.RegisterWebhookEventCallback(
ScheduleCallbackNormalPriority(llm.LlmCallback),
)
bot.RegisterWebhookEventCallback(
ScheduleCallbackHighestPriority(SimpleWebhookEventCallback),
)
// Start the chatbot
if err := bot.Start(); err != nil {
log.Fatalf("Error starting bot: %v", err)
}
}