diff --git a/api/types.go b/api/types.go index a38b335b7..45fad55cb 100644 --- a/api/types.go +++ b/api/types.go @@ -421,6 +421,7 @@ type ProcessModelResponse struct { Details ModelDetails `json:"details,omitempty"` ExpiresAt time.Time `json:"expires_at"` SizeVRAM int64 `json:"size_vram"` + Active bool `json:"active"` } type RetrieveModelResponse struct { diff --git a/cmd/cmd.go b/cmd/cmd.go index 710f49a72..3cc78a3cf 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -513,12 +513,20 @@ func ListRunningHandler(cmd *cobra.Command, args []string) error { } else { until = format.HumanTime(m.ExpiresAt, "Never") } - data = append(data, []string{m.Name, m.Digest[:12], format.HumanBytes(m.Size), procStr, until}) + + var activeStr string + if m.Active { + activeStr = "Yes" + } else { + activeStr = "No" + } + + data = append(data, []string{m.Name, m.Digest[:12], format.HumanBytes(m.Size), procStr, activeStr, until}) } } table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"NAME", "ID", "SIZE", "PROCESSOR", "UNTIL"}) + table.SetHeader([]string{"NAME", "ID", "SIZE", "PROCESSOR", "ACTIVE", "UNTIL"}) table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) table.SetAlignment(tablewriter.ALIGN_LEFT) table.SetHeaderLine(false) diff --git a/docs/api.md b/docs/api.md index 7de810496..f01403362 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1553,7 +1553,8 @@ A single JSON object will be returned. "quantization_level": "Q4_0" }, "expires_at": "2024-06-04T14:38:31.83753-07:00", - "size_vram": 5137025024 + "size_vram": 5137025024, + "active": true } ] } diff --git a/server/routes.go b/server/routes.go index 059936249..afb797e59 100644 --- a/server/routes.go +++ b/server/routes.go @@ -1402,6 +1402,11 @@ func (s *Server) PsHandler(c *gin.Context) { QuantizationLevel: model.Config.FileType, } + // Lock the reference mutex to safely check the reference count + v.refMu.Lock() + isActive := v.refCount > 0 + v.refMu.Unlock() + mr := api.ProcessModelResponse{ Model: model.ShortName, Name: model.ShortName, @@ -1410,6 +1415,7 @@ func (s *Server) PsHandler(c *gin.Context) { Digest: model.Digest, Details: modelDetails, ExpiresAt: v.expiresAt, + Active: isActive, } // The scheduler waits to set expiresAt, so if a model is loading it's // possible that it will be set to the unix epoch. For those cases, just