forked from whatwewant/chatgpt-for-chatbot-feishu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
156 lines (152 loc) · 4.57 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"github.com/go-zoox/cli"
)
func main() {
app := cli.NewSingleProgram(&cli.SingleProgramConfig{
Name: "chatgpt-for-chatbot-feishu",
Usage: "chatgpt-for-chatbot-feishu is a portable chatgpt server",
Version: Version,
Flags: []cli.Flag{
&cli.IntFlag{
Name: "port",
Usage: "server port",
Aliases: []string{"p"},
EnvVars: []string{"PORT"},
Value: 8080,
},
&cli.StringFlag{
Name: "api-path",
Usage: "custom api path, default: /",
EnvVars: []string{"API_PATH"},
Value: "/",
},
&cli.StringFlag{
Name: "openai-api-key",
Usage: "OpenAI API Key",
EnvVars: []string{"OPENAI_API_KEY"},
Required: true,
},
&cli.StringFlag{
Name: "openai-api-server",
Usage: "OpenAI API Server",
EnvVars: []string{"OPENAI_API_Server"},
},
&cli.StringFlag{
Name: "app-id",
Usage: "Feishu App ID",
EnvVars: []string{"APP_ID"},
Required: true,
},
&cli.StringFlag{
Name: "app-secret",
Usage: "Feishu App SECRET",
EnvVars: []string{"APP_SECRET"},
Required: true,
},
&cli.StringFlag{
Name: "encrypt-key",
Usage: "enable encryption if you need",
EnvVars: []string{"ENCRYPT_KEY"},
},
&cli.StringFlag{
Name: "verification-token",
Usage: "enable token verification if you need",
EnvVars: []string{"VERIFICATION_TOKEN"},
},
&cli.StringFlag{
Name: "report-url",
Usage: "Set error report url",
EnvVars: []string{"REPORT_URL"},
},
&cli.StringFlag{
Name: "site-url",
Usage: "The Site URL",
EnvVars: []string{"SITE_URL"},
},
&cli.StringFlag{
Name: "openai-model",
Usage: "Custom open ai model",
EnvVars: []string{"OPENAI_MODEL"},
},
&cli.StringFlag{
Name: "feishu-base-uri",
Usage: "Custom feishu base uri for selfhosted Feishu",
EnvVars: []string{"FEISHU_BASE_URI"},
},
&cli.StringFlag{
Name: "conversation-context",
Usage: "Custom chatgpt conversation context",
EnvVars: []string{"CONVERSATION_CONTEXT"},
},
&cli.StringFlag{
Name: "conversation-language",
Usage: "Custom chatgpt conversation lanuage",
EnvVars: []string{"CONVERSATION_LANGUAGE"},
},
&cli.StringFlag{
Name: "logs-dir",
Usage: "The logs dir for save logs",
EnvVars: []string{"LOGS_DIR"},
Value: "/tmp/chatgpt-for-chatbot-feishu",
},
&cli.StringFlag{
Name: "offline-message",
Usage: "The message to use for offline status",
EnvVars: []string{"OFFLINE_MESSAGE"},
Value: "robot is offline",
},
&cli.StringFlag{
Name: "admin-email",
Usage: "Sets the admin with admin email, who can run commands",
EnvVars: []string{"ADMIN_EMAIL"},
},
&cli.StringFlag{
Name: "bot-name",
Usage: "Sets the bot name, default: ChatGPT",
EnvVars: []string{"BOT_NAME"},
},
&cli.StringFlag{
Name: "proxy",
Usage: "Sets the request proxy",
EnvVars: []string{"PROXY", "HTTPS_PROXY"},
},
&cli.StringFlag{
Name: "proxy-openai-api-path",
Usage: "Sets the proxy path for OpenAI API",
EnvVars: []string{"PROXY_OPENAI_API_PATH"},
},
&cli.StringFlag{
Name: "proxy-openai-api-token",
Usage: "Sets the proxy tokens for OpenAI API",
EnvVars: []string{"PROXY_OPENAI_API_TOKEN"},
},
},
})
app.Command(func(ctx *cli.Context) (err error) {
return ServeFeishuBot(&FeishuBotConfig{
LogsDir: ctx.String("logs-dir"),
Port: ctx.Int64("port"),
APIPath: ctx.String("api-path"),
OpenAIAPIKey: ctx.String("openai-api-key"),
AppID: ctx.String("app-id"),
AppSecret: ctx.String("app-secret"),
EncryptKey: ctx.String("encrypt-key"),
VerificationToken: ctx.String("verification-token"),
ReportURL: ctx.String("report-url"),
SiteURL: ctx.String("site-url"),
OpenAIModel: ctx.String("openai-model"),
FeishuBaseURI: ctx.String("feishu-base-uri"),
ConversationContext: ctx.String("conversation-context"),
ConversationLanguage: ctx.String("conversation-language"),
OfflineMessage: ctx.String("offline-message"),
AdminEmail: ctx.String("admin-email"),
BotName: ctx.String("bot-name"),
Proxy: ctx.String("proxy"),
OpenAIAPIServer: ctx.String("openai-api-server"),
ProxyOpenAIAPIPath: ctx.String("proxy-openai-api-path"),
ProxyOpenAIAPIToken: ctx.String("proxy-openai-api-token"),
})
})
app.Run()
}