Skip to content

Commit

Permalink
opt: 优化配置文档加载
Browse files Browse the repository at this point in the history
  • Loading branch information
yangjian102621 committed May 6, 2023
1 parent 16a49c9 commit 97c90fa
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ src/tmp
src/bin
src/data
web/.env.development
config.toml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Chat-Plus 智能助手
# ChatGPT-Plus

基于 OpenAI API 实现的 ChatGPT Web 应用,一共分为两个版本:

Expand Down Expand Up @@ -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) </br>
> 口令:GeekMaster
Expand All @@ -58,7 +59,6 @@
* [ ] 接入 Google 语音 API,支持语音聊天

## 本地部署

## 线上发布

## 注意事项
Expand Down
42 changes: 23 additions & 19 deletions src/config.sample.toml
Original file line number Diff line number Diff line change
@@ -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
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
25 changes: 2 additions & 23 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"embed"
"flag"
"fmt"
"github.com/mitchellh/go-homedir"
"os"
"path/filepath"
)

var logger = logger2.GetLogger()
Expand All @@ -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 {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 97c90fa

Please sign in to comment.