diff --git a/.gitignore b/.gitignore index 20292b53..b6e53c89 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ src/tmp src/bin src/data web/.env.development +config.toml diff --git a/README.md b/README.md index e1abc86b..5b19268c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Chat-Plus 智能助手 +# ChatGPT-Plus 基于 OpenAI API 实现的 ChatGPT Web 应用,一共分为两个版本: @@ -48,6 +48,7 @@ ![ChatGPT admin](docs/imgs/admin-03.png) +### 5. 体验地址 > 体验地址:[https://www.chat-plus.net/chat/#/free](https://www.chat-plus.net/chat/#/free)
> 口令:GeekMaster @@ -58,7 +59,6 @@ * [ ] 接入 Google 语音 API,支持语音聊天 ## 本地部署 - ## 线上发布 ## 注意事项 diff --git a/src/config.sample.toml b/src/config.sample.toml index f6109c99..266c5f8d 100644 --- a/src/config.sample.toml +++ b/src/config.sample.toml @@ -1,31 +1,35 @@ Title = "Chat-Plus AI 助手" ConsoleTitle = "Chat-Plus 控制台" Listen = "0.0.0.0:5678" -ProxyURL = ["YOUR_PORYX_URL"] +ProxyURL = ["YOUR_PROXY_URL"] AccessKey = "YOUR_ACCESS_KEY" [Session] -SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" -Name = "CHAT_SESSION_ID" -Path = "/" -Domain = "" -MaxAge = 86400 -Secure = false -HttpOnly = false -SameSite = 2 + SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" + Name = "CHAT_SESSION_ID" + Path = "/" + Domain = "" + MaxAge = 86400 + Secure = false + HttpOnly = false + SameSite = 2 [ImgURL] -WechatCard = "https://img.r9it.com/chatgpt/WX20230505-162403.png" -WechatGroup = " https://img.r9it.com/chatgpt/WX20230505-162538.png" + WechatCard = "https://img.r9it.com/chatgpt/WX20230505-162403.png" + WechatGroup = " https://img.r9it.com/chatgpt/WX20230505-162538.png" [Manager] -Username = "admin" -Password = "admin123" + Username = "admin" + Password = "admin123" [Chat] -ApiURL = "https://api.openai.com/v1/chat/completions" -Model = "gpt-3.5-turbo" -Temperature = 1.0 -MaxTokens = 1024 -EnableContext = true -ChatContextExpireTime = 3600 \ No newline at end of file + ApiURL = "https://api.openai.com/v1/chat/completions" + Model = "gpt-3.5-turbo" + Temperature = 1.0 + MaxTokens = 1024 + EnableContext = true + ChatContextExpireTime = 3600 + + [[Chat.ApiKeys]] + Value = "YOUR_OPENAI_API_KEY" + LastUsed = 0 \ No newline at end of file diff --git a/src/main.go b/src/main.go index 5e4997f2..de875de3 100644 --- a/src/main.go +++ b/src/main.go @@ -6,9 +6,7 @@ import ( "embed" "flag" "fmt" - "github.com/mitchellh/go-homedir" "os" - "path/filepath" ) var logger = logger2.GetLogger() @@ -19,26 +17,7 @@ var configFile string var debugMode bool func main() { - // create config dir - configDir, _ := homedir.Expand("~/.config/chat-gpt") - _, err := os.Stat(configDir) - if err != nil { - err := os.MkdirAll(configDir, 0755) - if err != nil { - logger.Error(err) - return - } - } - - if err != nil { - logger.Errorf("failed to load web types: %v", err) - return - } - - if configFile == "" { - configFile = filepath.Join(configDir, "config.toml") - } - + logger.Info("Loading config file: ", configFile) // start server s, err := server.NewServer(configFile) if err != nil { @@ -49,7 +28,7 @@ func main() { func init() { - flag.StringVar(&configFile, "config", "", "Config file path (default: ~/.config/chat-gpt/config.toml)") + flag.StringVar(&configFile, "config", "config.toml", "Config file path (default: config.toml)") flag.BoolVar(&debugMode, "debug", true, "Enable debug mode (default: true, recommend to set false in production env)") flag.Usage = usage flag.Parse() diff --git a/src/types/config.go b/src/types/config.go index 83b8ee41..eeae3ae7 100644 --- a/src/types/config.go +++ b/src/types/config.go @@ -38,12 +38,12 @@ type Manager struct { // Chat configs struct type Chat struct { ApiURL string - ApiKeys []APIKey Model string Temperature float32 MaxTokens int EnableContext bool // 是否保持聊天上下文 ChatContextExpireTime int // 聊天上下文过期时间,单位:秒 + ApiKeys []APIKey } type APIKey struct { diff --git a/src/utils/config.go b/src/utils/config.go index b365b889..eb501529 100644 --- a/src/utils/config.go +++ b/src/utils/config.go @@ -17,7 +17,7 @@ func NewDefaultConfig() *types.Config { ProxyURL: make([]string, 0), ImgURL: types.ImgURL{}, Manager: types.Manager{Username: "admin", Password: "admin123"}, - AccessKey: "yangjian102621@gmail.com", + AccessKey: RandString(42), Session: types.Session{ SecretKey: RandString(64), @@ -47,7 +47,7 @@ func LoadConfig(configFile string) (*types.Config, error) { var config *types.Config _, err := os.Stat(configFile) if err != nil { - logger.Errorf("Error open config file: %s", err.Error()) + logger.Info("creating new config file: ", configFile) config = NewDefaultConfig() // save config err := SaveConfig(config, configFile)