From e6ca4c70150bd93f8b8c7075360a934a60335b9b Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Sun, 3 Dec 2023 04:44:53 +0800 Subject: [PATCH] feat: conf hot reload --- adapter/chatgpt/struct.go | 5 ++--- channel/manager.go | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/adapter/chatgpt/struct.go b/adapter/chatgpt/struct.go index ce7e2da5..fd2512e6 100644 --- a/adapter/chatgpt/struct.go +++ b/adapter/chatgpt/struct.go @@ -3,7 +3,6 @@ package chatgpt import ( "chat/globals" "fmt" - "github.com/spf13/viper" ) type ChatInstance struct { @@ -40,7 +39,7 @@ func NewChatInstance(endpoint, apiKey string) *ChatInstance { func NewChatInstanceFromConfig(conf globals.ChannelConfig) *ChatInstance { return NewChatInstance( - viper.GetString(conf.GetEndpoint()), - viper.GetString(conf.GetRandomSecret()), + conf.GetEndpoint(), + conf.GetRandomSecret(), ) } diff --git a/channel/manager.go b/channel/manager.go index 4fedf83a..f3477aca 100644 --- a/channel/manager.go +++ b/channel/manager.go @@ -25,13 +25,14 @@ func NewManager() *Manager { Models: []string{}, PreflightSequence: map[string]Sequence{}, } - manager.Init() + manager.Load() return manager } -func (m *Manager) Init() { +func (m *Manager) Load() { // init support models + m.Models = []string{} for _, channel := range m.GetActiveSequence() { for _, model := range channel.GetModels() { if !utils.Contains(model, m.Models) { @@ -41,6 +42,7 @@ func (m *Manager) Init() { } // init preflight sequence + m.PreflightSequence = map[string]Sequence{} for _, model := range m.Models { var seq Sequence for _, channel := range m.GetActiveSequence() { @@ -108,6 +110,7 @@ func (m *Manager) GetMaxId() int { func (m *Manager) SaveConfig() error { viper.Set("channel", m.Sequence) + m.Load() return viper.WriteConfig() }