mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 13:00:14 +09:00
feat: conf hot reload
This commit is contained in:
parent
1315782930
commit
e6ca4c7015
@ -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(),
|
||||
)
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user