Skip to content

Commit 749731d

Browse files
committed
update UI when config reloads
1 parent 5b5138a commit 749731d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

llama-swap.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ func main() {
7777
currentPM.Shutdown()
7878
srv.Handler = proxy.New(config)
7979
fmt.Println("Configuration Reloaded")
80+
81+
// wait a few seconds and tell any UI to reload
82+
time.AfterFunc(3*time.Second, func() {
83+
event.Emit(proxy.ConfigFileChangedEvent{
84+
ReloadingState: "end",
85+
})
86+
})
8087
} else {
8188
config, err = proxy.LoadConfig(*configPath)
8289
if err != nil {
@@ -92,7 +99,9 @@ func main() {
9299
debouncedReload := debounce(time.Second, reloadProxyManager)
93100
if *watchConfig {
94101
defer event.On(func(e proxy.ConfigFileChangedEvent) {
95-
debouncedReload()
102+
if e.ReloadingState == "start" {
103+
debouncedReload()
104+
}
96105
})()
97106

98107
fmt.Println("Watching Configuration for changes")
@@ -119,7 +128,9 @@ func main() {
119128
select {
120129
case changeEvent := <-watcher.Events:
121130
if changeEvent.Name == absConfigPath && (changeEvent.Has(fsnotify.Write) || changeEvent.Has(fsnotify.Create) || changeEvent.Has(fsnotify.Remove)) {
122-
event.Emit(proxy.ConfigFileChangedEvent{})
131+
event.Emit(proxy.ConfigFileChangedEvent{
132+
ReloadingState: "start",
133+
})
123134
}
124135

125136
case err := <-watcher.Errors:

proxy/events.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ func (e ChatCompletionStats) Type() uint32 {
2424
return ChatCompletionStatsEventID
2525
}
2626

27-
type ConfigFileChangedEvent struct{}
27+
type ConfigFileChangedEvent struct {
28+
ReloadingState string
29+
}
2830

2931
func (e ConfigFileChangedEvent) Type() uint32 {
3032
return ConfigFileChangedEventID

proxy/proxymanager_api.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (pm *ProxyManager) apiListModelsSSE(c *gin.Context) {
8888
c.SSEvent("message", pm.getModelStatus())
8989
c.Writer.Flush()
9090

91+
// send whenever the any process state
9192
defer event.On(func(e ProcessStateChangeEvent) {
9293
if c != nil && c.Writer != nil {
9394
models := pm.getModelStatus()
@@ -96,6 +97,15 @@ func (pm *ProxyManager) apiListModelsSSE(c *gin.Context) {
9697
}
9798
})()
9899

100+
// resend the models when the config is reloaded
101+
defer event.On(func(e ConfigFileChangedEvent) {
102+
if c != nil && c.Writer != nil && e.ReloadingState == "end" {
103+
models := pm.getModelStatus()
104+
c.SSEvent("message", models)
105+
c.Writer.Flush()
106+
}
107+
})()
108+
99109
select {
100110
case <-c.Request.Context().Done():
101111
case <-pm.shutdownCtx.Done():

0 commit comments

Comments
 (0)