mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-22 19:44:59 +00:00
Add token generation for federated server; remove additional P2P setup for federated instance mode
This commit is contained in:
parent
aa7171dd5d
commit
5c35029ae7
3 changed files with 24 additions and 9 deletions
|
@ -2,10 +2,12 @@ package cli
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
cliContext "github.com/mudler/LocalAI/core/cli/context"
|
||||
cliP2P "github.com/mudler/LocalAI/core/cli/p2p"
|
||||
"github.com/mudler/LocalAI/core/p2p"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type FederatedCLI struct {
|
||||
|
@ -18,6 +20,24 @@ type FederatedCLI struct {
|
|||
|
||||
func (f *FederatedCLI) Run(ctx *cliContext.Context) error {
|
||||
|
||||
if f.Peer2PeerToken == "" {
|
||||
log.Info().Msg("No token provided, generating one")
|
||||
connectionData, err := p2p.GenerateNewConnectionData(
|
||||
f.Peer2PeerDHTInterval, f.Peer2PeerOTPInterval,
|
||||
f.Peer2PeerPrivkey, f.Peer2PeerUsePeerguard,
|
||||
)
|
||||
if err != nil {
|
||||
log.Warn().Msgf("Error generating token: %s", err.Error())
|
||||
}
|
||||
f.Peer2PeerToken = connectionData.Base64()
|
||||
|
||||
log.Info().Msg("Generated Token:")
|
||||
fmt.Println(f.Peer2PeerToken)
|
||||
|
||||
log.Info().Msg("To use the token, you can run the following command in another node or terminal:")
|
||||
fmt.Printf("export TOKEN=\"%s\"\nlocal-ai worker p2p-llama-cpp-rpc\n", f.Peer2PeerToken)
|
||||
}
|
||||
|
||||
fs := p2p.NewFederatedServer(f.Address, p2p.NetworkID(f.Peer2PeerNetworkID, p2p.FederatedID), f.Peer2PeerToken, !f.RandomWorker, f.TargetWorker)
|
||||
|
||||
return fs.Start(context.Background(), f.P2PCommonFlags)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue