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

 | 
			
		||||
 | 
			
		||||
### 5. 体验地址
 | 
			
		||||
> 体验地址:[https://www.chat-plus.net/chat/#/free](https://www.chat-plus.net/chat/#/free) </br>
 | 
			
		||||
> 口令:GeekMaster
 | 
			
		||||
 | 
			
		||||
@@ -58,7 +59,6 @@
 | 
			
		||||
* [ ] 接入 Google 语音 API,支持语音聊天
 | 
			
		||||
 | 
			
		||||
## 本地部署
 | 
			
		||||
 | 
			
		||||
## 线上发布
 | 
			
		||||
 | 
			
		||||
## 注意事项
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
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]
 | 
			
		||||
@@ -29,3 +29,7 @@ Temperature = 1.0
 | 
			
		||||
  MaxTokens = 1024
 | 
			
		||||
  EnableContext = true
 | 
			
		||||
  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"
 | 
			
		||||
	"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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user