feat(explorer): make possible to run sync in a separate process (#3224)

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto 2024-08-12 19:25:44 +02:00 committed by GitHub
parent 4dfa085339
commit 9729d2ae37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 83 additions and 67 deletions

View file

@ -11,7 +11,6 @@ import (
func Dashboard() func(*fiber.Ctx) error {
return func(c *fiber.Ctx) error {
summary := fiber.Map{
"Title": "LocalAI API - " + internal.PrintableVersion(),
"Version": internal.PrintableVersion(),
@ -34,26 +33,24 @@ type AddNetworkRequest struct {
}
type Network struct {
explorer.Network
explorer.TokenData
Token string `json:"token"`
}
func ShowNetworks(db *explorer.Database, ds *explorer.DiscoveryServer) func(*fiber.Ctx) error {
func ShowNetworks(db *explorer.Database) func(*fiber.Ctx) error {
return func(c *fiber.Ctx) error {
networkState := ds.NetworkState()
results := []Network{}
for token, network := range networkState.Networks {
for _, token := range db.TokenList() {
networkData, exists := db.Get(token) // get the token data
hasWorkers := false
for _, cluster := range network.Clusters {
for _, cluster := range networkData.Clusters {
if len(cluster.Workers) > 0 {
hasWorkers = true
break
}
}
if exists && hasWorkers {
results = append(results, Network{Network: network, TokenData: networkData, Token: token})
results = append(results, Network{TokenData: networkData, Token: token})
}
}

View file

@ -10,7 +10,7 @@ import (
"github.com/mudler/LocalAI/core/http/routes"
)
func Explorer(db *explorer.Database, discoveryServer *explorer.DiscoveryServer) *fiber.App {
func Explorer(db *explorer.Database) *fiber.App {
fiberCfg := fiber.Config{
Views: renderEngine(),
@ -22,7 +22,7 @@ func Explorer(db *explorer.Database, discoveryServer *explorer.DiscoveryServer)
app := fiber.New(fiberCfg)
routes.RegisterExplorerRoutes(app, db, discoveryServer)
routes.RegisterExplorerRoutes(app, db)
httpFS := http.FS(embedDirStatic)

View file

@ -6,8 +6,8 @@ import (
"github.com/mudler/LocalAI/core/http/endpoints/explorer"
)
func RegisterExplorerRoutes(app *fiber.App, db *coreExplorer.Database, ds *coreExplorer.DiscoveryServer) {
func RegisterExplorerRoutes(app *fiber.App, db *coreExplorer.Database) {
app.Get("/", explorer.Dashboard())
app.Post("/network/add", explorer.AddNetwork(db))
app.Get("/networks", explorer.ShowNetworks(db, ds))
app.Get("/networks", explorer.ShowNetworks(db))
}