mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 01:06:39 +08:00
add command line arg --config, enable reply default message when the OpenAI API is not available
This commit is contained in:
parent
20bdf12180
commit
c700895d9c
31
main.go
31
main.go
@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
logger2 "openai/logger"
|
||||
"openai/server"
|
||||
@ -13,6 +15,7 @@ var logger = logger2.GetLogger()
|
||||
|
||||
//go:embed dist
|
||||
var webRoot embed.FS
|
||||
var configFile string
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
@ -37,10 +40,36 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
if configFile == "" {
|
||||
configFile = filepath.Join(configDir, "config.toml")
|
||||
}
|
||||
|
||||
// start server
|
||||
s, err := server.NewServer(filepath.Join(configDir, "/config.toml"))
|
||||
s, err := server.NewServer(configFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s.Run(webRoot, "dist")
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
flag.StringVar(&configFile, "config", "", "Config file path (default: ~/.config/chat-gpt/config.toml)")
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Printf(`WeChat-GPT, Version: 1.0.0
|
||||
USAGE:
|
||||
%s [command options]
|
||||
OPTIONS:
|
||||
`, os.Args[0])
|
||||
|
||||
flagSet := flag.CommandLine
|
||||
order := []string{"config"}
|
||||
for _, name := range order {
|
||||
f := flagSet.Lookup(name)
|
||||
fmt.Printf(" --%s => %s\n", f.Name, f.Usage)
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,12 @@ func (s *Server) sendMessage(userId string, text string, ws Client) error {
|
||||
}
|
||||
retryCount--
|
||||
}
|
||||
|
||||
// 如果三次请求都失败的话,则返回对应的错误信息
|
||||
if err != nil {
|
||||
replyMessage(types.WsMessage{Type: types.WsStart}, ws)
|
||||
replyMessage(types.WsMessage{Type: types.WsMiddle, Content: "抱歉,AI 助手开小差了,我马上找人去盘它。"}, ws)
|
||||
replyMessage(types.WsMessage{Type: types.WsEnd}, ws)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -113,20 +113,20 @@ export default defineComponent({
|
||||
|
||||
this.checkSession();
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
this.chatData.push({
|
||||
type: "prompt",
|
||||
id: randString(32),
|
||||
icon: 'images/user-icon.png',
|
||||
content: "孙悟空为什么可以把金棍棒放进耳朵?",
|
||||
});
|
||||
this.chatData.push({
|
||||
type: "reply",
|
||||
id: randString(32),
|
||||
icon: 'images/gpt-icon.png',
|
||||
content: "孙悟空是中国神话中的人物,传说中他可以把金箍棒放进耳朵里,这是一种超自然能力,无法用现代科学解释。这种能力可能是象征孙悟空超人力量的古代文化传说。",
|
||||
});
|
||||
}
|
||||
// for (let i = 0; i < 10; i++) {
|
||||
// this.chatData.push({
|
||||
// type: "prompt",
|
||||
// id: randString(32),
|
||||
// icon: 'images/user-icon.png',
|
||||
// content: "孙悟空为什么可以把金棍棒放进耳朵?",
|
||||
// });
|
||||
// this.chatData.push({
|
||||
// type: "reply",
|
||||
// id: randString(32),
|
||||
// icon: 'images/gpt-icon.png',
|
||||
// content: "孙悟空是中国神话中的人物,传说中他可以把金箍棒放进耳朵里,这是一种超自然能力,无法用现代科学解释。这种能力可能是象征孙悟空超人力量的古代文化传说。",
|
||||
// });
|
||||
// }
|
||||
|
||||
window.addEventListener("resize", () => {
|
||||
this.chatBoxHeight = window.innerHeight - this.toolBoxHeight;
|
||||
@ -195,7 +195,6 @@ export default defineComponent({
|
||||
});
|
||||
} else if (data.type === 'end') {
|
||||
this.sending = false;
|
||||
this.chatData[this.chatData.length - 1]["cursor"] = false;
|
||||
} else {
|
||||
let content = data.content;
|
||||
// 替换换行符
|
||||
|
Loading…
Reference in New Issue
Block a user