mirror of
https://github.com/coalaura/whiskr.git
synced 2025-12-02 20:22:52 +00:00
better model list diff and refresh interval config
This commit is contained in:
8
env.go
8
env.go
@@ -24,6 +24,7 @@ type EnvSettings struct {
|
|||||||
ImageGeneration bool `json:"image-generation"`
|
ImageGeneration bool `json:"image-generation"`
|
||||||
Transformation string `json:"transformation"`
|
Transformation string `json:"transformation"`
|
||||||
Timeout int64 `json:"timeout"`
|
Timeout int64 `json:"timeout"`
|
||||||
|
RefreshInterval int64 `json:"refresh-interval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EnvUI struct {
|
type EnvUI struct {
|
||||||
@@ -57,6 +58,7 @@ var env = Environment{
|
|||||||
CleanContent: true,
|
CleanContent: true,
|
||||||
ImageGeneration: true,
|
ImageGeneration: true,
|
||||||
Timeout: 1200,
|
Timeout: 1200,
|
||||||
|
RefreshInterval: 30,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +133,11 @@ func (e *Environment) Init() error {
|
|||||||
env.Settings.Timeout = 300
|
env.Settings.Timeout = 300
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// default model refresh interval
|
||||||
|
if env.Settings.RefreshInterval <= 0 {
|
||||||
|
env.Settings.RefreshInterval = 30
|
||||||
|
}
|
||||||
|
|
||||||
// create user lookup map
|
// create user lookup map
|
||||||
e.Authentication.lookup = make(map[string]*EnvUser)
|
e.Authentication.lookup = make(map[string]*EnvUser)
|
||||||
|
|
||||||
@@ -184,6 +191,7 @@ func (e *Environment) Store() error {
|
|||||||
"$.settings.image-generation": {yaml.HeadComment(" allow image generation (optional; default: true)")},
|
"$.settings.image-generation": {yaml.HeadComment(" allow image generation (optional; default: true)")},
|
||||||
"$.settings.transformation": {yaml.HeadComment(" what transformation method to use for too long contexts (optional; default: middle-out)")},
|
"$.settings.transformation": {yaml.HeadComment(" what transformation method to use for too long contexts (optional; default: middle-out)")},
|
||||||
"$.settings.timeout": {yaml.HeadComment(" the http timeout to use for completion requests in seconds (optional; default: 300s)")},
|
"$.settings.timeout": {yaml.HeadComment(" the http timeout to use for completion requests in seconds (optional; default: 300s)")},
|
||||||
|
"$.settings.refresh-interval": {yaml.HeadComment(" the interval in which the model list is refreshed in minutes (optional; default: 30m)")},
|
||||||
|
|
||||||
"$.ui.reduced-motion": {yaml.HeadComment(" disables things like the floating stars in the background (optional; default: false)")},
|
"$.ui.reduced-motion": {yaml.HeadComment(" disables things like the floating stars in the background (optional; default: false)")},
|
||||||
|
|
||||||
|
|||||||
21
models.go
21
models.go
@@ -53,7 +53,7 @@ func StartModelUpdateLoop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ticker := time.NewTicker(2 * time.Hour)
|
ticker := time.NewTicker(time.Duration(env.Settings.RefreshInterval) * time.Minute)
|
||||||
|
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
err := LoadModels(false)
|
err := LoadModels(false)
|
||||||
@@ -76,7 +76,7 @@ func LoadModels(initial bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !initial && len(list) == len(ModelList) {
|
if !initial && !HasModelListChanged(list) {
|
||||||
log.Println("No new models, skipping update")
|
log.Println("No new models, skipping update")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -173,3 +173,20 @@ func GetModelTags(model openrouter.Model, m *Model) {
|
|||||||
|
|
||||||
sort.Strings(m.Tags)
|
sort.Strings(m.Tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HasModelListChanged(list []openrouter.Model) bool {
|
||||||
|
modelMx.RLock()
|
||||||
|
defer modelMx.RUnlock()
|
||||||
|
|
||||||
|
if len(list) != len(ModelList) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, model := range list {
|
||||||
|
if ModelList[i].ID != model.ID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user