mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-09 10:43:44 +08:00
系统设置页面功能完成
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"openai/types"
|
||||
"openai/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *Server) TestHandle(c *gin.Context) {
|
||||
@@ -17,9 +18,42 @@ func (s *Server) TestHandle(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (s *Server) ConfigGetHandle(c *gin.Context) {
|
||||
data := struct {
|
||||
Title string `json:"title"`
|
||||
ConsoleTitle string `json:"console_title"`
|
||||
ProxyURL string `json:"proxy_url"`
|
||||
Model string `json:"model"`
|
||||
Temperature float32 `json:"temperature"`
|
||||
MaxTokens int `json:"max_tokens"`
|
||||
ChatContextExpireTime int `json:"chat_context_expire_time"`
|
||||
EnableContext bool `json:"enable_context"`
|
||||
}{
|
||||
Title: s.Config.Title,
|
||||
ConsoleTitle: s.Config.ConsoleTitle,
|
||||
ProxyURL: strings.Join(s.Config.ProxyURL, ","),
|
||||
Model: s.Config.Chat.Model,
|
||||
Temperature: s.Config.Chat.Temperature,
|
||||
MaxTokens: s.Config.Chat.MaxTokens,
|
||||
EnableContext: s.Config.Chat.EnableContext,
|
||||
ChatContextExpireTime: s.Config.Chat.ChatContextExpireTime,
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, types.BizVo{Code: types.Success, Data: data})
|
||||
}
|
||||
|
||||
// ConfigSetHandle set configs
|
||||
func (s *Server) ConfigSetHandle(c *gin.Context) {
|
||||
var data map[string]interface{}
|
||||
var data struct {
|
||||
Title string `json:"title"`
|
||||
ConsoleTitle string `json:"console_title"`
|
||||
ProxyURL string `json:"proxy_url"`
|
||||
Model string `json:"model"`
|
||||
Temperature float32 `json:"temperature"`
|
||||
MaxTokens int `json:"max_tokens"`
|
||||
ChatContextExpireTime int `json:"chat_context_expire_time"`
|
||||
EnableContext bool `json:"enable_context"`
|
||||
}
|
||||
err := json.NewDecoder(c.Request.Body).Decode(&data)
|
||||
if err != nil {
|
||||
logger.Errorf("Error decode json data: %s", err.Error())
|
||||
@@ -27,32 +61,15 @@ func (s *Server) ConfigSetHandle(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if model, ok := data["model"]; ok {
|
||||
s.Config.Chat.Model = model.(string)
|
||||
}
|
||||
// Temperature
|
||||
if temperature, ok := data["temperature"]; ok {
|
||||
s.Config.Chat.Temperature = temperature.(float32)
|
||||
}
|
||||
// max_users
|
||||
if maxTokens, ok := data["max_tokens"]; ok {
|
||||
s.Config.Chat.MaxTokens = int(maxTokens.(float64))
|
||||
}
|
||||
// enable Context
|
||||
if enableContext, ok := data["enable_context"]; ok {
|
||||
s.Config.Chat.EnableContext = enableContext.(bool)
|
||||
}
|
||||
if expireTime, ok := data["chat_context_expire_time"]; ok {
|
||||
s.Config.Chat.ChatContextExpireTime = int(expireTime.(float64))
|
||||
}
|
||||
// enable auth
|
||||
if enableAuth, ok := data["enable_auth"]; ok {
|
||||
s.Config.EnableAuth = enableAuth.(bool)
|
||||
}
|
||||
s.Config.Title = data.Title
|
||||
s.Config.ConsoleTitle = data.ConsoleTitle
|
||||
s.Config.ProxyURL = strings.Split(data.ProxyURL, ",")
|
||||
s.Config.Chat.Model = data.Model
|
||||
s.Config.Chat.Temperature = data.Temperature
|
||||
s.Config.Chat.MaxTokens = data.MaxTokens
|
||||
s.Config.Chat.EnableContext = data.EnableContext
|
||||
s.Config.Chat.ChatContextExpireTime = data.ChatContextExpireTime
|
||||
|
||||
if debug, ok := data["debug"]; ok {
|
||||
s.DebugMode = debug.(bool)
|
||||
}
|
||||
// 保存配置文件
|
||||
err = utils.SaveConfig(s.Config, s.ConfigPath)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user