mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-17 16:56:38 +08:00
opt: 优化配置文档加载
This commit is contained in:
parent
16a49c930b
commit
97c90fa550
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,3 +26,4 @@ src/tmp
|
|||||||
src/bin
|
src/bin
|
||||||
src/data
|
src/data
|
||||||
web/.env.development
|
web/.env.development
|
||||||
|
config.toml
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Chat-Plus 智能助手
|
# ChatGPT-Plus
|
||||||
|
|
||||||
基于 OpenAI API 实现的 ChatGPT Web 应用,一共分为两个版本:
|
基于 OpenAI API 实现的 ChatGPT Web 应用,一共分为两个版本:
|
||||||
|
|
||||||
@ -48,6 +48,7 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### 5. 体验地址
|
||||||
> 体验地址:[https://www.chat-plus.net/chat/#/free](https://www.chat-plus.net/chat/#/free) </br>
|
> 体验地址:[https://www.chat-plus.net/chat/#/free](https://www.chat-plus.net/chat/#/free) </br>
|
||||||
> 口令:GeekMaster
|
> 口令:GeekMaster
|
||||||
|
|
||||||
@ -58,7 +59,6 @@
|
|||||||
* [ ] 接入 Google 语音 API,支持语音聊天
|
* [ ] 接入 Google 语音 API,支持语音聊天
|
||||||
|
|
||||||
## 本地部署
|
## 本地部署
|
||||||
|
|
||||||
## 线上发布
|
## 线上发布
|
||||||
|
|
||||||
## 注意事项
|
## 注意事项
|
||||||
|
@ -1,31 +1,35 @@
|
|||||||
Title = "Chat-Plus AI 助手"
|
Title = "Chat-Plus AI 助手"
|
||||||
ConsoleTitle = "Chat-Plus 控制台"
|
ConsoleTitle = "Chat-Plus 控制台"
|
||||||
Listen = "0.0.0.0:5678"
|
Listen = "0.0.0.0:5678"
|
||||||
ProxyURL = ["YOUR_PORYX_URL"]
|
ProxyURL = ["YOUR_PROXY_URL"]
|
||||||
AccessKey = "YOUR_ACCESS_KEY"
|
AccessKey = "YOUR_ACCESS_KEY"
|
||||||
|
|
||||||
[Session]
|
[Session]
|
||||||
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80"
|
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80"
|
||||||
Name = "CHAT_SESSION_ID"
|
Name = "CHAT_SESSION_ID"
|
||||||
Path = "/"
|
Path = "/"
|
||||||
Domain = ""
|
Domain = ""
|
||||||
MaxAge = 86400
|
MaxAge = 86400
|
||||||
Secure = false
|
Secure = false
|
||||||
HttpOnly = false
|
HttpOnly = false
|
||||||
SameSite = 2
|
SameSite = 2
|
||||||
|
|
||||||
[ImgURL]
|
[ImgURL]
|
||||||
WechatCard = "https://img.r9it.com/chatgpt/WX20230505-162403.png"
|
WechatCard = "https://img.r9it.com/chatgpt/WX20230505-162403.png"
|
||||||
WechatGroup = " https://img.r9it.com/chatgpt/WX20230505-162538.png"
|
WechatGroup = " https://img.r9it.com/chatgpt/WX20230505-162538.png"
|
||||||
|
|
||||||
[Manager]
|
[Manager]
|
||||||
Username = "admin"
|
Username = "admin"
|
||||||
Password = "admin123"
|
Password = "admin123"
|
||||||
|
|
||||||
[Chat]
|
[Chat]
|
||||||
ApiURL = "https://api.openai.com/v1/chat/completions"
|
ApiURL = "https://api.openai.com/v1/chat/completions"
|
||||||
Model = "gpt-3.5-turbo"
|
Model = "gpt-3.5-turbo"
|
||||||
Temperature = 1.0
|
Temperature = 1.0
|
||||||
MaxTokens = 1024
|
MaxTokens = 1024
|
||||||
EnableContext = true
|
EnableContext = true
|
||||||
ChatContextExpireTime = 3600
|
ChatContextExpireTime = 3600
|
||||||
|
|
||||||
|
[[Chat.ApiKeys]]
|
||||||
|
Value = "YOUR_OPENAI_API_KEY"
|
||||||
|
LastUsed = 0
|
25
src/main.go
25
src/main.go
@ -6,9 +6,7 @@ import (
|
|||||||
"embed"
|
"embed"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/go-homedir"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = logger2.GetLogger()
|
var logger = logger2.GetLogger()
|
||||||
@ -19,26 +17,7 @@ var configFile string
|
|||||||
var debugMode bool
|
var debugMode bool
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// create config dir
|
logger.Info("Loading config file: ", configFile)
|
||||||
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")
|
|
||||||
}
|
|
||||||
|
|
||||||
// start server
|
// start server
|
||||||
s, err := server.NewServer(configFile)
|
s, err := server.NewServer(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -49,7 +28,7 @@ func main() {
|
|||||||
|
|
||||||
func init() {
|
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.BoolVar(&debugMode, "debug", true, "Enable debug mode (default: true, recommend to set false in production env)")
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -38,12 +38,12 @@ type Manager struct {
|
|||||||
// Chat configs struct
|
// Chat configs struct
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
ApiURL string
|
ApiURL string
|
||||||
ApiKeys []APIKey
|
|
||||||
Model string
|
Model string
|
||||||
Temperature float32
|
Temperature float32
|
||||||
MaxTokens int
|
MaxTokens int
|
||||||
EnableContext bool // 是否保持聊天上下文
|
EnableContext bool // 是否保持聊天上下文
|
||||||
ChatContextExpireTime int // 聊天上下文过期时间,单位:秒
|
ChatContextExpireTime int // 聊天上下文过期时间,单位:秒
|
||||||
|
ApiKeys []APIKey
|
||||||
}
|
}
|
||||||
|
|
||||||
type APIKey struct {
|
type APIKey struct {
|
||||||
|
@ -17,7 +17,7 @@ func NewDefaultConfig() *types.Config {
|
|||||||
ProxyURL: make([]string, 0),
|
ProxyURL: make([]string, 0),
|
||||||
ImgURL: types.ImgURL{},
|
ImgURL: types.ImgURL{},
|
||||||
Manager: types.Manager{Username: "admin", Password: "admin123"},
|
Manager: types.Manager{Username: "admin", Password: "admin123"},
|
||||||
AccessKey: "yangjian102621@gmail.com",
|
AccessKey: RandString(42),
|
||||||
|
|
||||||
Session: types.Session{
|
Session: types.Session{
|
||||||
SecretKey: RandString(64),
|
SecretKey: RandString(64),
|
||||||
@ -47,7 +47,7 @@ func LoadConfig(configFile string) (*types.Config, error) {
|
|||||||
var config *types.Config
|
var config *types.Config
|
||||||
_, err := os.Stat(configFile)
|
_, err := os.Stat(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Error open config file: %s", err.Error())
|
logger.Info("creating new config file: ", configFile)
|
||||||
config = NewDefaultConfig()
|
config = NewDefaultConfig()
|
||||||
// save config
|
// save config
|
||||||
err := SaveConfig(config, configFile)
|
err := SaveConfig(config, configFile)
|
||||||
|
Loading…
Reference in New Issue
Block a user