From 1770b92fb6db01955e68a97523255ca8b18609d3 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Thu, 14 Nov 2024 14:12:29 +0100 Subject: [PATCH] chore(api): return values from schema (#4153) Signed-off-by: Ettore Di Giacinto --- core/http/endpoints/localai/system.go | 7 ++++++- core/schema/localai.go | 9 ++++++--- pkg/model/loader.go | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/http/endpoints/localai/system.go b/core/http/endpoints/localai/system.go index 23a725e32fd4..92d80a3a2ea9 100644 --- a/core/http/endpoints/localai/system.go +++ b/core/http/endpoints/localai/system.go @@ -21,10 +21,15 @@ func SystemInformations(ml *model.ModelLoader, appConfig *config.ApplicationConf for b := range appConfig.ExternalGRPCBackends { availableBackends = append(availableBackends, b) } + + sysmodels := []schema.SysInfoModel{} + for _, m := range loadedModels { + sysmodels = append(sysmodels, schema.SysInfoModel{ID: m.ID}) + } return c.JSON( schema.SystemInformationResponse{ Backends: availableBackends, - Models: loadedModels, + Models: sysmodels, }, ) } diff --git a/core/schema/localai.go b/core/schema/localai.go index 1b663ae0baa0..861ed577ea04 100644 --- a/core/schema/localai.go +++ b/core/schema/localai.go @@ -2,7 +2,6 @@ package schema import ( "github.com/mudler/LocalAI/core/p2p" - "github.com/mudler/LocalAI/pkg/model" gopsutil "github.com/shirou/gopsutil/v3/process" ) @@ -77,7 +76,11 @@ type P2PNodesResponse struct { FederatedNodes []p2p.NodeData `json:"federated_nodes" yaml:"federated_nodes"` } +type SysInfoModel struct { + ID string `json:"id"` +} + type SystemInformationResponse struct { - Backends []string `json:"backends"` - Models []model.Model `json:"loaded_models"` + Backends []string `json:"backends"` + Models []SysInfoModel `json:"loaded_models"` } diff --git a/pkg/model/loader.go b/pkg/model/loader.go index ade9944ad727..b32e3745efc9 100644 --- a/pkg/model/loader.go +++ b/pkg/model/loader.go @@ -103,13 +103,13 @@ FILE: return models, nil } -func (ml *ModelLoader) ListModels() []Model { +func (ml *ModelLoader) ListModels() []*Model { ml.mu.Lock() defer ml.mu.Unlock() - models := []Model{} + models := []*Model{} for _, model := range ml.models { - models = append(models, *model) + models = append(models, model) } return models