kalavai-client 0.5.14__py3-none-any.whl → 0.5.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kalavai_client/__init__.py +1 -1
- kalavai_client/assets/apps.yaml +2 -2
- kalavai_client/assets/docker-compose-gui.yaml +10 -0
- kalavai_client/assets/docker-compose-template.yaml +5 -3
- kalavai_client/cli.py +143 -597
- kalavai_client/cluster.py +25 -2
- kalavai_client/core.py +655 -4
- kalavai_client/env.py +41 -2
- kalavai_client/utils.py +55 -19
- {kalavai_client-0.5.14.dist-info → kalavai_client-0.5.16.dist-info}/METADATA +6 -4
- kalavai_client-0.5.16.dist-info/RECORD +23 -0
- {kalavai_client-0.5.14.dist-info → kalavai_client-0.5.16.dist-info}/WHEEL +1 -1
- kalavai_client-0.5.14.dist-info/RECORD +0 -22
- {kalavai_client-0.5.14.dist-info → kalavai_client-0.5.16.dist-info}/LICENSE +0 -0
- {kalavai_client-0.5.14.dist-info → kalavai_client-0.5.16.dist-info}/entry_points.txt +0 -0
kalavai_client/env.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
from pathlib import Path
|
3
|
+
import importlib.resources
|
3
4
|
|
4
5
|
|
5
6
|
def user_path(relative_path, create_path=False):
|
@@ -12,8 +13,46 @@ def user_path(relative_path, create_path=False):
|
|
12
13
|
|
13
14
|
return full_path
|
14
15
|
|
16
|
+
def resource_path(relative_path: str):
|
17
|
+
""" Get absolute path to resource """
|
18
|
+
try:
|
19
|
+
last_slash = relative_path.rfind("/")
|
20
|
+
path = relative_path[:last_slash].replace("/", ".")
|
21
|
+
filename = relative_path[last_slash+1:]
|
22
|
+
resource = str(importlib.resources.files(path).joinpath(filename))
|
23
|
+
except Exception as e:
|
24
|
+
return None
|
25
|
+
return resource
|
15
26
|
|
27
|
+
|
28
|
+
TEMPLATE_LABEL = "kalavai.job.name"
|
29
|
+
STORAGE_CLASS_LABEL = "kalavai.storage.enabled"
|
30
|
+
USER_NODE_LABEL = "kalavai.cluster.user"
|
31
|
+
SERVER_IP_KEY = "server_ip"
|
32
|
+
KALAVAI_PLATFORM_URL = "https://platform.kalavai.net"
|
33
|
+
KALAVAI_PLATFORM_ENDPOINT = "https://platform.kalavai.net/_/api"
|
34
|
+
DEFAULT_CONTAINER_NAME = "kalavai"
|
35
|
+
DEFAULT_VPN_CONTAINER_NAME = "kalavai-vpn"
|
36
|
+
CONTAINER_HOST_PATH = user_path("pool/", create_path=True)
|
37
|
+
DEFAULT_FLANNEL_IFACE = os.getenv("KALAVAI_FLANNEL_IFACE", "netmaker-1")
|
38
|
+
DEFAULT_WATCHER_PORT = 30001
|
39
|
+
KUBE_VERSION = os.getenv("KALAVAI_KUBE_VERSION", "v1.31.1+k3s1")
|
40
|
+
FORBIDEDEN_IPS = ["127.0.0.1"]
|
41
|
+
# kalavai templates
|
42
|
+
HELM_APPS_FILE = resource_path("kalavai_client/assets/apps.yaml")
|
43
|
+
HELM_APPS_VALUES = resource_path("kalavai_client/assets/apps_values.yaml")
|
44
|
+
DOCKER_COMPOSE_TEMPLATE = resource_path("kalavai_client/assets/docker-compose-template.yaml")
|
45
|
+
DOCKER_COMPOSE_GUI = resource_path("kalavai_client/assets/docker-compose-gui.yaml")
|
46
|
+
USER_WORKSPACE_TEMPLATE = resource_path("kalavai_client/assets/user_workspace.yaml")
|
47
|
+
DEFAULT_USER_WORKSPACE_VALUES = resource_path("kalavai_client/assets/user_workspace_values.yaml")
|
48
|
+
POOL_CONFIG_TEMPLATE = resource_path("kalavai_client/assets/pool_config_template.yaml")
|
49
|
+
POOL_CONFIG_DEFAULT_VALUES = resource_path("kalavai_client/assets/pool_config_values.yaml")
|
50
|
+
# user specific config files
|
51
|
+
USER_TEMPLATES_FOLDER = user_path("templates", create_path=True)
|
16
52
|
USER_LOCAL_SERVER_FILE = user_path(".server")
|
17
53
|
USER_COOKIE = user_path(".user_cookie.pkl")
|
18
|
-
|
19
|
-
|
54
|
+
USER_COMPOSE_FILE = user_path("docker-compose-worker.yaml")
|
55
|
+
USER_GUI_COMPOSE_FILE = user_path("docker-compose-gui.yaml")
|
56
|
+
USER_HELM_APPS_FILE = user_path("apps.yaml")
|
57
|
+
USER_KUBECONFIG_FILE = user_path("kubeconfig")
|
58
|
+
USER_VPN_COMPOSE_FILE = user_path("docker-compose-vpn.yaml")
|
kalavai_client/utils.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import json, base64
|
2
2
|
import os
|
3
|
+
import uuid
|
3
4
|
import requests
|
4
5
|
from pathlib import Path
|
5
6
|
import shutil
|
6
7
|
import subprocess
|
7
8
|
import re
|
8
9
|
|
9
|
-
import importlib
|
10
10
|
from jinja2 import Template
|
11
11
|
|
12
12
|
from rich.table import Table
|
@@ -15,7 +15,14 @@ import yaml
|
|
15
15
|
|
16
16
|
from kalavai_client.auth import KalavaiAuthClient
|
17
17
|
from kalavai_client.env import (
|
18
|
-
SERVER_IP_KEY
|
18
|
+
SERVER_IP_KEY,
|
19
|
+
DOCKER_COMPOSE_TEMPLATE,
|
20
|
+
DEFAULT_CONTAINER_NAME,
|
21
|
+
DEFAULT_FLANNEL_IFACE,
|
22
|
+
DEFAULT_VPN_CONTAINER_NAME,
|
23
|
+
CONTAINER_HOST_PATH,
|
24
|
+
USER_COMPOSE_FILE,
|
25
|
+
user_path
|
19
26
|
)
|
20
27
|
|
21
28
|
|
@@ -85,14 +92,46 @@ def is_storage_compatible():
|
|
85
92
|
return False
|
86
93
|
################
|
87
94
|
|
88
|
-
def
|
95
|
+
def generate_compose_config(role, node_name, is_public, node_ip_address="0.0.0.0", num_gpus=0, node_labels=None, pool_ip=None, vpn_token=None, pool_token=None):
|
96
|
+
|
97
|
+
if node_labels is not None:
|
98
|
+
node_labels = " ".join([f"--node-label {key}={value}" for key, value in node_labels.items()])
|
99
|
+
rand_suffix = uuid.uuid4().hex[:8]
|
100
|
+
compose_values = {
|
101
|
+
"user_path": user_path(""),
|
102
|
+
"service_name": DEFAULT_CONTAINER_NAME,
|
103
|
+
"vpn": is_public,
|
104
|
+
"vpn_name": DEFAULT_VPN_CONTAINER_NAME,
|
105
|
+
"node_ip_address": node_ip_address,
|
106
|
+
"pool_ip": pool_ip,
|
107
|
+
"pool_token": pool_token,
|
108
|
+
"vpn_token": vpn_token,
|
109
|
+
"node_name": node_name,
|
110
|
+
"command": role,
|
111
|
+
"storage_enabled": "True",
|
112
|
+
"num_gpus": num_gpus,
|
113
|
+
"k3s_path": f"{CONTAINER_HOST_PATH}/{rand_suffix}/k3s",
|
114
|
+
"etc_path": f"{CONTAINER_HOST_PATH}/{rand_suffix}/etc",
|
115
|
+
"node_labels": node_labels,
|
116
|
+
"flannel_iface": DEFAULT_FLANNEL_IFACE if is_public else ""
|
117
|
+
}
|
118
|
+
# generate local config files
|
119
|
+
compose_yaml = load_template(
|
120
|
+
template_path=DOCKER_COMPOSE_TEMPLATE,
|
121
|
+
values=compose_values)
|
122
|
+
with open(USER_COMPOSE_FILE, "w") as f:
|
123
|
+
f.write(compose_yaml)
|
124
|
+
return compose_yaml
|
125
|
+
|
126
|
+
def is_watcher_alive(server_creds, user_cookie, timeout=30):
|
89
127
|
try:
|
90
128
|
request_to_server(
|
91
129
|
method="get",
|
92
130
|
endpoint="/v1/health",
|
93
131
|
data=None,
|
94
132
|
server_creds=server_creds,
|
95
|
-
user_cookie=user_cookie
|
133
|
+
user_cookie=user_cookie,
|
134
|
+
timeout=timeout
|
96
135
|
)
|
97
136
|
except Exception as e:
|
98
137
|
print(str(e))
|
@@ -260,7 +299,8 @@ def request_to_server(
|
|
260
299
|
server_creds,
|
261
300
|
force_url=None,
|
262
301
|
force_key=None,
|
263
|
-
user_cookie=None
|
302
|
+
user_cookie=None,
|
303
|
+
timeout=60
|
264
304
|
):
|
265
305
|
if force_url is None:
|
266
306
|
service_url = load_server_info(data_key=WATCHER_SERVICE_KEY, file=server_creds)
|
@@ -284,7 +324,8 @@ def request_to_server(
|
|
284
324
|
method=method,
|
285
325
|
url=f"http://{service_url}{endpoint}",
|
286
326
|
json=data,
|
287
|
-
headers=headers
|
327
|
+
headers=headers,
|
328
|
+
timeout=timeout
|
288
329
|
)
|
289
330
|
try:
|
290
331
|
result = response.json()
|
@@ -388,17 +429,6 @@ def encode_dict(data: dict):
|
|
388
429
|
def decode_dict(str_data: str):
|
389
430
|
return json.loads(base64.b64decode(str_data.encode()))
|
390
431
|
|
391
|
-
def resource_path(relative_path: str):
|
392
|
-
""" Get absolute path to resource """
|
393
|
-
try:
|
394
|
-
last_slash = relative_path.rfind("/")
|
395
|
-
path = relative_path[:last_slash].replace("/", ".")
|
396
|
-
filename = relative_path[last_slash+1:]
|
397
|
-
resource = str(importlib.resources.files(path).joinpath(filename))
|
398
|
-
except Exception as e:
|
399
|
-
return None
|
400
|
-
return resource
|
401
|
-
|
402
432
|
def safe_remove(filepath, force=True):
|
403
433
|
if not os.path.exists(filepath):
|
404
434
|
return
|
@@ -407,6 +437,12 @@ def safe_remove(filepath, force=True):
|
|
407
437
|
os.remove(filepath)
|
408
438
|
if os.path.isdir(filepath):
|
409
439
|
shutil.rmtree(filepath)
|
440
|
+
return
|
410
441
|
except:
|
411
|
-
|
412
|
-
|
442
|
+
pass
|
443
|
+
|
444
|
+
if force:
|
445
|
+
try:
|
446
|
+
run_cmd(f"rm -rf {filepath}")
|
447
|
+
except:
|
448
|
+
pass
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: kalavai-client
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.16
|
4
4
|
Summary: Client app for kalavai platform
|
5
5
|
License: Apache-2.0
|
6
6
|
Keywords: LLM,platform
|
@@ -31,6 +31,7 @@ Requires-Dist: jinja2 (==3.1.4)
|
|
31
31
|
Requires-Dist: netifaces (==0.11.0)
|
32
32
|
Requires-Dist: psutil (==5.9.8)
|
33
33
|
Requires-Dist: py2app (==0.28.7) ; extra == "dev"
|
34
|
+
Requires-Dist: pydantic (==2.10.6)
|
34
35
|
Requires-Dist: pyinstaller (==6.5.0) ; extra == "dev"
|
35
36
|
Requires-Dist: pyyaml (==6.0.2)
|
36
37
|
Requires-Dist: requests (>=2.25)
|
@@ -46,11 +47,11 @@ Description-Content-Type: text/markdown
|
|
46
47
|
<div align="center">
|
47
48
|
|
48
49
|
 
