mirror of
https://github.com/mudler/LocalAI.git
synced 2026-03-31 21:25:59 -04:00
* feat: add distributed mode (experimental) Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix data races, mutexes, transactions Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix events and tool stream in agent chat Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * use ginkgo Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(cron): compute correctly time boundaries avoiding re-triggering Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * enhancements, refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * do not flood of healthy checks Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * do not list obvious backends as text backends Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * tests fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Drop redundant healthcheck Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * enhancements, refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package p2p
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/mudler/LocalAI/core/schema"
|
|
)
|
|
|
|
const (
|
|
defaultServicesID = "services"
|
|
LlamaCPPWorkerID = "worker"
|
|
MLXWorkerID = "mlx_worker"
|
|
)
|
|
|
|
var mu sync.Mutex
|
|
var nodes = map[string]map[string]schema.NodeData{}
|
|
|
|
func GetAvailableNodes(serviceID string) []schema.NodeData {
|
|
if serviceID == "" {
|
|
serviceID = defaultServicesID
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
var availableNodes = []schema.NodeData{}
|
|
for _, v := range nodes[serviceID] {
|
|
availableNodes = append(availableNodes, v)
|
|
}
|
|
|
|
slices.SortFunc(availableNodes, func(a, b schema.NodeData) int {
|
|
return strings.Compare(a.ID, b.ID)
|
|
})
|
|
|
|
return availableNodes
|
|
}
|
|
|
|
func GetNode(serviceID, nodeID string) (schema.NodeData, bool) {
|
|
if serviceID == "" {
|
|
serviceID = defaultServicesID
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if _, ok := nodes[serviceID]; !ok {
|
|
return schema.NodeData{}, false
|
|
}
|
|
nd, exists := nodes[serviceID][nodeID]
|
|
return nd, exists
|
|
}
|
|
|
|
func AddNode(serviceID string, node schema.NodeData) {
|
|
if serviceID == "" {
|
|
serviceID = defaultServicesID
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if nodes[serviceID] == nil {
|
|
nodes[serviceID] = map[string]schema.NodeData{}
|
|
}
|
|
nodes[serviceID][node.ID] = node
|
|
}
|