-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathmain.go
91 lines (73 loc) · 2.18 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
package main
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/ian-kent/gptchat/config"
"github.com/ian-kent/gptchat/module"
"github.com/ian-kent/gptchat/module/memory"
"github.com/ian-kent/gptchat/module/plugin"
"github.com/ian-kent/gptchat/ui"
openai "github.com/sashabaranov/go-openai"
)
var client *openai.Client
var cfg = config.New()
func init() {
openaiAPIKey := strings.TrimSpace(os.Getenv("OPENAI_API_KEY"))
if openaiAPIKey == "" {
ui.Warn("You haven't configured an OpenAI API key")
fmt.Println()
if !ui.PromptConfirm("Do you have an API key?") {
ui.Warn("You'll need an API key to use GPTChat")
fmt.Println()
fmt.Println("* You can get an API key at https://platform.openai.com/account/api-keys")
fmt.Println("* You can get join the GPT-4 API waitlist at https://openai.com/waitlist/gpt-4-api")
os.Exit(1)
}
openaiAPIKey = ui.PromptInput("Enter your API key:")
if openaiAPIKey == "" {
fmt.Println("")
ui.Warn("You didn't enter an API key.")
os.Exit(1)
}
}
cfg = cfg.WithOpenAIAPIKey(openaiAPIKey)
openaiAPIModel := strings.TrimSpace(os.Getenv("OPENAI_API_MODEL"))
if openaiAPIModel == "" {
ui.Warn("You haven't configured an OpenAI API model, defaulting to GPT4")
openaiAPIModel = openai.GPT4
}
cfg = cfg.WithOpenAIAPIModel(openaiAPIModel)
supervisorMode := os.Getenv("GPTCHAT_SUPERVISOR")
switch strings.ToLower(supervisorMode) {
case "disabled":
ui.Warn("Supervisor mode is disabled")
cfg = cfg.WithSupervisedMode(false)
default:
}
debugEnv := os.Getenv("GPTCHAT_DEBUG")
if debugEnv != "" {
v, err := strconv.ParseBool(debugEnv)
if err != nil {
ui.Warn(fmt.Sprintf("error parsing GPT_DEBUG: %s", err.Error()))
} else {
cfg = cfg.WithDebugMode(v)
}
}
client = openai.NewClient(openaiAPIKey)
module.Load(cfg, client, []module.Module{
&memory.Module{},
&plugin.Module{},
}...)
if err := module.LoadCompiledPlugins(); err != nil {
ui.Warn(fmt.Sprintf("error loading compiled plugins: %s", err))
}
}
func main() {
ui.Welcome(
`Welcome to the GPT client.`,
`You can talk directly to GPT, or you can use /commands to interact with the client.
Use /help to see a list of available commands.`)
chatLoop(cfg)
}