2024-07-08 20:04:06 +00:00
package cli
import (
"context"
cliContext "github.com/mudler/LocalAI/core/cli/context"
"github.com/mudler/LocalAI/core/p2p"
)
type FederatedCLI struct {
2024-08-07 21:35:44 +00:00
Address string ` env:"LOCALAI_ADDRESS,ADDRESS" default:":8080" help:"Bind address for the API server" group:"api" `
Peer2PeerToken string ` env:"LOCALAI_P2P_TOKEN,P2P_TOKEN,TOKEN" name:"p2ptoken" help:"Token for P2P mode (optional)" group:"p2p" `
2024-08-13 14:17:18 +00:00
RandomWorker bool ` env:"LOCALAI_RANDOM_WORKER,RANDOM_WORKER" default:"false" help:"Select a random worker from the pool" group:"p2p" `
2024-08-07 21:35:44 +00:00
Peer2PeerNetworkID string ` env:"LOCALAI_P2P_NETWORK_ID,P2P_NETWORK_ID" help:"Network ID for P2P mode, can be set arbitrarly by the user for grouping a set of instances." group:"p2p" `
2024-08-13 14:17:18 +00:00
TargetWorker string ` env:"LOCALAI_TARGET_WORKER,TARGET_WORKER" help:"Target worker to run the federated server on" group:"p2p" `
2024-07-08 20:04:06 +00:00
}
func ( f * FederatedCLI ) Run ( ctx * cliContext . Context ) error {
2024-08-13 14:17:18 +00:00
fs := p2p . NewFederatedServer ( f . Address , p2p . NetworkID ( f . Peer2PeerNetworkID , p2p . FederatedID ) , f . Peer2PeerToken , ! f . RandomWorker , f . TargetWorker )
2024-07-08 20:04:06 +00:00
2024-07-18 17:15:15 +00:00
return fs . Start ( context . Background ( ) )
2024-07-08 20:04:06 +00:00
}