Skip to content

Commit

Permalink
chore(p2p): make commands easier to copy-paste (#3273)
Browse files Browse the repository at this point in the history
chore(p2p): make box easier to copy-paste

Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler authored Aug 19, 2024
1 parent bb6d06f commit 73c9b35
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
63 changes: 43 additions & 20 deletions core/http/views/p2p.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!DOCTYPE html>
<html lang="en">
{{template "views/partials/head" .}}

<body class="bg-gray-900 text-gray-200">
<div class="flex flex-col min-h-screen">
<div class="flex flex-col min-h-screen" x-data="{}">

{{template "views/partials/navbar" .}}
<div class="container mx-auto px-4 flex-grow">
<div class="workers mt-12 text-center">
Expand All @@ -26,6 +25,16 @@ <h1 class="text-5xl font-bold text-gray-100">
</div>
</div>
<h5 class="mb-4 text-justify">LocalAI uses P2P technologies to enable distribution of work between peers. It is possible to share an instance with Federation and/or split the weights of a model across peers (only available with llama.cpp models). You can now share computational resources between your devices or your friends!</h5>

<div class="bg-gray-800 p-6 rounded-lg shadow-lg mb-12 text-left">
<p class="text-lg font-bold mb-4 mt-1">
Network token
<i class="fa-solid fa-copy copy-icon float-right"></i>
</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words" @click="copyClipboard($el.textContent)">{{.P2PToken}}</code><br>
The network token can be used to either share the instance or join a federation or a worker network. Below you will find a few examples on how to start a new instance or a worker with the token and you will be able to see the available workers and federated nodes.
</div>

<!-- Warning box if p2p token is empty and p2p is enabled -->
{{ if and .IsP2PEnabled (eq .P2PToken "") }}
<div class="bg-red-500 p-4 rounded-lg shadow-lg mb-12 text-left">
Expand All @@ -50,7 +59,6 @@ <h5 class="mb-4 text-justify">LocalAI uses P2P technologies to enable distributi

<h3 class="text-2xl font-semibold text-gray-100 mb-6"><i class="fa-solid fa-book"></i> Start a federated instance</h3>


<!-- Tabs navigation -->
<ul class="mb-5 flex list-none flex-row flex-wrap ps-0" role="tablist" data-twe-nav-ref>
<li role="presentation" class="flex-auto text-center">
Expand All @@ -62,22 +70,25 @@ <h3 class="text-2xl font-semibold text-gray-100 mb-6"><i class="fa-solid fa-book
</ul>

<!-- Tabs content -->
<div class="mb-6">

<div class="mb-6">
<div class="tabcontent hidden opacity-100 transition-opacity duration-150 ease-linear data-[twe-tab-active]:block p-4" id="tabs-federated-cli" role="tabpanel" aria-labelledby="tabs-federated-cli" data-twe-tab-active>


<p class="mb-2">To start a new instance to share:</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words">
<p class="text-lg font-bold mb-4 mt-1">
To start a new instance to share:
<i class="fa-solid fa-copy copy-icon float-right"></i>
</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words" @click="copyClipboard($el.textContent)">
# Start a new instance to share with --federated and a TOKEN<br>
export TOKEN="<span class="token">{{.P2PToken}}</span>"<br>
local-ai run --federated --p2p
</code>

<p class="mt-2">Note: If you don't have a token do not specify it and use the generated one that you can find in this page.</p>

<p class="mb-2">To start a new federated load balancer:</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words">
<p class="text-lg font-bold mb-4 mt-1">
To start a new federated load balancer:
<i class="fa-solid fa-copy copy-icon float-right"></i>
</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words" @click="copyClipboard($el.textContent)">
export TOKEN="<span class="token">{{.P2PToken}}</span>"<br>
local-ai federated
</code>
Expand All @@ -87,13 +98,19 @@ <h3 class="text-2xl font-semibold text-gray-100 mb-6"><i class="fa-solid fa-book
<p class="mt-2">For all the options available, please refer to the <a href="https://localai.io/features/distribute/#starting-workers" target="_blank" class="text-yellow-300 hover:text-yellow-400">documentation</a>.</p>
</div>
<div class="tabcontent hidden opacity-0 transition-opacity duration-150 ease-linear data-[twe-tab-active]:block p-4" id="tabs-federated-docker" role="tabpanel" aria-labelledby="tabs-federated-docker">
<p class="mb-2">To start a new federated instance:</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words">
<p class="text-lg font-bold mb-4 mt-1">
To start a new federated instance:
<i class="fa-solid fa-copy copy-icon float-right"></i>
</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words" @click="copyClipboard($el.textContent)">
docker run -ti --net host -e TOKEN="<span class="token">{{.P2PToken}}</span>" --name local-ai -p 8080:8080 localai/localai:latest-cpu run --federated --p2p
</code>

<p class="mb-2">To start a new federated server (port to 9090):</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words">
<p class="text-lg font-bold mb-4 mt-1">
To start a new federated server with Docker (port to 9090):
<i class="fa-solid fa-copy copy-icon float-right"></i>
</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words" @click="copyClipboard($el.textContent)">
docker run -ti --net host -e TOKEN="<span class="token">{{.P2PToken}}</span>" --name local-ai -p 9090:8080 localai/localai:latest-cpu federated
</code>

Expand Down Expand Up @@ -129,17 +146,23 @@ <h3 class="text-2xl font-semibold text-gray-100 mb-6"><i class="fa-solid fa-book
<!-- Tabs content -->
<div class="mb-6">
<div class="tabcontent hidden opacity-100 transition-opacity duration-150 ease-linear data-[twe-tab-active]:block p-4" id="tabs-cli" role="tabpanel" aria-labelledby="tabs-cli" data-twe-tab-active>
<p class="mb-2">To start a new worker, run the following command:</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words">
<p class="text-lg font-bold mb-4 mt-1">
To start a new worker, run the following command:
<i class="fa-solid fa-copy copy-icon float-right"></i>
</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words" @click="copyClipboard($el.textContent)">
export TOKEN="<span class="token">{{.P2PToken}}</span>"<br>
local-ai worker p2p-llama-cpp-rpc
</code>

<p class="mt-2">For all the options available, please refer to the <a href="https://localai.io/features/distribute/#starting-workers" target="_blank" class="text-yellow-300 hover:text-yellow-400">documentation</a>.</p>
</div>
<div class="tabcontent hidden opacity-0 transition-opacity duration-150 ease-linear data-[twe-tab-active]:block p-4" id="tabs-docker" role="tabpanel" aria-labelledby="tabs-docker">
<p class="mb-2">To start a new worker with docker, run the following command:</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words">
<p class="text-lg font-bold mb-4 mt-1">
To start a new worker with docker, run the following command:
<i class="fa-solid fa-copy copy-icon float-right"></i>
</p>
<code class="block bg-gray-700 text-yellow-300 p-4 rounded-lg break-words" @click="copyClipboard($el.textContent)">
docker run -ti --net host -e TOKEN="<span class="token">{{.P2PToken}}</span>" --name local-ai -p 8080:8080 localai/localai:latest-cpu worker p2p-llama-cpp-rpc
</code>

Expand Down
10 changes: 10 additions & 0 deletions core/http/views/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
preflight: false,
},
};
function copyClipboard(token) {
navigator.clipboard.writeText(token)
.then(() => {
console.log('Text copied to clipboard:', token);
alert('Text copied to clipboard!');
})
.catch(err => {
console.error('Failed to copy token:', err);
});
}
</script>
<link href="/static/assets/fontawesome/css/fontawesome.css" rel="stylesheet" />
<link href="/static/assets/fontawesome/css/brands.css" rel="stylesheet" />
Expand Down
2 changes: 1 addition & 1 deletion core/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func newNodeOpts(token string) ([]node.Option, error) {
}
libp2ploglevel := os.Getenv("LOCALAI_LIBP2P_LOGLEVEL")
if libp2ploglevel == "" {
libp2ploglevel = "info"
libp2ploglevel = "fatal"
}
c := config.Config{
Limit: config.ResourceLimit{
Expand Down

0 comments on commit 73c9b35

Please sign in to comment.