Skip to content

Commit

Permalink
feat: conf hot reload
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Dec 2, 2023
1 parent 1315782 commit e6ca4c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions adapter/chatgpt/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chatgpt
import (
"chat/globals"
"fmt"
"github.com/spf13/viper"
)

type ChatInstance struct {
Expand Down Expand Up @@ -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(),
)
}
7 changes: 5 additions & 2 deletions channel/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down Expand Up @@ -108,6 +110,7 @@ func (m *Manager) GetMaxId() int {

func (m *Manager) SaveConfig() error {
viper.Set("channel", m.Sequence)
m.Load()
return viper.WriteConfig()
}

Expand Down

0 comments on commit e6ca4c7

Please sign in to comment.