|
49
|
-
   [   [](https://discordapp.com/channels/1295009828623880313) [](https://platform.kalavai.net)
|
50
51
|
|
51
52
|
</div>
|
52
53
|
|
53
|
-
⭐⭐⭐ **Kalavai and our LLM pools are open source, and free to use in both commercial and non-commercial purposes. If you find it useful, consider supporting us by [giving a star to our GitHub project](https://github.com/kalavai-net/kalavai-client), joining our [discord channel](https://discord.gg/
|
54
|
+
⭐⭐⭐ **Kalavai and our LLM pools are open source, and free to use in both commercial and non-commercial purposes. If you find it useful, consider supporting us by [giving a star to our GitHub project](https://github.com/kalavai-net/kalavai-client), joining our [discord channel](https://discord.gg/YN6ThTJKbM), follow our [Substack](https://kalavainet.substack.com/) and give us a [review on Product Hunt](https://www.producthunt.com/products/kalavai/reviews/new).**
|
54
55
|
|
55
56
|
|
56
57
|
# Kalavai: turn your devices into a scalable LLM platform
|
@@ -128,7 +129,7 @@ Not what you were looking for? [Tell us](https://github.com/kalavai-net/kalavai-
|
|
128
129
|
- Get a free [Kalavai account](https://platform.kalavai.net) and access unlimited AI.
|
129
130
|
- Full [documentation](https://kalavai-net.github.io/kalavai-client/) for the project.
|
130
131
|
- [Join our Substack](https://kalavainet.substack.com/) for updates and be part of our community
|
131
|
-
- [Join our discord community](https://discord.gg/
|
132
|
+
- [Join our discord community](https://discord.gg/YN6ThTJKbM)
|
132
133
|
|
133
134
|
|
134
135
|
## Getting started
|
@@ -322,3 +323,4 @@ python -m unittest
|
|
322
323
|
```
|
323
324
|
|
324
325
|
docker run --rm --net=host -v /root/.cache/kalavai/:/root/.cache/kalavai/ ghcr.io/helmfile/helmfile:v0.169.2 helmfile sync --file /root/.cache/kalavai/apps.yaml --kubeconfig /root/.cache/kalavai/kubeconfig
|
326
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
kalavai_client/__init__.py,sha256=r18HAWHGJVUFx-29UpqHQDvNuq_9ey86nLfnKDvXHfM,23
|
2
|
+
kalavai_client/__main__.py,sha256=WQUfxvRsBJH5gsCJg8pLz95QnZIj7Ol8psTO77m0QE0,73
|
3
|
+
kalavai_client/assets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
kalavai_client/assets/apps.yaml,sha256=V1x1FY-fyYsYrXvcIMv3QrBCgJ7jNunluRyJh67eWB0,5983
|
5
|
+
kalavai_client/assets/apps_values.yaml,sha256=CjKVelPQHd-hm-DTMEuya92feKiphU9mh3HrosLYYPE,1676
|
6
|
+
kalavai_client/assets/docker-compose-gui.yaml,sha256=cLju75mcCExztRxwJy5BVk2zBNViOJVp9dqabHXZjE4,240
|
7
|
+
kalavai_client/assets/docker-compose-template.yaml,sha256=Fnsk44oFtUqS2E77umVUiWl1-eS96E13TPe31GYo1XI,2825
|
8
|
+
kalavai_client/assets/nginx.conf,sha256=drVVCg8GHucz7hmt_BI6giAhK92OV71257NTs3LthwM,225
|
9
|
+
kalavai_client/assets/pool_config_template.yaml,sha256=fFz4w2-fMKD5KvyzFdfcWD_jSneRlmnjLc8hCctweX0,576
|
10
|
+
kalavai_client/assets/pool_config_values.yaml,sha256=VrM3XHQfQo6QLZ68qvagooUptaYgl1pszniY_JUtemk,233
|
11
|
+
kalavai_client/assets/user_workspace.yaml,sha256=wDvlMYknOPABAEo0dsQwU7bac8iubjAG9tdkFbJZ5Go,476
|
12
|
+
kalavai_client/assets/user_workspace_values.yaml,sha256=G0HOzQUxrDMCwuW9kbWUZaKMzDDPVwDwzBHCL2Xi2ZM,542
|
13
|
+
kalavai_client/auth.py,sha256=QsBh28L2LwjBBK6pTUE4Xu36lLDTyetyU1YfS1Hbb6g,1717
|
14
|
+
kalavai_client/cli.py,sha256=GYi7X3F6j4GpbiZq8qrYXmXrkzeFVyO8gwhZAAkXeEs,48794
|
15
|
+
kalavai_client/cluster.py,sha256=gwjmdsd--YrffT0BmZDOEpbrdm3lPskUuN5jdgcrOR0,12947
|
16
|
+
kalavai_client/core.py,sha256=7hoddNN87NB2mvmBb9Flpi-8mbOufMljvYLUlEeH4lU,27247
|
17
|
+
kalavai_client/env.py,sha256=Zg2pP-xGJpQumo56KMBxBLgIsBmcNN0S9R-ZP2-s630,2604
|
18
|
+
kalavai_client/utils.py,sha256=rz5W9PRZrTpgdmOs6yeqUi4f_q_L-3BJ5g1o7Asgnyo,13386
|
19
|
+
kalavai_client-0.5.16.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
20
|
+
kalavai_client-0.5.16.dist-info/METADATA,sha256=9DRC2jLu-pObMkhWXDRjHGLVbpJl8P3ITTEwdmyibyY,14389
|
21
|
+
kalavai_client-0.5.16.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
22
|
+
kalavai_client-0.5.16.dist-info/entry_points.txt,sha256=9T6D45gxwzfVbglMm1r6XPdXuuZdHfy_7fCeu2jUphc,50
|
23
|
+
kalavai_client-0.5.16.dist-info/RECORD,,
|
@@ -1,22 +0,0 @@
|
|
1
|
-
kalavai_client/__init__.py,sha256=w3lW-XLGLyRg9TivuSzsLBUjs3nPX74ewdf47ZPX-as,23
|
2
|
-
kalavai_client/__main__.py,sha256=WQUfxvRsBJH5gsCJg8pLz95QnZIj7Ol8psTO77m0QE0,73
|
3
|
-
kalavai_client/assets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
kalavai_client/assets/apps.yaml,sha256=yC-vtYTPE960KUQihTk5pee8xZz9RD8Reuyh1nSpRWk,5981
|
5
|
-
kalavai_client/assets/apps_values.yaml,sha256=CjKVelPQHd-hm-DTMEuya92feKiphU9mh3HrosLYYPE,1676
|
6
|
-
kalavai_client/assets/docker-compose-template.yaml,sha256=mo8LUam9-AzB_0w72wTyMyreKr4Ns-pxZGc4GVWcUHA,2747
|
7
|
-
kalavai_client/assets/nginx.conf,sha256=drVVCg8GHucz7hmt_BI6giAhK92OV71257NTs3LthwM,225
|
8
|
-
kalavai_client/assets/pool_config_template.yaml,sha256=fFz4w2-fMKD5KvyzFdfcWD_jSneRlmnjLc8hCctweX0,576
|
9
|
-
kalavai_client/assets/pool_config_values.yaml,sha256=VrM3XHQfQo6QLZ68qvagooUptaYgl1pszniY_JUtemk,233
|
10
|
-
kalavai_client/assets/user_workspace.yaml,sha256=wDvlMYknOPABAEo0dsQwU7bac8iubjAG9tdkFbJZ5Go,476
|
11
|
-
kalavai_client/assets/user_workspace_values.yaml,sha256=G0HOzQUxrDMCwuW9kbWUZaKMzDDPVwDwzBHCL2Xi2ZM,542
|
12
|
-
kalavai_client/auth.py,sha256=QsBh28L2LwjBBK6pTUE4Xu36lLDTyetyU1YfS1Hbb6g,1717
|
13
|
-
kalavai_client/cli.py,sha256=tozKzLsDWFhztC5lcorryBcdhzSYyqb5XGWQsUtQ45A,66297
|
14
|
-
kalavai_client/cluster.py,sha256=odzfJFrkKNvZpFFiTA4pg-CeRdPnIe2UyIpSItCjK6A,12319
|
15
|
-
kalavai_client/core.py,sha256=Vb-5MBHjpuR590FIDOnytJpP1Xjt7hYqehPV2rh6P68,6863
|
16
|
-
kalavai_client/env.py,sha256=RAi37vJtIGfPR25PNxZYMZNkkEKR4AyUPN_htFiFesM,575
|
17
|
-
kalavai_client/utils.py,sha256=kQk_1QOs8u08rcfhkcfo_oC-cZzww0cij-1R_jK1ER8,12185
|
18
|
-
kalavai_client-0.5.14.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
19
|
-
kalavai_client-0.5.14.dist-info/METADATA,sha256=au17zuHNT9eVKuhxpsp_Gqmx6YYksrkSRhnzEqAkZmk,14347
|
20
|
-
kalavai_client-0.5.14.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
21
|
-
kalavai_client-0.5.14.dist-info/entry_points.txt,sha256=9T6D45gxwzfVbglMm1r6XPdXuuZdHfy_7fCeu2jUphc,50
|
22
|
-
kalavai_client-0.5.14.dist-info/RECORD,,
|
File without changes
|
File without changes
|